NAME ID SCORE 1. (20). Given structure Student Infor as follows. Please create a
ID: 3930959 • Letter: N
Question
NAME ID SCORE 1. (20). Given structure Student Infor as follows. Please create an array of 3 Student Infors. Then, initialize the array. Finally, print ou t the information of your array. - struct StudentInfo string name string major float GPA . (20). x = 1, y = 2, z[6] = 10, z[7] = 15, z[8] = 20, ip is an pointer which points to x. After executing th following program segments, what is the result of cout? y ='ip; [7] =" ip; ip &(6) 'ip = 500; y =, (ip + 1); 0. Give member function defini 40). A rational number q has the form of or the following class where a, b are integers and bExplanation / Answer
1. struct StudentInfo
{
string name;
string major;
float GPA;
};
int main()
{
struct StudentInfo students[3]; //Creates an array of 3 StudentInfos.
/*Initialization starts.*/
students[0].name = "Adam";
students[0].major = "CS";
students[0].GPA = 6.4;
students[1].name = "Ayesha";
students[1].major = "EEE";
students[1].GPA = 4.9;
students[2].name = "Zubain";
students[2].major = "Physics";
students[2].GPA = 3.5;
/*Initialization ends*/
for(int i = 0; i < 3; i++) //Prints the information of the array.
cout<<"Name: "<<students[i].name<<" Major: "<<students[i].major<<" GPA: "<<students[i].GPA<<endl;
}
Here is the solution for the 2nd problem:
x = 1, y = 2, z[6]= 10, z[7] = 15, z[8] = 20;
ip = &x;
y = *ip; //y is assigned a value to which ip is pointing to. So, y = 1.
*ip = z[8]; //x = z[8]. So, x = 20.
z[7] = *ip; //z[7] = x. So, z[7] = 20.
ip = &z[6]; //ip is assigned the address of z[6] which is holding the value 10.
*ip = 500; //z[6] = 500.
y = *(ip + 1); //y = z[6+1], i.e., y = z[7]. So, y = 20.
cout<<x<<" "<<y<<" "<<z[6]<<" "<<z[7]<<" "<<z[8];
//This line will print: 20 20 500 20 20
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.