-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanRoute.cpp
More file actions
147 lines (107 loc) · 3.69 KB
/
planRoute.cpp
File metadata and controls
147 lines (107 loc) · 3.69 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
// <zianren>
// <wpinto>
// <034,014>
// <Date Submitted>
//------------------------------------------------------
// AUTOGRADER INFO -- IGNORE BUT DO NOT REMOVE
// test_cases: true
// feedback('all')
// 35b24e49-2842-4603-8ba7-0f656200c2d1
//------------------------------------------------------
// Add your code here!
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cctype>
#include <functional>
#include <string>
using namespace std;
//Function to fix data corruption
void fix_string(string &Planet_name){
int index_XX = Planet_name.find("XX");
int index_ = Planet_name.find("_");
//erases XX from string
if (index_XX != string::npos) {
Planet_name.erase(index_XX,2);
}
//replace _ with space
if (index_ != string::npos) {
Planet_name.replace(index_, 1," ");
}
}
//
int main(){
struct Planet {
int Planet_row;
int Planet_column;
string Planet_symbol;
int Planet_ID;
};
Planet default_planet = {0,0,"a",0};
struct Planet_names {
int Planet_ID;
string Planet_name;
};
//Prompt user for filename (tested, working)
string Location;
string Name;
cout << "Enter Locations Filename: ";
cin >> Location;
cout << "Enter Names Filename: ";
cin >> Name;
//
//Read in location and names files
ifstream Locations_file (Location);
ifstream Name_file (Name);
if (! Locations_file.is_open() || !Name_file.is_open()){
cout << "Input file could not be opened";
cout << "" << endl;
return 1;
}
//
//testcase cout every vector in Planet and Planet_names
//Reading in data from the files
int Range_row;
int Range_column;
int Start_row;
int Start_column;
int End_row;
int End_column;
int Planet_row;
int Planet_column;
string Planet_symbol;
int Planet_ID;
Locations_file >> Range_row >> Range_column;
Locations_file >> Start_row >> Start_column;
Locations_file >> End_row >> End_column;
vector <Planet> Planet_vector;
Planet planet;
//cout << Range_row << " " << Range_column;
while (Locations_file >> planet.Planet_row >> planet.Planet_column >> planet.Planet_symbol >> planet.Planet_ID ) {
Planet_vector.push_back(planet);
}
//tested by test case
Planet_names planet_name;
vector <Planet_names> Planet_names_vector;
while (Name_file >> planet_name.Planet_ID >> planet_name.Planet_name){
Planet_names_vector.push_back(planet_name);
}
//tested by test case
// test case to print out the vectors of planets and planet names
//for(size_t i = 0; i<Planet_vector.size();++i){
// cout << Planet_vector.at(i).Planet_row << " " << Planet_vector.at(i).Planet_column << " " << Planet_vector.at(i).Planet_symbol << " " << Planet_vector.at(i).Planet_ID <<endl;
//}
//for(size_t i = 0; i<Planet_names_vector.size();++i){
// cout << Planet_names_vector.at(i).Planet_ID << " " << Planet_names_vector.at(i).Planet_name <<endl;
//}
//check each planet in file to see if out of range
for(size_t i = 0;i<Planet_vector.size();++i){
if(Planet_vector.at(i).Planet_row > Range_row || Planet_vector.at(i).Planet_column > Range_column || Planet_vector.at(i).Planet_row < 1 || Planet_vector.at(i).Planet_column < 1 ){
cout << Planet_vector.at(i).Planet_ID << " " << "out of range - ignoring"<<endl;
//erase that planet from planet_vector - look to recent lab for example
Planet_vector.erase(Planet_vector.begin()+ i);
--i;
}
}
}