-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·175 lines (137 loc) · 3.56 KB
/
main.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
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
164
165
166
167
168
169
170
171
172
173
174
175
/*
CS202 PROGRAM 1 : MAX SMILEY
file: main.cpp
*/
#include <iostream>
#include <fstream>
#include "address.h"
#include "list.h"
#include "vehicle.h"
#include "citymap.h"
#include "record.h"
using namespace std;
const char * PACKAGE_INPUT = "packages.txt";
const char * MAP_FILE = "citymap.txt";
int main()
{
//make a record list.
RecordList record_list;
//make a new citymap, reading in data from file.
CityMap city_map(MAP_FILE);
//all the package lists for us to populate and then de-populate.
//package_list is a dual purpose list, hence the semi vague name.
PackageList * drn_list = NULL;
PackageList * exp_list = NULL;
PackageList * std_list = NULL;
PackageList * package_list = NULL;
//lets read in some packages from a text file!
ifstream package_input;
package_input.open(PACKAGE_INPUT);
//you'll see what these are for pretty soon.
int priority, address, size, weight;
Drone * drone;
Express * express;
Standard * standard;
//while we're still getting info from file.
while(package_input >> priority >> address >> size >> weight)
{
//make a new package list.
package_list = new PackageList(priority, address, size, weight, NULL);
//depending on what the priority of the package is, add this package list to one of the other package lists.
switch(priority)
{
case 0:
if(drn_list)
{
drn_list->add_to_rear(package_list);
}
else
{
drn_list = package_list;
}
break;
case 1:
if(exp_list)
{
exp_list->add_to_rear(package_list);
}
else
{
exp_list = package_list;
}
break;
case 2:
if(std_list)
{
std_list->add_to_rear(package_list);
}
else
{
std_list = package_list;
}
break;
}
package_list = NULL;
}
//while there are packages in the drone list.
while(drn_list)
{
//more horrible syntax. put the first element of drone list into package list.
drn_list = drn_list->get_first_element(package_list);
//make a new drone, passing it the sub-list.
drone = new Drone(package_list, 1, 20);
//send that drone out to deliver some stuff.
drone->dispatch(city_map);
//get the record of the drone's delivery, and add it to the record list.
record_list.add_record(drone->getRecord());
//get rid of that drone.
delete drone;
package_list = NULL;
}
while(exp_list)
{
//this block is the same as above, except for the for loop which i will explain
exp_list = exp_list->get_first_element(package_list);
//drone list was only popping one element at a time, but here we have to grab up to three.
//break statement in case there are less than three packages in the list to begin with.
for(int i = 1; i < 3; ++i)
{
PackageList * temp_list;
if (!exp_list)
{
break;
}
exp_list = exp_list->get_first_element(package_list);
package_list->add_to_rear(temp_list);
}
express = new Express(package_list, 3, 200);
express->dispatch(city_map);
record_list.add_record(express->getRecord());
delete express;
package_list = NULL;
}
while(std_list)
{
//this block is the same as the previous.
std_list = std_list->get_first_element(package_list);
for(int i = 1; i < 8; ++i)
{
PackageList * temp_list;
if(!std_list)
{
break;
}
std_list = std_list->get_first_element(package_list);
package_list->add_to_rear(temp_list);
}
standard = new Standard(package_list, 8, 1000);
standard->dispatch(city_map);
record_list.add_record(standard->getRecord());
delete standard;
package_list = NULL;
}
//print the records
record_list.print();
//and we're done.
return 0;
}