QP CPP 2
QP CPP 2
De 2b18
Instructionsfor Candidates
. Write your Roll No. on the top immediately on receipt of
this question paper.
2. The question paper consists of two Sections. Section A is
compulsory.
3 Attempt any four questions from Section B.
Section A
Va2+b2
C
4a
b Consider three integer variables initialized as: x=1, y=0, and z=1
What are the values of x, y, and z after executing the following code
segment?
P.T.O.
46 2
46
if(x>y&&x2) class Base
(v)
public:
2=X*1; void print ()
else if(x+y>=z) Base Class";
cout<<"\n P r i n t
What will be
printed on execution of
each part
independent of other)? following statements
) cout<<*val;
(consider
void show()
(i) cout<(*val+1) *2; Class";
cout<"\n Show Derived
d) Find output of each of the
following code segments
) String 2X4
s1="Hello", s2="Beautiful world I!! ";
String s3="Be Happy" void main( )
String s=s1+" "+s2+""+s3 {
[Link] (5, '! ') Base *Bptr;
cout<<s<<endl; Derived D;
cout&<[Link]('"Be") ; Bptr = &D;
Bptr->print( );
(i) void main() Bptr->show( );
int val=1;
do of the following code segments
Find error(s) (if any) in each
if(z<x|ly>=z&&z==1)
if(z&&y) private: int x;
y 1; protected: int y;
else public: int z
x=1;
cout<<x<<" "<<y<<" "<<z;
P.T.C
46
46
4
class Funny : public Fun prototype:
{ replace with the following
function named
Write a
private: int u; h) String replace(String s t r 1 ) ;
protected: int v;
public: int wi the lower
substituting all
returns à new string obtained by s t r 1 passed to
it as a
The function letters in the string
void main() c a s e letters by
uppercase "Hello
World! !!"
[Link] example, "HELLO for the input string WORLD!!!"
Fun fun; output
Funny funny; Thefunction should of the following
of first n tenms
fun.z 2 Write a function
that returns the sum
funny.y =12; i)
funny .u= 5; series
funny. Z=l0;
What is a copy
the help of an
constructor? llustrate the use of copy declaration:
) Give one wordexample.
answer
constructor with
1+2
Given the following
float num = 576.21f
for the
following: c o u t statement?
) In the executing the following
following declaration for the class
4
What will be printed on
class base
countA++
public elseif(ch=='B'||ch=='b')
int x; countB+*
int yi elseif(ch=='C'||ch=='c')
countc+*;
class
derived: else
private base cout<<"Error-Not A, B, or C \n" ;
P.T.
46
6
6
c Assume that you are code segment:
factorial of any numberprovided to function named fact to find the in the following
a
Find error(s)
(passed it as a parameter) with the 4 b)
prototype: following class X
nt
fact(int num) ;
private:
Using this fact function, write int i,J
n even numbers.
a
program to print the factorial of first
virtual
i
x() 1 ; j=1;}
void show()=0;
(i) AxB
(Multiplication of two
ain()
void main ()
Y WW
Gi) A
(Transpose of the squarematrices)
matrix)
.print();
int arrt]={1, 2, 3,
int *ptr1, *ptr2; 4, 5, 6, 7, 8, 9};
class polygon
ptrl=arI; protected:
ptr2=ptrl+2; int width, height;
cout<<ptr2-ptrl; public:
set_values(int a, int b)
void
width=a; height=b;
class output1
P.T
46 8 46 9
6
Account and Employee having
public: C) Declare the classes Person, Create the required
inheritance hierarchy shown in the figure below.
void output(int i); the following
runtime polymorphism for
objects to demonstrate
operations
void outputl: :output(
int i) (i) Accept the information of an employee.
of an employee.
Gi) Display information
cout<<i<<endl;
PeTsona
Name
Code
class rectangle : public polygon, public outpu
t1
AC ount
PaY_
public:
int area()
Enmployee
return(width * height);
statements:
P.T
10
46
(1400)