Output of following C++ program :

M.C.A. (Management Faculty) (Semester - II)

IT 21: Object Oriented Programming Using C ++ (2012 Pattern)


Time: 3 Hours] [Max.Marks: 70

Instructions to the candidates:

1) Question 1 is compulsory.
2) Answer any six questions from remaining questions.
3) Figures to the right indicate full marks


Q1) What will be the output of following program?

a) void main ()
{
Cout << setw(10) << setfill('#');
cout.setf(ios :: internal, ios :: adjustfield);
cout << setiosflags (ios:: showpoint);
cout << setprecision(5);
cout << 11.432 << endl;
cout << setiosflags (ios :: showpos);
cout << 15.4 ;
}

Output:

####11.432
+15.400

b)
classmca
{
public: int a;
private: int b;
protected: int c;
};
void main()
{
mcaobj 1;
cout << obj 1.a << obj 1.b << obj 1.c;
}

Output:

As variable b and c are private and protected respectively so these variables cannot be access outside the class. So it will give compile time error.
There is also syntax error while declaring object as obj 1. There should be no space between obj and 1, it should be obj1.

c) #include< iostream.h>

void execute (int x, int y = 200)
{
int temp = x + y;

x +=temp;
if (y!= 200)
cout << temp << x << y << endl;
}
void main ( )
{

int a = 50, b = 20;
execute (b);
cout << a << b << endl;
execute (a, b);
cout << a << b << endl;
}


Output:

In the question paper there is error in above code. There should be if (y! = 200) in place of int (y! = 200). If we consider if (y! = 200) then the output will be as given below.

5020
7012020
5020
d)

void main ( )
{
int a = 65;
int * const p = &a;
cout << char (*p);
*p = 66 ;
cout << char (*p);
(char *) p++;
cout << char (*p);
}

Output:
In the above code p is declare as int * const p and it constant pointer to integer. So we cannot modify const object. It will give compile time error.

e)
class sample
{
int a;
public :

explicit sample (int i)
{
a = i;
}
void display ( )
{
cout << "Value of A : " << a;
}

};

int main ( )
{
sample S = 25;
S. display();
return 0;
}

Output:

In the above code explicit keyword is written with constructor. So we cannot write like sample S = 25 because it is implicit conversion from int to sample; It will give compile time error. You can provide value to constructor as follows sample S(25);
Post your comment