Hi! I need help with this C++ assignment! Thanks The next 8 questions are based
ID: 666179 • Letter: H
Question
Hi! I need help with this C++ assignment! Thanks
The next 8 questions are based upon the following material:
struct nameType
{
string first;
string last;
};
struct courseType
{
string courseName;
int callNum;
int credits;
char grade;
};
struct studentType
{
nameType name;
double gpa;
courseType course;
};
//**********************************************
//Variables defined using the above defined structs
studentType student;
studentType classList[100];
courseType course;
nameType name;
//************************************************
These are the questions:
1.The following is a valid C++ statement: student.course.callNum = 123; true or false?
2. The following is a valid C++ statement:cin >> student.name; true or false?
3.The following is a valid C++ statement: classList[0] = name; true or false?
4. The following is a valid C++ statement:classList[1].gpa = 3.45; true or false?
5. The following is a valid C++ statement: string n1 = classList[15].name.first; true or false?
6. The following is a valid C++ statement: student.name = name; true or false?
7. The following is a valid C++ statement: cout << classList[10] << endl; true or false?
8. The following is a valid C++ program segment:
true or false?
PLEASE HELP!
Explanation / Answer
1) TRUE Yes it is valid....it will go to coursetype struct and sets the value 123.
2) FALSE not it will throw error...type is nametype not string.
3) FALSE ...it will throw error as: operand types are studentType and nameType.
4) TRUE....both structures we use variable double..so it is true
5) TRUE ...It will casted to nametype to string..so it is true.
6) TRUE .. As name declared nametype...and in structure also same..so this statement will pass.
7) TRUE .. It will pass
8) TRUE ..It will pass....since we declared classlist array of size 100...so not out of bounds exception raise. so valid
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.