Classes And Objects In C Plus Plus - Study Mode

[#176] 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
}
Correct Answer

(B) rect area: 12

[#177] 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
}
Correct Answer

(A) Volume of Box1 : 210 Volume of Box2 : 1560 Volume of Box3 : 5400

[#178] 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
}
Correct Answer

(D) 15 9223372036854770000

[#179] 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
}
Correct Answer

(C) 2614

[#180] 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
}
Correct Answer

(A) 50