Consider the following statements: struct nameType struct courseType struct stud
ID: 643615 • Letter: C
Question
Consider the following statements:
struct nameType struct courseType struct studentType
{ { {
string first; string name; nameType name;
string last; int callNum; double gpa;
}; int credits; courseType course;
char grade; };
};
studentType student;
studentType classList[100];
courseType course;
nameType name;
Mark the following statements as valid or invalid. If a statement is invalid, explain why.
a. student.course.callNum = "CSC230";
b. cin >> student.name;
c. classList[0] = name;
d. classList[1].gpa = 3.45;
e. name = classList[15].name;
f. student.name = name;
g. cout << classList[10] << endl;
h. for (int j = 0; j < 100; j++)
classList[j].name = name;
i. classList.course.credits = 3;
j. course = studentType.course;
Explanation / Answer
a) wrong. (type of callNum is int. so, we can't assignm string to it)
b) wrong. (type of student.name is nameType. so, we can't use cin or cout on it)
c) wrong. (type of classList[0] is studentType and os name is nameType. since they are of two different structs, we can't use assignment operator)
d) correct
e) correct
f) correct
g) wrong. (type of classList[0] is studentType. so, we can't use cin or cout on it)
h) correct
i) wrong. (classList is an array. to access an element of the array. correct representation must be classList[0].course.credits = 3
j) wrong. (first you must create an object of type studentType
correct representation would be
studentType s;
course = s.course;
)