1. Consider the following declarations and statements: struct nameType struct co
ID: 3881050 • Letter: 1
Question
1. Consider the following declarations and statements: struct nameType struct courseType string first; string last; string name; int callNum; int credits; char grade; struct studentType nameType name; double gpa; courseType courses [50] studentType classList[100] Give a C++ statement to do each the following operations. a) Set the first name of 2nd student (i.e. index 1) stored in the classList array equal to "Hubert" b) Read the gpa of the 5th student (i.e. index 4) stored in the classList array from cin. c) Write the name of the 10th course (i.e. index 9) taken by the 19th student (i.e. index 18) stored in the classList array to cout. 2. Write C++ statements to do each of the following a. Declare an array alpha of 10 rows and 20 columns of type int. b. Initialize the array alpha to 0 using nested loopsExplanation / Answer
#include<iostream>
using namespace std;
struct nameType
{
string first;
string last;
};
struct courseType
{
string name;
int callNum;
int credits;
char grade;
};
struct studentType
{
nameType name;
double gpa;
courseType courses[50];
};
int main()
{
studentType classList[100];
//a
//setting first name of 2nd student to Hubert
classList[1].name.first="Hubert";
//printing to cout
cout<<classList[1].name.first<<endl;
//b
//read gpa of 5th student
cout<<"Enter gpa:";
cin>>classList[4].gpa;//reading gpa from cin
//printing to cout
cout<<classList[4].gpa<<endl;
//c
//write the name of 10 th course, taken by 19 the student
//first the name of the course
classList[18].courses[9].name ="Maths";
//now writing to cout
cout<<classList[18].courses[9].name<<endl;
return 0;
}
output:
Hubert
Enter gpa:9.8
9.8
Maths
Process exited normally.
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.