-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape.h
115 lines (84 loc) · 2.21 KB
/
shape.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#pragma once
#include <string>
#include <ostream>
class shape
{
public:
/* copy constructor: */
/* shape(cosnt shape&); */
// undefined behavior UB
// virtual destructor
virtual ~shape() = default;
// abstruct
virtual float area() const = 0; // pure virtual method
virtual float perimeter() const = 0;
virtual float circumference() const = 0;
virtual std::ostream& shape_info(std::ostream&) const = 0;
virtual std::string shape_details() const = 0;
};
// concrete
class rectangle : public shape
{
public:
rectangle() = default;
rectangle(float width, float height);
float width() const;
float height() const;
float area() const override;
float perimeter() const override;
float circumference() const override;
std::ostream& shape_info(std::ostream&) const override;
std::string shape_details() const override;
private:
float m_width;
float m_height;
};
class square : public rectangle
{
public:
square(float side);
float side() const;
std::ostream& shape_info(std::ostream&) const override;
std::string shape_details() const override;
};
class circle : public shape
{
public:
circle() = default;
circle(float radius);
float radius() const;
float area() const override;
float perimeter() const override;
float circumference() const override;
std::ostream& shape_info(std::ostream&) const override;
std::string shape_details() const override;
private:
const float m_PI = 3.1415926F;
float m_radius;
};
// undone
class triangle : public shape
{
public:
triangle() = default;
triangle(float bottom, float left_side, float right_side);
float bottom() const;
float lside() const;
float rside() const;
float area() const override;
float perimeter() const override;
float circumference() const override;
std::ostream& shape_info(std::ostream&) const override;
std::string shape_details() const override;
private:
float m_bottom;
float m_lside;
float m_rside;
};
std::ostream& operator<<(std::ostream& os, const shape& sp);
/*
std::ostream& operator<<(std::ostream& os, const rectangle& rect);
std::ostream& operator<<(std::ostream& os, const square& sq);
std::ostream& operator<<(std::ostream& os, const circle& cir);
std::ostream& operator<<(std::ostream& os, const triangle& tri);
*/