Question 1 of 25
Hints left: 3
Q1
What will be the output of the following C++ code? #include <iostream> using namespace std; class Box { double length; double breadth; double height; public: double getVolume(void) { return length * breadth * height; } void setLength( double len ) { length = len; } void setBreadth( double bre ) { breadth = bre; } void setHeight( double hei ) { height = hei; } Box operator+(const Box& b) { Box box; box.length = this->length + b.length; box.breadth = this->breadth + b.breadth; box.height = this->height + b.height; return box; } }; int main( ) { Box Box1; Box Box2; Box Box3; double volume = 0.0; Box1.setLength(6.0); Box1.setBreadth(7.0); Box1.setHeight(5.0); Box2.setLength(12.0); Box2.setBreadth(13.0); Box2.setHeight(10.0); volume = Box1.getVolume(); cout << "Volume of Box1 : " << volume <<endl; volume = Box2.getVolume(); cout << "Volume of Box2 : " << volume <<endl; Box3 = Box1 + Box2; volume = Box3.getVolume(); cout << "Volume of Box3 : " << volume <<endl; return 0; }
Q2
What will be the output of the following C++ code? #include <iostream> #include <cmath> using namespace std; class Complex { private: double real; double imag; public: Complex(double r = 0.0, double i = 0.0) : real(r), imag(i) {} double mag() { return getMag(); } operator double () { return getMag(); } private: double getMag() { return sqrt(real * real + imag * imag); } }; int main() { Complex com(3.0, 4.0); cout << com.mag(); cout << com; return 0 }
Q3
Inline functions are avoided when . . . . . . . .
Q4
What will be the output of the following C++ code? #include <iostream> using namespace std; class sample1 { float i, j; }; class sample2 { int x, y; public: sample2 (int a, int b) { x = a; y = b; } int result() { return x + y; } }; int main () { sample1 d; sample2 * padd; padd = (sample2*) &d; cout<< padd->result(); return 0; }
Q5
Which is used to tell the computer that where a pointer is pointing to?
Q6
Which special character is used to mark the end of class?
Q7
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class complex { int i; int j; public: complex(int a, int b) { i = a; j = b; } complex operator+(complex c) { complex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; return temp; } void show(){ cout<<"Complex Number: "<<i<<" + i"<<j<<endl; } }; int main(int argc, char const *argv[]) { complex c1(1,2); complex c2(3,4); complex c3 = c1 + c2; c3.show(); return 0; }
Q8
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 20; int b = 10; int c = 15; int d = 5; int e; e = a + b * c / d; cout << e << endl ; return 0; }
Q9
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main () { string str ("Ubuntu"); cout << str.capacity(); cout << str.max_size(); return 0; }
Q10
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { static int a; public: void change(int i){ a = i; } void value_of_a(){ cout<<a; } }; int A::a = 5; int main(int argc, char const *argv[]) { A a1 = A(); A a2 = A(); A a3 = A(); a1.change(10); a1.value_of_a(); a2.value_of_a(); a3.value_of_a(); return 0; }
Q11
What will be the output of the following C++ code? #include <iostream> using namespace std; class rect { int x, y; public: void val (int, int); int area () { return (x * y); } }; void rect::val (int a, int b) { x = a; y = b; } int main () { rect rect; rect.val (3, 4); cout << "rect area: " << rect.area(); return 0; }
Q12
Pick the correct statement.
Q13
What will be the output of the following C++ code? #include <stdio.h> #include<iostream> using namespace std; int main() { int x = 5, y = 5; cout << ++x << --y << endl; return 0; }
Q14
How many specifiers are present in access specifiers in class?
Q15
What will be the output of the following C++ code? #include <iostream> using namespace std; class base { int val1, val2; public: int get() { val1 = 100; val2 = 300; } friend float mean(base ob); }; float mean(base ob) { return float(ob.val1 + ob.val2) / 2; } int main() { base obj; obj.get(); cout << mean(obj); return 0; }
Q16
In case of non-static member functions how many maximum object arguments a unary operator overloaded function can take?
Q17
What is the associativity of add(+);?
Q18
How to declare operator function?
Q19
What will be the output of the following C++ code? #include <iostream> using namespace std; void duplicate (int& a, int& b, int& c) { a *= 2; b *= 2; c *= 2; } int main () { int x = 1, y = 3, z = 7; duplicate (x, y, z); cout << x << y << z; return 0; }
Q20
What is a friend function in C++?
Q21
What is the scope of typedef defined data types?
Q22
What is the use of functor?
Q23
How to access the object in the class?
Q24
Which is called ternary operator?
Q25
What will be the output of the following C++ code? #include <iostream> #include <string> #include <cstring> using namespace std; int main(int argc, char const *argv[]) { const char *a = "Hello\0World"; cout<<a; return 0; }