Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class p
4.
{
5.
protected:
6.
int width, height;
7.
public:
8.
void set_values (int a, int b)
9.
{
10.
width = a; height = b;
11.
}
12.
virtual int area (void) = 0;
13.
};
14.
class r: public
15.
{
16.
public:
17.
int area (void)
18.
{
19.
return (width * height);
20.
}
21.
};
22.
class t: public p
23.
{
24.
public:
25.
int area (void)
26.
{
27.
return (width * height / 2);
28.
}
29.
};
30.
int main ()
31.
{
32.
r rect;
33.
t trgl;
34.
p * ppoly1 = ▭
35.
p * ppoly2 = &trgl;
36.
ppoly1->set_values (4, 5);
37.
ppoly2->set_values (4, 5);
38.
cout area() ;
39.
cout area();
40.
return 0;
41.
}
Options:
A .  1020
B .  20
C .  10
D .  2010
Answer: Option D

In this program, We are calculating the area of rectangle and
triangle by using abstract class.
Output:
$ g++ abs.cpp
$ a.out
2010



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers