-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExercise_10.8.cpp
95 lines (79 loc) · 2.21 KB
/
Exercise_10.8.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
86
87
88
89
90
91
92
93
94
95
/*
* Exercise_10.cpp
* Day 10: Advanced Functioins
*
* Created on: 28 Aug 2014
* Author: cohabo
*/
// Headers and Includes
/*
#include<iostream>
using namespace std;
// Types and Defines
typedef unsigned short USHORT;
// Class Declarations
// Simple Circle class declaration with one member variable: itsRadius
class SimpleCircle
{
public:
SimpleCircle(); // Class Constructor: Default Constructor
SimpleCircle( USHORT x); // Class Constructor: Overloaded Constructor
SimpleCircle( const SimpleCircle & ); // Class Constructor: Copy Constructor
~SimpleCircle() {} // Class Destructor: Default Destructor
USHORT GetItsRadius() const { return *itsRadius; } // Class Methods: Accessor Functions
void SetItsRadius( USHORT x ) { *itsRadius = x; } // Class Methods: Accessor Functions
const SimpleCircle& operator++(); // Class Methods: Prefix Increment Operator
const SimpleCircle operator++( int ); // Class Methods: Postfix Increment Operator
SimpleCircle operator=( const SimpleCircle & ); // Assignment Operator
private:
USHORT * itsRadius;
};
// Class Definition
SimpleCircle::SimpleCircle()
{
itsRadius = new USHORT (5);
}
SimpleCircle::SimpleCircle( USHORT x )
{
itsRadius = new USHORT (x);
}
SimpleCircle::SimpleCircle( const SimpleCircle & rhs )
{
itsRadius = new USHORT;
*itsRadius = rhs.GetItsRadius();
}
const SimpleCircle& SimpleCircle::operator++()
{
++itsRadius;
return *this;
}
const SimpleCircle SimpleCircle::operator++( int )
{
SimpleCircle temp(*this);
++itsRadius;
return temp;
}
SimpleCircle SimpleCircle::operator=( const SimpleCircle & rhs )
{
if ( this == &rhs )
return *this;
delete itsRadius;
itsRadius = new USHORT;
*itsRadius = rhs.GetItsRadius();
return *this;
}
// Main Program
int main()
{
SimpleCircle theCircle;
SimpleCircle anotherCircle(9);
++theCircle;
++anotherCircle;
cout << "The radius of theCircle is " <<theCircle.GetItsRadius() <<endl;
cout << "The radius of anotherCircle is " <<anotherCircle.GetItsRadius() <<endl;
theCircle = anotherCircle;
cout << "The radius of theCircle is " <<theCircle.GetItsRadius() <<endl;
cout << "The radius of anotherCircle is " <<anotherCircle.GetItsRadius() <<endl;
return 0;
}
*/