forked from bucs240/program1-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStar.cpp
More file actions
156 lines (130 loc) · 3.66 KB
/
Star.cpp
File metadata and controls
156 lines (130 loc) · 3.66 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
#include "Star.h"
#include "Planet.h"
#include "List.h"
#include "Vector.h"
#include <iostream>
Starvector::Starvector(){
current_planets = 0;
vec_star = new Vector();
}
Starvector::~Starvector(){
delete vec_star;
}
long Starvector::addPlanet(){
int rand_dis = rand() % 3000;
Planet * new_planet = new Planet(rand_dis);
vec_star -> insert(current_planets, new_planet);
current_planets = current_planets + 1;
return (unsigned)new_planet->getID();
}
bool Starvector::findPlanet(long id){
for(int i = 0; i <current_planets; i++){
Planet * temp_planet = vec_star->read(i);
if(temp_planet->getID() == id)
return true;
}
return false;
}
bool Starvector::removePlanet(long id){
if(findPlanet(id)){
int find_index;
for(int i = 0; i <current_planets; i++){
Planet * temp_planet = vec_star->read(i);
if(temp_planet->getID() == id)
find_index = i;
}
current_planets = current_planets - 1;
if(vec_star->remove(find_index))
return true;
}
return false;
}
Planet * Starvector::getPlanet(long id){
for(int i = 0; i <current_planets; i++){
Planet * temp_planet = vec_star->read(i);
if(temp_planet->getID() == id)
return vec_star-> read(i);
}
return NULL;
}
void Starvector::orbit(){
for(int i = 0; i <current_planets; i++){
Planet * temp_planet = vec_star->read(i);
temp_planet->orbit();
}
}
void Starvector::printStarInfo(){
std::cout << "The starvector currently has " << current_planets << " planets." << std::endl;
std::cout << "Planets: " << std::endl;
for(int i = 0; i < current_planets; i++){
Planet * temp_planet = vec_star->read(i);
std::cout << "Planet " << temp_planet->getType() << temp_planet->getID() << " is " << temp_planet->getDistance() << " million miles away at positon " << temp_planet->getPos() << " around the star." << std::endl;
}
}
Starlist::Starlist(){
list_star = new List();
current_planets = 0;
}
Starlist::~Starlist() {
delete list_star;
}
long Starlist::addPlanet(){
int rand_dis = rand() % 3000;
Planet * new_planet = new Planet(rand_dis);
list_star -> insert(current_planets, new_planet);
current_planets = current_planets + 1;
return (unsigned)new_planet->getID();
}
bool Starlist::findPlanet(long id){
for(int i = 0; i <current_planets; i++){
Planet * temp_planet = list_star->read(i);
if(temp_planet->getID() == id)
return true;
}
return false;
}
bool Starlist::removePlanet(long id) {
if(findPlanet(id)){
int find_index;
for(int i = 0; i <current_planets; i++){
Planet * temp_planet = list_star->read(i);
if(temp_planet->getID() == id)
find_index = i;
}
current_planets = current_planets - 1;
if(list_star->remove(find_index))
return true;
}
return false;
}
Planet * Starlist::getPlanet(long id) {
for(int i = 0; i <current_planets; i++){
Planet * temp_planet = list_star->read(i);
if(temp_planet->getID() == id)
return list_star-> read(i);
}
return NULL;
}
void Starlist::orbit() {
for(int i = 0; i <current_planets; i++){
Planet * temp_planet = list_star->read(i);
temp_planet->orbit();
}
}
void Starlist::printStarInfo() {
std::cout << "The starlist currently has " << current_planets << " planets." << std::endl;
std::cout << "Planets: " << std::endl;
for(int i = 0; i < current_planets; i++){
Planet * temp_planet = list_star->read(i);
std::cout << "Planet " << temp_planet->getType() << temp_planet->getID() << " is " << temp_planet->getDistance() << " million miles away at positon " << temp_planet->getPos() << " around the star." << std::endl;
}
}
unsigned int Starlist::getCurrentNumPlanets() {
/*
unsigned int count = 0;
while(list_star->read(count) != NULL){
list_star = list_star->next;
count++;
} */
return list_star->size();
}