• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# figure.h

martukha Feb 18th, 2020 (edited) 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #pragma once
2. #include<iostream>
3. #include<cmath>
4. #include<string>
5. using namespace std;
6.
7. class Shape {
8. public:
9.     virtual int shape_perimetr()=0;
10.     virtual int shape_area() = 0;
11.     virtual ~Shape() {};
12.
13. };
14.
15. class Polygon : public Shape {
16. public:
17.     virtual string get_shape() const {
18.         return "Polygon";
19.     }
20. };
21.
22. class Square : public Polygon {
23. protected:
24.     int diagonal;
25. public:
26.     Square() :diagonal(0) {}
27.     Square(int d) : diagonal(d) {}
28.     Square(const Square& s) : diagonal(s.diagonal) {}
29.
30.     int get_diagonal() const {
31.         return diagonal;
32.     }
33.     string get_shape() const {
34.         return "Square:" + to_string(diagonal) + "cm";
35.     }
36.     int shape_perimetr()  {
37.         return 4 * diagonal;
38.     }
39.     int shape_area() {
40.         return pow(diagonal, 2);
41.     }
42.
43.     friend ostream& operator<<(ostream& out, const Square& s) {
44.         out << s.diagonal << "cm" << endl;
45.         return out;
46.     }
47.     /*friend iostream& operator>>(istream& in, Square& s) {
48.         in >> s.diagonal;
49.         return in;
50.     }*/
51. };
52.
53. class Rectungle :public Polygon {
54. protected:
55.     int side1;
56.     int side2;
57. public:
58.     Rectungle() :side1(0), side2(0) {}
59.     Rectungle(int s1, int s2) : side1(s1),side2(s2) {}
60.     Rectungle(const Rectungle& r) : side1(r.side1),side2(r.side2) {}
61.
62.     string get_shape() const {
63.         return "Rectangle:" + to_string(side1) + "cm," + to_string(side2) + "cm";
64.     }
65.     int shape_perimetr() {
66.         return 2 * (side1 + side2);
67.     }
68.     int shape_area() {
69.         return side1 * side2;
70.     }
71.     friend ostream& operator<<(ostream& out, const Rectungle& r) {
72.         out << r.side1 << "cm &" << r.side2<<"cm"<< endl;
73.         return out;
74.     }
75.     /*friend iostream& operator>>(istream& in, Rectungle& r) {
76.         in >> r.side1;
77.         in >> r.side2;
78.         return in;
79.     }*/
80. };
81.
82. class Triangle : public Polygon {
83. protected:
84.     int a;
85.     int b;
86.     int c;
87. public:
88.     Triangle() : a(0), b(0), c(0) {}
89.     Triangle(int t_height) :a(t_height), b(t_height), c(t_height) {}
90.     Triangle(int aa,int bb,int cc): a(aa), b(bb),c(cc){}
91.     Triangle(const Triangle&t): a(t.a), b(t.b), c(t.c){}
92.
93.     string get_shape() const {
94.         return "Triangle:" + to_string(a) + "cm," + to_string(b) + "cm," + to_string(c) + "cm";
95.     }
96.     int shape_perimetr() {
97.         return a + b + c;
98.     }
99.     int shape_area() {
100.         return sqrt(Triangle::shape_perimetr() * (Triangle::shape_perimetr() - a) * (Triangle::shape_perimetr() - b) * (Triangle::shape_perimetr() - c));
101.     }
102.
103.     friend ostream& operator<<(ostream& out, const Triangle& t) {
104.         out << t.a << "cm &" << t.b << "cm &" << t.c << "cm" << endl;
105.         return out;
106.     }
107.     /*friend iostream& operator>>(istream& in, Triangle& t) {
108.         in >> t.a;
109.         in >> t.b;
110.         in >> t.c;
111.         return in;
112.     }*/
113. };
114.
115. class Circle :public Shape {
116. protected:
118. public:
122.
123.     string get_shape() const {
125.     }
128.     }
129.     int shape_perimetr() {
130.         return 2 * 3,14 * radius;
131.     }
132.     int shape_area() {
133.         return 3,14 * pow(radius, 2);
134.     }
135.
136.     friend ostream& operator<<(ostream& out, const Circle& c) {