-
Notifications
You must be signed in to change notification settings - Fork 23
/
11.Quiz1.cpp
57 lines (46 loc) · 980 Bytes
/
11.Quiz1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
using namespace std;
class Shape
{
public:
virtual double Area() = 0;
virtual void Print() = 0;
};
class Circle: public Shape
{
double Radius;
public:
Circle(double inputRadius) : Radius(inputRadius) {}
double Area() override
{
return 3.1415 * Radius * Radius;
}
void Print() override
{
cout << "Circle says hello!" << endl;
}
};
class Triangle: public Shape
{
double Base, Height;
public:
Triangle(double inputBase, double inputHeight) : Base(inputBase), Height(inputHeight) {}
double Area() override
{
return 0.5 * Base * Height;
}
void Print() override
{
cout << "Triangle says hello!" << endl;
}
};
int main()
{
Circle myRing(5);
Triangle myWarningTriangle(6.6, 2);
cout << "Area of circle: " << myRing.Area() << endl;
cout << "Area of triangle: " << myWarningTriangle.Area() << endl;
myRing.Print();
myWarningTriangle.Print();
return 0;
}