Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following statements: struct nameType { string first; string last;

ID: 3779637 • Letter: C

Question

Consider the following statements:

struct nameType
{
string first;
string last;
};

struct courseType
{
string name;
int callNum;
int credits;
char grade;
};

struct studentType
{
nameType name;
double gpa;
courseType course;
};

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.) student.course.callNum = "CSC230";

invalid char to int

b.) cin >> student.name;

invalid , cannot read name of nameType struct

c.) classList[0] = name;

invalid , cannot assign name of nameType to studentType

d.) classList[1].gpa = 3.45;

valid , classList has gpa property

e.) name = classList[15].name;

valid can assign nameType to nameType

f.) student.name = name;

valid can assign nameType to nameType

g.) cout << classList[10] << endl;

/invalid ,can not print only struct alone

h.) for (int j = 0; j < 100; j++)
classList[j].name = name;

valid can assign nameType to nameType

i.) classList.course.credits = 3;

invalid ,classList is arrayType so should point out index

j.) course = studentType.course;

invalid ,studentType is struct so can use . operator