-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute.cpp
More file actions
144 lines (117 loc) · 3.09 KB
/
execute.cpp
File metadata and controls
144 lines (117 loc) · 3.09 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
//execute.cpp
//***************************************************************
// MLH PRIME HACKATHON ENTRY
//Post Hackathon
//Find a way to apply function that can be distributed throughout
//the graph
//For example, can mimck shattering of glass as rock impacts it
//at different points
//***************************************************************
//Global Documentation...
// The radiation graph
//Developed and Tested by
//@author = Brandon Daniel
#include "stdafx.h"
#include "radiationgraph.h"
#include <fstream>
#define ADD 1
#define DELETE 2
#define SIZE 3
#define DISPLAY 4
#define CLUSTERS 5
#define HISTOGRAM 6
#define EXIT 7
void main_loop(RadiationGraph*);
void prompt_help();
int main(int argc, char *argv[]) {
string line;
RadiationGraph globe;
ifstream in;
if (argc == HAS_FILE) {
//open the file and perform addition to the graph
in.open(argv[ADD]);
while (!in.eof()) {
getline(in, line);
globe.add(&line);
}
in.close();
main_loop(&globe);
}
else {
main_loop(&globe);
}
return 0;
}
//running the cmd user interface and signals the
//interaction with the graph
//makes the huge assumption that the user only enters valid coordinates
//every time....
void main_loop(RadiationGraph *globe) {
bool run = true;
string coordinates;
int option, cluster_dist = 0;
const string HELP_KEYWORD = "HELP";
while (run) {
std::cout << globe->printOptions();
cin >> option;
switch (option) {
case ADD:
//adding to the graph
std::cout << "Enter the coordinates or type \"help\" to see an example" << endl;
cin >> coordinates;
//if the help command was invoked
boost::to_upper(coordinates);
if (!coordinates.compare(HELP_KEYWORD)) {
prompt_help();
}
else {
globe->add(&coordinates);
}
break;
case DELETE:
//adding to the graph
std::cout << "Enter the coordinates or type \"help\" to see an example" << endl;
cin >> coordinates;
//if the help command was invoked
boost::to_upper(coordinates);
if (!coordinates.compare(HELP_KEYWORD)) {
prompt_help();
}
else {
globe->remove(&coordinates);
}
break;
case SIZE:
cout << "There were " << globe->getSize() << " total nodes added to the graph" <<
" with " << globe->explicit_size() << " being empty" << endl;
break;
case DISPLAY:
globe->display(-1);
break;
case CLUSTERS:
cout << "Maximum node distance for each cluster" << endl;
cin >> cluster_dist;
globe->print_cluster(cluster_dist);
break;
case HISTOGRAM:
cout << "Displaying histogram now..." << endl;
globe->display_histogram();
break;
case EXIT:
run = false;
cout << "Exiting..." << endl;
break;
default:
cerr << "Error: Invalid selection: " << option << endl;
}
}
}
//prompt to enter a coordinate or display the
//help display
void prompt_help() {
cout << "An example command is shown below..." << endl;
cout << "A2W2N5-45 (Ascend 2, West 2, North 5 value 45)\n" << endl;
cout << "The list of valid commands are as follows." << endl;
cout << " N = North\n S = South\n E = East\n W = West\n"
<< " A = Ascend\n D = Descend\n" << endl;
}