/* Abdullah Havaldar CST116 - Lab3 Purpose: The purpose of this program is to take in a file which has the logs of a taxi service and output it in a formatted table along with the average per person, total people moved, and total cost */ //precompiler directives #include #include #include using namespace std; using std::cout; using std::cin; using std::endl; int main() { //initializing filename to ask user string fileName; //ask user for the filename and store file name cout << "Please enter the input file name including extension: "; cin >> fileName; //opening the file ifstream theFile(fileName); //variables within the opened file int count = 1; int pick; int drop; int ppl; double dis; double fare; double toll; //variables which are to calculate double avg = 0; int totalPpl = 0; double totalCost = 0; //write the column headers cout << left; cout << setw(20) << "Trip" << setw(20) << "Pickup" << setw(20) << "Dropoff" << setw(20) << "#ppl" << setw(20) << "Distance" << setw(20) << "Fare" << setw(20) << "Toll" << setw(20) << "Total" << setw(20) << "Cost/Mi" << endl; //within the opened file readin the columns as the followiung variables while (theFile >> pick >> drop >> ppl >> dis >> fare >> toll) { //take total for each row double total = fare + toll; //take price per mile for each row double cpm = total / dis; //output the elements in the file and the calculated vartiables cout << setw(20) << count << setw(20) << pick << setw(20) << drop << setw(20) << ppl << setw(20) << dis << setw(20) << fare << setw(20) << toll << setw(20) << total << setw(20) << setprecision(3) << cpm << endl; //add to totals count++; totalPpl += ppl; totalCost += total; } //calculate average avg = totalCost / totalPpl; cout << " " << endl; cout << " " << endl; cout << " " << endl; cout << "** Avg Cost Per Person: " << avg << " **" << endl; cout << "** People Transported: " << totalPpl << " **" << endl; cout << "** Total Paid: " << setprecision(7) << totalCost << " **" << endl; }