-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask1.cpp
52 lines (49 loc) · 1.21 KB
/
Task1.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
// 2018556502 Muhammed Ali ARICI
// 2019556461 Mahmut Can CINGI
// 2020556061 Emre ULUSOY
#include <iostream>
#include <limits>
#define PI 3.14
using namespace std;
// Base Class
class area_cl {
public:
double height,width;
};
// Sub Class 1
class rectangle : public area_cl {
public:
double area(double h,double w) {
return h * w;
}
};
// Sub Class 2
class cylinder : public area_cl {
public:
double area(double h,double w) {
double r = w/2;
return 2 * PI * r * (h + r) ;
}
};
int main(void) {
area_cl object;
rectangle rec_obj;
cylinder cly_obj;
double area_rectangle,area_cylinder;
while (1) {
cout << "What are the dimensions? (Heigth and Width)" << endl;
cin >> object.height >> object.width;
if (cin.fail()) {
cout << "You have entered characters, please enter numbers." << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
else {
area_rectangle = rec_obj.rectangle::area(object.height,object.width);
area_cylinder = cly_obj.cylinder::area(object.height,object.width);
cout << "Cylinder's area is:" << area_cylinder << endl;
cout << "Renctangle's area is:" << area_rectangle << endl;
break;
}
}
}