Given the following statements: struct nameType { string first; string last; };
ID: 3910324 • Letter: G
Question
Given the following statements:
struct nameType {
string first;
string last;
};
struct courseType {
string name;
int callNum;
int credits;
char grade;
};
struct studentType {
unsigned queueSlot
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.
student.course.callNum = "CSC230";
wrong => type of callNum is int. so, we can't assign string to it
cin >> student.name;
wrong => type of student.name is nameType. so, we can't use cin or cout on it
classList[0] = name;
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
classList[1].gpa = 3.45;
correct
name = classList[15].name;
correct
student.name = name;
correct
cout << classList[10] << endl;
wrong => type of classList[0] is studentType. so, we can't use cin or cout on it
for(int j = 0; j < 100; j++) classList[j].name = name;
correct
Using the declarations from the previous question. Write C++ statements to do the following:
Store the following information in course:
name: Programming I
callNum: 13452
credits: 3
grade: ‘ ‘ [the space character]
In the array classList initialize each queueSlot to the index value of the component inside of classList, and initialize each gpa to 0.0.
Copy the information of the thirty-first component of the array classList into student.
Update the gpa of the tenth student in the array classList by adding 0.75 to its previous value.
Explanation / Answer
If you have any doubts, please give me comment...
Mark the following statements as valid or invalid. If a statement is invalid, explain why.
student.course.callNum = "CSC230";
wrong => type of callNum is int. so, we can't assign string to it
cin >> student.name;
wrong => type of student.name is nameType. so, we can't use cin or cout on it
classList[0] = name;
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
classList[1].gpa = 3.45;
correct
name = classList[15].name;
correct
student.name = name;
correct
cout << classList[10] << endl;
wrong => type of classList[0] is studentType. so, we can't use cin or cout on it
for(int j = 0; j < 100; j++) classList[j].name = name;
correct
Using the declarations from the previous question. Write C++ statements to do the following:
Store the following information in course:
name: Programming I
callNum: 13452
credits: 3
grade: ‘ ‘ [the space character]
course.name = "Programming I";
course.callNum = 13452;
course.credits = 3;
course.grade = ' ';
In the array classList initialize each queueSlot to the index value of the component inside of classList, and initialize each gpa to 0.0.
for(int i=0; i<100;i++){
classList[i].queueSlot = i;
gpa = 0.0;
}
Copy the information of the thirty-first component of the array classList into student.
student = classList[31];
Update the gpa of the tenth student in the array classList by adding 0.75 to its previous value.
classList[10].gpa += 0.75
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.