-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLine_Task2.cpp
80 lines (63 loc) · 2.09 KB
/
Line_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
#include "Line_Task2.h" // class implemented
using namespace std;
// File scope starts here
/////////////////////////////// PUBLIC ///////////////////////////////////////
//============================= LIFECYCLE ====================================
// Line Default+Overloaded Constructor
Line::Line(char* aColor, int aCoord, float aLength) : Shape(aColor, aCoord), mLength(aLength) {
this->SetLine(aColor, aCoord, aLength);
}
// end Line constructor
// Line Copy Constructor
Line::Line(const Line& rhs) : Shape(rhs.GetShape()), mLength(rhs.GetLength()) {
this->SetLine(rhs.GetLength());
}
// end Line constructor
// Line assignment operator.
Line& Line:: operator =(const Line& rhs) {
this->SetLine(rhs.GetLine());
return *this;
}
// end Line assignment operator.
//============================= OPERATIONS ===================================
// Pure virtual function that draws Line.
void Line::Draw() {
cout << "Drawing a line of length " << this->GetLength() << " in " << this->GetColor() << " color." << endl;
}
// end function Draw
//============================= ACESS ===================================
// function that sets length of Line
void Line::SetLength(float aLength) {
if (aLength < 0.0)
cout << "Error: Length cannot be nagative." << endl;
else
this->mLength = aLength;
}
// end function SetLength
// function that sets Line
void Line::SetLine(char* aColor, int aCoord, float aLength) {
this->SetShape(aColor, aCoord);
this->SetLine(aLength);
}
// end function SetLine
// overloaded function that sets the Line
void Line::SetLine(float aLength) {
this->SetLength(aLength);
}
// end function SetLine
// overloaded function that sets the Line
void Line::SetLine(const Line& aLine) {
this->SetShape(aLine.GetShape());
this->SetLine(aLine.GetLength());
}
// end function SetLine
// function that gets length of Line
float Line::GetLength()const {
return this->mLength;
}
// end function GetLength
// function that gets the Line
const Line& Line::GetLine()const {
return *this;
}
// end function GetLine