summaryrefslogtreecommitdiff
path: root/BlankConsoleLab
diff options
context:
space:
mode:
authorTim Pearse <[email protected]>2022-11-30 20:02:07 -0800
committerTim Pearse <[email protected]>2022-11-30 20:02:07 -0800
commit49887d7387780b73ac76fff422279d1b44885e6b (patch)
treedb4bdc4bc6d71add97606896106e783519252073 /BlankConsoleLab
parentChange 1 : Works (diff)
downloadcst116-lab3-legokid1503-49887d7387780b73ac76fff422279d1b44885e6b.tar.xz
cst116-lab3-legokid1503-49887d7387780b73ac76fff422279d1b44885e6b.zip
Added comments
Diffstat (limited to 'BlankConsoleLab')
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp25
-rw-r--r--BlankConsoleLab/large.txt48
2 files changed, 62 insertions, 11 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index ebf1f80..bd2cce9 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -17,31 +17,27 @@ void Output_Extra_Stats(int total_people, double fares[50]);
int main()
{
- // Create a text file
- ofstream MyWriteFile("filename.txt");
-
- // Write to the file
- MyWriteFile << "1 2 3 4 5 6";
-
- // Close the file
- MyWriteFile.close();
-
+ // initialize the taxi trips lists
double taxi_trips[50][8];
cout << "Enter the file you'd like to read with the extension";
string filename;
cin >> filename;
cout << endl;
-
+
+ //These ints and doubles will be used for file reading
int start_point;
int end_point;
int passengers;
double distance;
double fare_amount;
double toll_amount;
+
+ //Open the file then read it.
std::ifstream input;
input.open(filename);
int total_trips = 0;
if (input.is_open()) {
+ //Reads each line of the file, then saves it to the taxi_trips
while (input >> start_point >> end_point >> passengers >> distance >> fare_amount >> toll_amount) {
//Set start point
taxi_trips[total_trips][0] = start_point;
@@ -54,7 +50,7 @@ int main()
taxi_trips[total_trips][7] = 0.0;
total_trips++;
}
-
+ //Adds the total fare and the cost per mile to each taxi trip
for (int i = 0; i < total_trips; i++) {
taxi_trips[i][6] = taxi_trips[i][4] + taxi_trips[i][5];
if (taxi_trips[i][3] != 0) {
@@ -64,31 +60,38 @@ int main()
}
int total_people = 0;
+ // Initializes everything in the fares list to 0. This way it dosen't break later.
double fares[50];
for (int i = 0; i < 50; i++) {
fares[i] = 0;
}
+ //Sets the total amount of people, and saves the fares.
for (int i = 0; i < total_trips; i++) {
total_people += taxi_trips[i][2];
fares[i] = taxi_trips[i][6];
}
+ //Prints the lables for output
cout << setw(10) << "Trip#" << setw(10) << "# ppl" << setw(10) << "Dist." << setw(10) << "Fare" << setw(10) << "Toll" << setw(10) << "Total" << setw(10) << "Cost/MI" << endl;
+ //Prints the output for each taxi trip
for (int i = 0; i < total_trips; i++) {
cout << setw(4) << setfill(' ') << " " << setw(3) << setfill('0') << taxi_trips[i][0] << setw(3) << setfill('0') << taxi_trips[i][1] << setw(10)
<< setfill(' ') << taxi_trips[i][2] << setw(10) << taxi_trips[i][3] << setw(10) << taxi_trips[i][4] << setw(10) << taxi_trips[i][5] << setw(10)
<< taxi_trips[i][6] << setw(10) << taxi_trips[i][7] << endl;
}
+ //Finish the output
Output_Extra_Stats(total_people, fares);
}
}
void Output_Extra_Stats(int total_people, double fares[50]) {
+ // Sets the total fares, and the average cost per person
double total_fares = 0.0;
for (int i = 0; i < 50; i++) {
total_fares += fares[i];
}
int average_cost_per_person = total_fares / total_people;
+ //Prints the People transported, total paid, and average cost per person.
cout << endl;
cout << "People Transported: " << total_people << endl;
cout << "Total Paid: " << total_fares << endl;
diff --git a/BlankConsoleLab/large.txt b/BlankConsoleLab/large.txt
new file mode 100644
index 0000000..1c3dbbb
--- /dev/null
+++ b/BlankConsoleLab/large.txt
@@ -0,0 +1,48 @@
+129 7 3 1.3 7.5 0
+36 69 1 11.41 32 5.76
+7 41 1 4.6 15 5.76
+150 61 2 6.75 23 0
+112 17 1 3.84 15 0
+80 112 6 1.64 9.5 0
+256 183 1 16.08 44.5 0
+138 166 2 7.4 24.5 6.12
+142 50 5 1.7 8 0
+107 163 0 3.6 17 0
+132 3 2 19.1 52 6.12
+48 41 1 4.07 18 4.36
+132 226 1 14.3 39 0
+229 151 1 3.96 14.5 4.58
+238 166 1 0.76 4.5 0
+151 238 2 0.64 5 2.2
+138 82 4 3 12 0
+264 231 3 10.74 32.5 0
+170 114 5 2.01 9 0
+186 87 2 3.45 12 0
+209 256 1 3.79 17 0
+132 107 1 17.2 52 6.12
+232 112 1 3.1 11 0
+164 141 3 2.85 10.5 0
+129 7 3 1.3 7.5 0
+36 69 1 11.41 32 5.76
+7 41 1 4.6 15 5.76
+150 61 2 6.75 23 0
+112 17 1 3.84 15 0
+80 112 6 1.64 9.5 0
+256 183 1 16.08 44.5 0
+138 166 2 7.4 24.5 6.12
+142 50 5 1.7 8 0
+107 163 0 3.6 17 0
+132 3 2 19.1 52 6.12
+48 41 1 4.07 18 4.36
+132 226 1 14.3 39 0
+229 151 1 3.96 14.5 4.58
+238 166 1 0.76 4.5 0
+151 238 2 0.64 5 2.2
+138 82 4 3 12 0
+264 231 3 10.74 32.5 0
+170 114 5 2.01 9 0
+186 87 2 3.45 12 0
+209 256 1 3.79 17 0
+132 107 1 17.2 52 6.12
+232 112 1 3.1 11 0
+164 141 3 2.85 10.5 0