Sei sulla pagina 1di 35

Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++

QUIZ

By Shivani Nanda

1
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

1) Which type of Access specifier class data


member number is?
//a simple class
class test_example
{
int number;
};

Shivani Nanda 2
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

2) What will be the int main()


output of this {
program? sample obj;
#include <iostream> obj.x=100;
using namespace std; cout<<"x=<<obj.x;
}
class sample
{
int x;
}
Shivani Nanda 3
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

3) Which variable(s) is/are


accessible in main() function?
class sample
{ public:
private: int z;
int x; }
protected:
int y;

Shivani Nanda 4
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

4) Write two different statements to print value


of var ?
int var=100;
class sample
{
private:
void showVal(void)
{ }
}
Shivani Nanda 5
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

5) How to access the object in the class?


a) scope resolution operator b) ternary operator
c) direct member access operator
d) none of the mentioned

6) Pick out the other definition of objects.


a) member of the class b) associate of the class
c) attribute of the class d) instance of the class

Shivani Nanda 6
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

7) Which of these following members are not


accessed by using direct member access( . )
operator?
a) public b) private
c) protected d) Both b & c
8) Function overloading is also similar to which
of the following?
a) operator overloading b) constructor overloading
c) destructor overloading d) none of the mentioned

Shivani Nanda 7
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

class Box
{ public :double length, breadth, height; };
int main( )
{ Box Box1;
9) What will be
double volume;
the output of this
Box1.height = 5;
program?
Box1.length = 6;
Box1.breadth = 7.1;
volume = Box1.height * Box1.length * Box1.breadth;
cout << "Volume of Box1 : " << volume <<endl;
return 0;
}
Shivani Nanda 8
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

class Rect
{ int x, y;
public: void set_values (int,int);
int area ()
10) What will
be the output { return (x * y); } };
of this void Rect::set_values (int a, int b)
program? { x = a; y = b; }
int main ()
{ Rect recta, rectb;
recta.set_values (5, 6); rectb.set_values (7, 6);
cout << "recta area: " << recta.area();
cout << "rectb area: " << rectb.area(); return 0; }
Shivani Nanda 9
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

class sample
{ private: int var;
public: void input(){ cout << var; }
void output(){ cout << "Variable entered is ";
cout << var << "\n; } };
int main()
{ sample object; 11) What will
object.input(); be the output
object.output();
of this
object.var();
program?
return 0;
}
Shivani Nanda 10
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

class number
{ int i; 12) What will
public: int geti(); be the output
void puti(int j); of this
}; program?
int number::geti() { return i; }
void number::puti(int j) { i = j; }
int main(){
number s;
s.puti(10);
cout << s.geti( );
return 0;
Shivani Nanda 11
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

#include <iostream.h>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0; 13) What
int main() will be the
{ for (temp = 0; temp < 5; temp++)
output of
{ result += array1[temp]; }
this
for (temp = 0; temp < 4; temp++)
{ result += array2[temp]; }
program?
cout << result;
return 0;
Shivani Nanda 12
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

#include <stdio.h>
14) What will
using namespace std; be the output
int main() of this
{ program?
int array[] = {10, 20, 30};
cout << -2[array];
return 0;
}

Shivani Nanda 13
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

#include <iostream> void swap(int &a, int &b)


using namespace std; {
void swap(int &a, int &b); int temp;
temp = a;
int main() a = b;
{ int a = 5, b = 10; b = temp;
swap(a, b); cout << "In swap
cout << "In main " << a << b; << a << b;
return 0; }
} 15) What will
be the
output of this program?

Shivani Nanda 14
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

#include <iostream>
using namespace std;
int main()
16) What will be the
{ output of this program?
int a = 9;
int & aref = a;
a++;
cout << "The value of a is " << aref;
return 0;
}
Shivani Nanda 15
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

#include <iostream>
using namespace std;
class sample
{ private: int x;
public: void sample(){x=0; printf("Object created.");}
void sample(int a){x=a;} };
int main()
{ 17) What is the correct answer
sample s; Compile Time Error Object Created
return 0; Run Time Error Cant be predicted
}

Shivani Nanda 16
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

#include <iostream>
using namespace std;
18a) What will be the
class sample output of this program?
{ private: int x,y;
public: void sample(int a,int b) { x=a; y=b;} };
int main()
{
18b) What is the correct form
sample s; of creating the object according
return 0; to the type of constructor
} provided?

Shivani Nanda 17
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

19) Overloaded functions are


a) Very long functions that can hardly run
b) One function containing another one or more functions inside
it.
c) Two or more functions with the same name but different
number of parameters or type.
d) none of the mentioned
20) Which rule will not affect the friend function?
a) private and protected members of a class cannot be accessed
from outside
b) private and protected member can be accessed anywhere
c) both a & b
d) None of the mentioned
Shivani Nanda 18
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

21) Where does keyword friend should be


placed?
a) function declaration b) function definition
c) main function d) None of the mentioned
22) What is this operator called ?: ?
a) conditional
b) relational
c) casting operator
d) none of the mentioned

Shivani Nanda 19
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

#include <iostream>
using namespace std;
int main()
23) What will be the
{ output of this program?
int i, j;
j = 10;
i = (j++, j + 100, 999 + j);
cout << i;
return 0;
}
Shivani Nanda 20
OOPS Using C++
Quiz
Ceuturion University of Technology and Management

int main ()
{ int x, y;
x = 5;
24) What will be the
y = ++x * ++x; output of this program?
cout << x << y;
x = 5;
y = x++ * ++x;
cout << x << y;
return 0;
}
Shivani Nanda 21
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

22
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

23
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

24
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

25
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

26
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

27
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

28
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

29
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

30
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

31
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

32
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

33
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

34
Ceuturion University of Technology and Management

Shivani Nanda
OOPS Using C++
Quiz

35

Potrebbero piacerti anche