C++ EVALUATION
Duration: 1hrs.
Total Marks: 35
1. Constructor is called when
a. a method is declared
b. a class is declared
c. a object is declared
2. Function overloading in C++ is
a. a group function with the same name
b. all have the same number and type of arguments
c. functions with same name and same number and type of arguments
3. Opertor Overloading is like that
a. giving new meaning to existing C++ operators
b. making c++ operators works with objects
c. both a and b
4. Destructor can contain
a. Zero arguments
b. One arguments
c. Two arguments
5. How constructor differ from destructor
a. constructors can be overloaded but destructors can't be overloaded
b. constructors can take arguments but destructor can't
c. both a and b
6. What is output of following?
int main() {
cout << "R4R" << endl;
return 0;
}
a. 1.Execution time error
b. 2.Syntax error
c. 3.R4R
d. 4.None
7. What is output of following
int main() {
int a=000;
cout << "R4R:";
cout << a;
return 0;
}
a. 1.Execution time error
b. 2.Syntax error
c. 3.R4R:0
d. 4.None
8Write the Output
class base
{
public:
int bval;
base(){ bval=0;}
};
class deri:public base
{
public:
int dval;
deri(){ dval=1;}
};
void SomeFunc(base *arr,int size)
{
for(int i=0; i‹size; i++,arr++)
cout«arr-›bval;
cout«endl;
}
int main()
{
base BaseArr[5];
SomeFunc(BaseArr,5);
deri DeriArr[5];
SomeFunc(DeriArr,5);
}
9. Write the output of the following programme
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();
}
11. Name the operators that cannot be overloaded.
12. Which of the following is the correct operator to compare two variables?
a. :=
b. =
c. Equal
d. ==
13. All of the following are valid expressions in C++
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:
cout <<”x is 1”;
break;
case 2:
cout <<”x is 2”;
break;
default:
cout <<”value of x unknown”;
CODE 2
If (x==1){
Cout <<”x is 1”;
}
else if (x==2){
Cout << “x is 2”;
}
else{
Cout <<”value of x unknown”;
}
a. Both of the above code fragments have the same behaviour
b. Both of the above code fragments produce different effects
c. The first code produces more results than second
d. The second code produces more results than first.
15. The continue statement
a. resumes the program if it is hanged
b. resumes the program if it was break was applied
c. skips the rest of the loop in current iteration
d. all of above
16. Examine the following program and determine the output
#include <iostream>
using namespace std;
int operate (int a, int b)
return (a * b);
float operate (float a, float b)
return (a/b);
int main()
int x=5, y=2;
float n=5.0, m=2.0;
cout << operate(x,y) <<"\t";
cout << operate (n,m);
return 0;
}
a. 10.0 5.0
b. 5.0 2.5
c. 10.0 5
d. 10 2.5
17. Overload function in C++
a. a group function with the same name
b. all have the same number and type of arguments
c. functions with same name and same number and type of arguments
d. All of the above
18. Operator overloading is
a. making c++ operators works with objects
b. giving new meaning to existing c++ operators
c. making new c++ operator
d. both a& b above
19. A constructor is called whenever
a. a object is declared
b. an object is used
c. a class is declared
d. a class is used
20. A class having no name
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. constructors can take arguments but destructor can't
b. constructors can be overloaded but destructors can't be overloaded
c. both a & b
d. None of these
22. A destructor takes
a. one argument
b. two arguments
c. three arguments
d. Zero arguments
23. Constructors are used to
a. initialize the objects
b. construct the data members
c. both a & b
d. None of these
24. In C++ a function contained with in a class is called
a. a member function
b. an operator
c. a class function
d. a method
25. The fields in a class of a c++ program are by default
a. protected
b. public
c. private
d. None of these
26. Write the Output
class some{
public:
~some()
{
cout«"some's destructor"«endl;
}
};
void main()
{
some s;
s.~some();
}
27.Write the Output
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();
}
28. void main()
{
int a, *pa, &ra;
pa = &a;
ra = a;
cout «"a="«a «"*pa="«*pa «"ra"«ra ;
}
29. Which of the following is not a jump statement in C++?
a. break
b. goto
c. exit
d. switch
30. The continue statement
a. resumes the program if it is hanged
b. resumes the program if it was break was applied
c. skips the rest of the loop in current iteration
d. all of above
(25 x 1=25)
II
1. Create a class Bank Customer. Write the following functions:
+ operator overload (customers? balances should be added up, as an example of
joint account between husband and wife)
(10 x 1 = 10)