Abstract Classes(C++ Programming ) Questions and Answers
Explanation:-
Answer: Option B. -> 212In this program, We are executing these based on the condition given in array. So it is printing as 212.
Output:
$ g++ abs4.cpp
$ a.out
212
Explanation:-
Answer: Option C. -> ubuntu is awesomeIn this program, We are combining the two statements from two classes and printing it by
using abstract class.
Output:
$ g++ abs3.cpp
$ a.out
ubuntu is awesome
Explanation:-
Answer: Option C. -> 5 5In this program, We are displaying the data from the two classes
by using abstract class.
Output:
$ g++ abs1.cpp
$ a.out
5 5
Question 7.
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.
}
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.
}
Explanation:-
Answer: Option D. -> 2010In this program, We are calculating the area of rectangle and
triangle by using abstract class.
Output:
$ g++ abs.cpp
$ a.out
2010