// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include #include #include #include using namespace std; using std::cout; using std::cin; using std::endl; using std::setw; 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(); double taxi_trips[50][8]; cout << "Enter the file you'd like to read with the extension"; string filename; cin >> filename; cout << endl; int start_point; int end_point; int passengers; double distance; double fare_amount; double toll_amount; std::ifstream input; input.open(filename); int total_trips = 0; if (input.is_open()) { while (input >> start_point >> end_point >> passengers >> distance >> fare_amount >> toll_amount) { //Set start point taxi_trips[total_trips][0] = start_point; taxi_trips[total_trips][1] = end_point; taxi_trips[total_trips][2] = passengers; taxi_trips[total_trips][3] = distance; taxi_trips[total_trips][4] = fare_amount; taxi_trips[total_trips][5] = toll_amount; taxi_trips[total_trips][6] = 0.0; taxi_trips[total_trips][7] = 0.0; total_trips++; } 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) { taxi_trips[i][7] = taxi_trips[i][6] / taxi_trips[i][3]; taxi_trips[i][7] = ceil(taxi_trips[i][7] * 100.0) / 100.0; } } int total_people = 0; double fares[50]; for (int i = 0; i < 50; i++) { fares[i] = 0; } for (int i = 0; i < total_trips; i++) { total_people += taxi_trips[i][2]; fares[i] = taxi_trips[i][6]; } cout << setw(10) << "Trip#" << setw(10) << "# ppl" << setw(10) << "Dist." << setw(10) << "Fare" << setw(10) << "Toll" << setw(10) << "Total" << setw(10) << "Cost/MI" << endl; 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; } Output_Extra_Stats(total_people, fares); } } void Output_Extra_Stats(int total_people, double fares[50]) { 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; cout << endl; cout << "People Transported: " << total_people << endl; cout << "Total Paid: " << total_fares << endl; cout << "Average Cost Per Person: " << average_cost_per_person << endl; } /* Pseudocode main(){ taxi_trips[50][8] read the file assign each list to an item in taxi_trips. Leaving the last two entries at 0.0 total_trips = amount of trips counted in file. for each trip in the file set the second to last item to the fare + toll check if the distance of the trip != 0 set the last item to the fare / distance int total_people = 0 double fares[50] for each trip in the file (using i) total_people += [i][2] fares[i] = taxi_trips[i][6] print the following from each trip in order # ppl -> Dist. -> Fare -> Toll -> Total -> Cost/MI Output_Extra_Stats(total_people, fares) } Output_Extra_Stats(int total_people, double fares[50]){ double total_fares = 0; for the amount of fares total_fares += fares[i] double average_cost_per_person = total_fares / total_people print total people, total paid, then average cost per person } */