diff options
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 25 |
1 files changed, 14 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; |