1. Give the output of the following program. Assuming all the desired header files are already included, which are required to run the code.
struct Pixel
{
int C, R;
};
void Display(Pixel P)
{
cout << "Col "<< P.C << " Row " << P.R << endl;
}
int main()
{
Pixel X = {40,50}, Y, Z;
Z = X;
X.C += 10;
Y = Z;
Y.C += 10;
Y.R += 20;
Z.C -= 15;
Display(X);
Display(Y);
Display(Z);
return 0;
}
2.
Find the output of the following program. Assuming all the desired header files are already included, which are required to run the code.
struct Play
{
int score, bonus;
};
void calculate(Play &P, int N = 10)
{
P.score++;
P.bonus += N;
}
int main()
{
Play PL = {10, 15};
calculate(PL, 5);
cout << PL.score << ":" << PL.bonus << endl;
calculate(PL);
cout << PL.score << ":" << PL.bonus << endl;
calculate(PL, 15);
cout << PL.score << ":" << PL.bonus << endl;
return 0;
}
3. Find the output of the following program. Assuming all the desired header files are already included, which are required to run the code.
struct MyBox
{
int length, breadth, height;
};
void dimension (MyBox M)
{
cout << M.length << "x" << M.breadth << "x";
cout << M.height << endl;
}
int main ()
{
MyBox B1 = {10, 15, 5}, B2, B3;
++B1.height;
dimension(B1);
B3 = B1;
++B3.length;
B3.breadth++;
dimension(B3);
B2 = B3;
B2.height += 5;
B2.length--;
dimension(B2);
return 0;
}
4.
Rewrite the following program after removing the syntactical errors (if any). Underline each correction.
struct Pixels
{
int color, style;
}
void showPoint(Pixels P)
{
cout << P.color, P.style << endl;
}
int main()
{
Pixels Point1 = (5, 3);
showPoint(Point1);
Pixels Point2 = Point1;
color.Point1 += 2;
showPoint(Point2);
return 0;
}
5.
Declare a structure to represent a complex number (a number having a real part and imaginary part). Write C++ functions to add, subtract, multiply and divide two complex numbers.
6. An array stores details of 25 students (rollno, name, marks in three subject). Write a program to create such an array and print out a list of students who have failed in more than one subject.