 # inheritance exc

Jul 25th, 2021
862
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include<iostream>
2. #include <cmath>
3. using namespace std;
4. class Cpolygon {
5.     float ribsNumber;
6.     float side;
7.     float apothem;
8. protected:
9.     double pi = 22.0 / 7.0;
11. public:
12.     void setPolygon(float Radius,float RibsNumber ) {
14.         double angle = pi / RibsNumber;
15.         side = 2 * radius * sin(angle);
16.         apothem = radius * cos(angle);
17.     }
20.     }
21.     float getRibsNumber() {
22.         return ribsNumber;
23.     }
24.     float getSide() { return side; }
25.     float getApothem() { return apothem; }
26.     float polygonArea() {
27.         return (0.5 * ribsNumber * side * apothem);
28.     }
29.     float polygonCirum() {
30.         return (side * ribsNumber);
31.     }
32. };
33.
34. class circle : public Cpolygon {
35. public:
36.     circle(float r) {
38.     }
39.     float circleCirum() {
40.         return (2 * pi * radius);
41.     }
42.     float circleArea() {
44.     }
45. };
46. class Ccircum : public Cpolygon {
47.
48.
49. };
50. int main() {
51.     circle c(20);
52.     cout << " my circle radius is :" << c.getRadius() << endl;
53.     cout << " my circle area is :" << c.circleArea()<<endl;
54.     cout << " my circle cirum is :" << c.circleCirum()<<endl;
55.     cout << "\n------------------------------------------\n";
56.     Cpolygon p;
57.     p.setPolygon(20,7);
58.     cout << " my polygon Ribs Number is :" << p.getRibsNumber() << endl;