Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Shivani Nanda
OOPS Using C++
QUIZ
By Shivani Nanda
1
OOPS Using C++
Quiz
Ceuturion University of Technology and Management
Shivani Nanda 2
OOPS Using C++
Quiz
Ceuturion University of Technology and Management
Shivani Nanda 4
OOPS Using C++
Quiz
Ceuturion University of Technology and Management
Shivani Nanda 6
OOPS Using C++
Quiz
Ceuturion University of Technology and Management
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
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
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