NAME ID SCORE 1 20 Given structure Student Infor as follows
Solution
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<<\"\\tMajor: \"<<students[i].major<<\"\\tGPA: \"<<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
