diff options
| author | Musa Ahmed <[email protected]> | 2022-11-29 12:54:17 -0800 |
|---|---|---|
| committer | Musa Ahmed <[email protected]> | 2022-11-29 12:54:17 -0800 |
| commit | b9a3e7e041ab815cdc75365e2b45315a2b74a14b (patch) | |
| tree | 2bfcd81aa6a18afca2c87cf2aa3b9399607deb8c /BlankConsoleLab/Lab3-Ahmed.cpp | |
| parent | kinda working for small.txt (diff) | |
| download | cst116-lab3-m005a-b9a3e7e041ab815cdc75365e2b45315a2b74a14b.tar.xz cst116-lab3-m005a-b9a3e7e041ab815cdc75365e2b45315a2b74a14b.zip | |
formatted properly
Diffstat (limited to 'BlankConsoleLab/Lab3-Ahmed.cpp')
| -rw-r--r-- | BlankConsoleLab/Lab3-Ahmed.cpp | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/BlankConsoleLab/Lab3-Ahmed.cpp b/BlankConsoleLab/Lab3-Ahmed.cpp index 3efa1aa..a78d875 100644 --- a/BlankConsoleLab/Lab3-Ahmed.cpp +++ b/BlankConsoleLab/Lab3-Ahmed.cpp @@ -19,9 +19,9 @@ using namespace std; const int MAX = 50; -int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float costPMile[], int counter, int people, int totalRecords, int paid, float totalFare[]); -void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float totalFare[], float costPMile[], int counter, float paid); -void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float totalFare[], float costPMile[], int counter, float paid); +int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float costPMile[], int counter, float totalFare[]); +void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float costPMile[]); +void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int passCount[], float distance[], float fare[], float toll[], float totalFare[], float costPMile[], float paid); int main() { @@ -49,13 +49,13 @@ int main() if (inFile.is_open()) { - record_counter = ReadData(inFile, outFile, pick, drop, passCount, distance, fare, toll, costPMile, counter, people, record_counter, paid, totalFare); + record_counter = ReadData(inFile, outFile, pick, drop, passCount, distance, fare, toll, costPMile, counter, totalFare); inFile.close(); if (outFile.is_open()) { - WriteOutputFile(outFile, record_counter, people, pick, drop, passCount, distance, fare, toll, totalFare, costPMile, counter, paid); - PrintTotalsAndSummary(outFile, record_counter, people, pick, drop, passCount, distance, fare, toll, totalFare, costPMile, counter, paid); + WriteOutputFile(outFile, record_counter, people, pick, drop, passCount, distance, fare, toll, costPMile); + PrintTotalsAndSummary(outFile, record_counter, people, passCount, distance, fare, toll, totalFare, costPMile, paid); outFile.close(); } else @@ -71,45 +71,47 @@ int main() } return 0; } -int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float costPMile[], int counter, int people, int totalRecords, int paid, float totalFare[]) +int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float costPMile[], int counter, float totalFare[]) { - cout << setiosflags(ios::left) << setw(19) + cout << setiosflags(ios::left) << setw(10) << "Trip" << setw(15) + << "Pick" << setw(10) << "Drop" << setw(10) << "# ppl" - << setw(18) << "Distance" << setw(22) + << setw(10) << "Distance" << setw(10) << "Fare" - << setw(20) << "Toll" - << setw(15) << "Total" - << setw(11) << "Cost per Mile" << endl; + << setw(10) << "Toll" + << setw(10) << "Total" + << setw(10) << "Cost per Mile" << endl; inFile >> pick[counter] >> drop[counter] >> passCount[counter] >> distance[counter] >> fare[counter] >> toll[counter]; // Priming Read while (!inFile.eof()) { totalFare[counter] = fare[counter] + toll[counter]; - cout << setiosflags(ios::left) << setw(20) - //<< pick[counter] - //<< setw(20) << drop[counter] << setw(20) + cout << setiosflags(ios::left) << setw(10) << counter << setw(15) + << pick[counter] + << setw(10) << drop[counter] << setw(10) << passCount[counter] - << setw(20) << distance[counter] << setw(20) + << setw(10) << distance[counter] << setw(10) << fare[counter] - << setw(20) << toll[counter] << setw(20) - << totalFare[counter] << setw(20); + << setw(10) << toll[counter] << setw(15) + << totalFare[counter] << setw(10); if (distance[counter] == 0) { costPMile[counter] = 0; } else { costPMile[counter] = (toll[counter] + fare[counter]) / distance[counter]; } - cout << setw(20) << setprecision(3) << costPMile[counter] << endl; + cout << setprecision(3) << costPMile[counter]; counter++; inFile >> pick[counter] >> drop[counter] >> passCount[counter] >> distance[counter] >> fare[counter] >> toll[counter]; + cout << endl; } return counter; } -void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float totalFare[], float costPMile[], int counter, float paid) +void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float costPMile[]) { @@ -128,7 +130,7 @@ void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[] } } -void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float totalFare[], float costPMile[], int count, float paid) +void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int passCount[], float distance[], float fare[], float toll[], float totalFare[], float costPMile[], float paid) { for (int i = 0; i < totalRecords; i++) { people += passCount[i]; @@ -139,20 +141,21 @@ void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int if (distance == 0) { costPMile[i] = 0; } + else { costPMile[i] = totalFare[i] / distance[i]; // cout << costPMile[i]; } } // To screen - cout << "\n\n\t** Total Records: " << totalRecords << " **\n" + cout << "\n\n\t** Avg Cost Per Person: " << paid/people << " **\n" << "\n\n\t** People Transported: " << people << " **\n" - << "\n\n\t** Total Cost: " << paid << " **\n" + << "\n\n\t** Total Cost: " << setprecision(5) << paid << " **\n" << "\t\t The End \n"; // To file - outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" + outFile << "\n\n\t** Avg Cost Per Person: " << paid/people << " **\n" << "\n\n\t** People Transported: " << people << " **\n" << "\n\n\t** Total Cost: " << paid << " **\n" << "\t\t The End \n"; |