diff options
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 63 |
1 files changed, 40 insertions, 23 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index 2adcb04..160c136 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -20,12 +20,12 @@ using std::ofstream; const int MAX = 100; int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], float tfare[], float CPM[]); -void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], +void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], float tfare[], float CPM[], int counter); void PrintTotalsAndSummary(ofstream& outFile, int totalRecords); -void PassengerCount(int psgr[], int counter, int &pplt); -void TotalPaid(float tfare[], int counter, float &paid); -void AverageCostPerPerson(float paid, int pplt, float ACM); +void PassengerCount(ofstream& outFile, int psgr[], int counter, int &pplt); +void TotalPaid(ofstream& outFile, float tfare[], int counter, float &paid); +void AverageCostPerPerson(ofstream& outFile, float paid, int pplt, float ACM); int main() { @@ -57,10 +57,10 @@ int main() if (outFile.is_open()) { - WriteOutputFile(outFile, pick, drop, psgr, dist, fare, toll, record_counter); - PassengerCount(psgr, record_counter, pplt); - TotalPaid(tfare, record_counter, paid); - AverageCostPerPerson(paid, pplt, ACM); + WriteOutputFile(outFile, pick, drop, psgr, dist, fare, toll, tfare, CPM, record_counter); + PassengerCount(outFile, psgr, record_counter, pplt); + TotalPaid(outFile, tfare, record_counter, paid); + AverageCostPerPerson(outFile, paid, pplt, ACM); PrintTotalsAndSummary(outFile, record_counter); outFile.close(); } @@ -124,23 +124,37 @@ int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], return counter; } -void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], +void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], float tfare[], float CPM[], int counter) { - outFile << " Here is the Output File" << endl; + outFile << "\n\n\t\t\t\t\t\t\t Here is the Output File" << endl << endl; + outFile << setiosflags(ios::left) + << "Pickup location" << resetiosflags(ios::left) + << setw(24) << "Drop-off location" << resetiosflags(ios::left) + << setw(15) << "# of ppl" << resetiosflags(ios::left) + << setw(17) << "Distance" << resetiosflags(ios::left) + << setw(11) << "Fare" << resetiosflags(ios::left) + << setw(15) << "Toll" << resetiosflags(ios::left) + << setw(16) << "Total Fare" << resetiosflags(ios::left) + << setw(18) << "Cost Per Mile" << resetiosflags(ios::left) + << endl << endl; + for (int i = 0; i < counter; i++) { - outFile << setiosflags(ios::left) << setw(5) + outFile << fixed << setprecision(2) << setiosflags(ios::left) << setw(10) << pick[i] << resetiosflags(ios::left) - << setw(10) << drop[i] << resetiosflags(ios::left) - << setw(12) << psgr[i] << resetiosflags(ios::left) - << setw(14) << dist[i] << resetiosflags(ios::left) + << setw(20) << drop[i] << resetiosflags(ios::left) + << setw(20) << psgr[i] << resetiosflags(ios::left) + << setw(19) << dist[i] << resetiosflags(ios::left) << setw(14) << fare[i] << resetiosflags(ios::left) - << setw(14) << toll[i] + << setw(14) << toll[i] << resetiosflags(ios::left) + << setw(14) << tfare[i] << resetiosflags(ios::left) + << setw(14) << CPM[i] << resetiosflags(ios::left) << endl; } + } -void PassengerCount(int psgr[], int counter, int &pplt) +void PassengerCount(ofstream& outFile, int psgr[], int counter, int &pplt) { for (int i = 0; i < counter; i++) @@ -150,10 +164,11 @@ void PassengerCount(int psgr[], int counter, int &pplt) } - cout << endl << "Total number of passengers transported: " << pplt << endl; + cout << endl << "\t\t\t\t\t\tTotal number of passengers transported: " << pplt << endl; + outFile << fixed << setprecision(2) << endl << "\t\t\t\t\t\tTotal number of passengers transported: " << pplt << endl; } -void TotalPaid(float tfare[], int counter, float &paid) +void TotalPaid(ofstream& outFile, float tfare[], int counter, float &paid) { for (int i = 0; i < counter; i++) @@ -163,16 +178,18 @@ void TotalPaid(float tfare[], int counter, float &paid) } - cout << "Total fairs paid: $" << paid << endl; + cout << "\t\t\t\t\t\tTotal fairs paid: $" << paid << endl; + outFile << fixed << setprecision(2) << "\t\t\t\t\t\tTotal fairs paid: $" << paid << endl; } -void AverageCostPerPerson(float paid, int pplt, float ACM) +void AverageCostPerPerson(ofstream& outFile, float paid, int pplt, float ACM) { ACM = paid / pplt; - cout << "Average cost per person: $" << ACM << endl; + cout << "\t\t\t\t\t\tAverage cost per person: $" << ACM << endl; + outFile << fixed << setprecision(2) << "\t\t\t\t\t\tAverage cost per person: $" << ACM << endl; } @@ -183,6 +200,6 @@ void PrintTotalsAndSummary(ofstream& outFile, int totalRecords) << "\t\t\t\t\t\t\t The End \n"; - outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" - << "\t\t The End \n"; + outFile << "\n\n\t\t\t\t\t\t** Total Records: " << totalRecords << " **\n" + << "\t\t\t\t\t\t\t The End \n"; } |