diff options
| author | Joe Traver <[email protected]> | 2022-11-26 21:05:22 -0800 |
|---|---|---|
| committer | Joe Traver <[email protected]> | 2022-11-26 21:05:22 -0800 |
| commit | da6d02cd6b9a3059b9a789e5c12d07b417994bc7 (patch) | |
| tree | d743a8c26624a8a8459b511656387c04785fc40b | |
| parent | Main (diff) | |
| download | cst116-lab3-joetraver30-da6d02cd6b9a3059b9a789e5c12d07b417994bc7.tar.xz cst116-lab3-joetraver30-da6d02cd6b9a3059b9a789e5c12d07b417994bc7.zip | |
Added total fare and cost per mile
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index b8844eb..3c0db4a 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -9,6 +9,8 @@ using std::cin; using std::cout; using std::endl; using std::setw; +using std::setprecision; +using std::fixed; using std::ios; using std::ifstream; @@ -17,7 +19,7 @@ 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[]); +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[], int counter); void PrintTotalsAndSummary(ofstream& out, int totalRecords); @@ -32,6 +34,7 @@ int main() float fare[MAX]; float toll[MAX]; float tfare[MAX]; + float CPM[MAX]; int record_counter(0); ifstream inFile; @@ -42,7 +45,7 @@ int main() if (inFile.is_open()) { - record_counter = ReadData(inFile, pick, drop, psgr, dist, fare, toll, tfare); + record_counter = ReadData(inFile, pick, drop, psgr, dist, fare, toll, tfare, CPM); inFile.close(); if (outFile.is_open()) @@ -67,7 +70,7 @@ int main() } -int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], float tfare[]) +int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], float tfare[], float CPM[]) { int counter = 0; inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> dist[counter] >> fare[counter] >> toll[counter]; @@ -75,8 +78,9 @@ int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], while (!inFile.eof()) { tfare[counter] = fare[counter] + toll[counter]; + CPM[counter] = fare[counter] / dist[counter]; - cout << setiosflags(ios::left) << setw(5) + cout << fixed << setprecision(2) << setiosflags(ios::left) << setw(5) << pick[counter] << resetiosflags(ios::left) << setw(10) << drop[counter] << resetiosflags(ios::left) << setw(12) << psgr[counter] << resetiosflags(ios::left) @@ -84,6 +88,7 @@ int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], << setw(14) << fare[counter] << resetiosflags(ios::left) << setw(14) << toll[counter] << resetiosflags(ios::left) << setw(14) << tfare[counter] << resetiosflags(ios::left) + << setw(14) << CPM[counter] << resetiosflags(ios::left) << endl; counter++; inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> dist[counter] >> fare[counter] >> toll[counter] >> tfare[counter]; |