-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlanet.cpp
More file actions
executable file
·163 lines (129 loc) · 3.08 KB
/
Planet.cpp
File metadata and controls
executable file
·163 lines (129 loc) · 3.08 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Planet.cpp
* Solar
*
* Created by Michael Robinson on 29/11/2010.
* Copyright 2010 . All rights reserved.
*
*/
#include "Planet.h"
Planet::Orbit::Orbit() {
aphelion = 0.0;
perihelion = 0.0;
period = 0.0f;
inclination = 0.0f;
}
Planet::Orbit::Orbit(const Orbit *newOrbit) { //constructor with pointer to Orbit object - THIS IS NOT A COPY CONSTRUCTOR
aphelion = newOrbit->aphelion;
perihelion = newOrbit->perihelion;
period = newOrbit->period;
inclination = newOrbit->inclination;
}
double Planet::Orbit::getAverageDistance() const {
return aphelion + perihelion / 2;
}
double Planet::Orbit::getAphelion() const {
return aphelion;
}
double Planet::Orbit::setAphelion(double newAphelion) {
return aphelion = newAphelion;
}
double Planet::Orbit::getPerihelion() const {
return perihelion;
}
double Planet::Orbit::setPerihelion(double newPerihelion) {
return perihelion = newPerihelion;
}
float Planet::Orbit::getPeriod() const {
return period;
}
float Planet::Orbit::setPeriod(float newPeriod) {
return period = newPeriod;
}
float Planet::Orbit::getInclination() const {
return inclination;
}
float Planet::Orbit::setInclination(float newInclination) {
return inclination = newInclination;
}
Planet::Planet() {
name = "";
radius = 0.0f;
period = 0.0f;
axialTilt = 0.0f;
orbit = new Orbit();
colour = new Colour();
satellites = 0;
}
Planet::~Planet() {
if (orbit != 0) {
delete orbit;
orbit = 0;
}
}
Planet::Planet(const Planet& copyMe){
//set data members stored in stack
name = copyMe.getName();
radius = copyMe.getRadius();
period = copyMe.getPeriod();
//data member pointer has not pointed to anythin yet so nothin the delete
//create data members on the heap
orbit = new Orbit(copyMe.getOrbit());
}
Planet& Planet::operator=(const Planet& assignFromMe) {
if (this != &assignFromMe) {
//set data members stored in stack
name = assignFromMe.getName();
radius = assignFromMe.getRadius();
period = assignFromMe.getPeriod();
//delete data members from the heap
if (orbit != 0) {
delete orbit;
}
// create new copies of data members on the heap
orbit = new Orbit(assignFromMe.getOrbit());
}
return *this;
}
string Planet::getName() const {
return name;
}
string Planet::setName(string newName) {
return name = newName;
}
Planet::Orbit* Planet::getOrbit() const {
return orbit;
}
Planet::Orbit* Planet::setOrbit(Orbit *newOrbit) {
return orbit = newOrbit;
}
float Planet::getRadius() const {
return radius;
}
float Planet::setRadius(float newRadius) {
return radius = newRadius;
}
float Planet::getPeriod() const {
return period;
}
float Planet::setPeriod(float newPeriod) {
return period = newPeriod;
}
float Planet::getAxialTilt() const {
return axialTilt;
}
float Planet::setAxialTilt(float newAxialTilt) {
return axialTilt = newAxialTilt;
}
Colour* Planet::getColour() const {
return colour;
}
Colour* Planet::setColour(Colour *newColour) {
return colour = newColour;
}
int Planet::getNumSatellites() const {
return satellites;
}
int Planet::setNumSatellites(int newNumSatellites) {
return satellites = newNumSatellites;
}