C++ Evaluation Duration: 1hrs. Total Marks: 35 1. Constructor Is Called When
C++ Evaluation Duration: 1hrs. Total Marks: 35 1. Constructor Is Called When
C++ Evaluation Duration: 1hrs. Total Marks: 35 1. Constructor Is Called When
Duration: 1hrs.
Total Marks: 35
int main()
{
base BaseArr[5];
SomeFunc(BaseArr,5);
deri DeriArr[5];
SomeFunc(DeriArr,5);
}
class base
{
public:
void baseFun(){ cout«"from base"«endl;}
};
class deri:public base
{
public:
void baseFun(){ cout« "from derived"«endl;}
};
void SomeFunc(base *baseObj)
{
baseObj->baseFun();
}
int main()
{
base baseObject;
SomeFunc(&baseObject);
deri deriObject;
SomeFunc(&deriObject);
}
10. Write the output of the following programme
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double n) { re=n,im=n;};
complex(int m,int n) { re=m,im=n;}
void print() { cout«re; cout«im;}
};
void main(){
complex c3;
double i=5;
c3 = i;
c3.print();
}
a. :=
b. =
c. Equal
d. ==
a = 2 + (b = 5);
a = b = c = 5;
a = 11 % 3
a. True
b. False
14. Consider the following two pieces of codes and choose the best answer
CODE 1:
switch (x) {
case 1:
break;
case 2:
break;
default:
CODE 2
If (x==1){
}
else if (x==2){
}
else{
}
a. Both of the above code fragments have the same behaviour
#include <iostream>
int main()
return 0;
}
c. 10.0 5
a. is not allowed
b. can't have a constructor
c. can't have a destructor
d. can't be passed as an argument
21. The differences between constructors and destructor are
a. a member function
b. an operator
c. a class function
d. a method
class some{
public:
~some()
{
cout«"some's destructor"«endl;
}
};
void main()
{
some s;
s.~some();
}
void main(){
complex c3;
double i=5;
c3 = i;
c3.print();
}
28. void main()
{
int a, *pa, &ra;
pa = &a;
ra = a;
cout «"a="«a «"*pa="«*pa «"ra"«ra ;
}
a. break
b. goto
c. exit
d. switch
(25 x 1=25)
II
(10 x 1 = 10)