-
Notifications
You must be signed in to change notification settings - Fork 1
/
Circle_Task2.cpp
85 lines (68 loc) · 2.33 KB
/
Circle_Task2.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
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
#include "Circle_Task2.h" // class implemented
using namespace std;
// File scope starts here
/////////////////////////////// PUBLIC ///////////////////////////////////////
//============================= LIFECYCLE ====================================
// Circle Default+Overloaded Constructor
Circle::Circle(char* aColor, int aCoord, float aRadius) : Shape(aColor, aCoord), mRadius(aRadius) {
this->SetCircle(aRadius);
}
// end Circle constructor
// Circle Copy Constructor
Circle::Circle(const Circle& rhs) : Shape(rhs.GetShape()), mRadius(rhs.GetRadius()) {
this->SetCircle(rhs.GetRadius());
}
// end Circle constructor
// Circle assignment operator.
Circle& Circle:: operator =(const Circle& rhs) {
this->SetCircle(rhs.GetCircle());
return *this;
}
// end Circle assignment operator.
//============================= OPERATIONS ===================================
// Pure virtual function that draws Circle.
void Circle::Draw() {
cout << "Drawing a Circle of radius " << this->GetRadius() << " in " << this->GetColor() << " color." << endl;
}
// end function Draw
// function that computes area of Circle.
float Circle::ComputeArea() {
return (3.1429*this->GetRadius()*this->GetRadius());
}
// end function ComputeArea
//============================= ACESS ===================================
// function that sets radius of Circle
void Circle::SetRadius(float aRadius) {
if (aRadius < 0.0)
cout << "Error: Radius cannot be nagative." << endl;
else
this->mRadius = aRadius;
}
// end function SetRadius
// function that sets Circle
void Circle::SetCircle(char* aColor, int aCoord, float aRadius) {
this->SetShape(aColor, aCoord);
this->SetCircle(aRadius);
}
// end function SetCircle
// overloaded function that sets the Circle
void Circle::SetCircle(float aRadius) {
this->SetRadius(aRadius);
}
// end function SetCircle
// overloaded function that sets the Circle
void Circle::SetCircle(const Circle& aCircle) {
this->SetShape(aCircle.GetShape());
this->SetCircle(aCircle.GetRadius());
}
// end function SetCircle
// function that gets radius of Circle
float Circle::GetRadius()const {
return this->mRadius;
}
// end function GetRadius
// function that gets the Circle
const Circle& Circle::GetCircle()const {
return *this;
}
// end function GetCircle