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 | |
| parent | kinda working for small.txt (diff) | |
| download | cst116-lab3-m005a-b9a3e7e041ab815cdc75365e2b45315a2b74a14b.tar.xz cst116-lab3-m005a-b9a3e7e041ab815cdc75365e2b45315a2b74a14b.zip | |
formatted properly
| -rw-r--r-- | BlankConsoleLab/Lab3-Ahmed.cpp | 51 | ||||
| -rw-r--r-- | BlankConsoleLab/large.txt | 48 | ||||
| -rw-r--r-- | BlankConsoleLab/out.txt | 48 |
3 files changed, 120 insertions, 27 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"; diff --git a/BlankConsoleLab/large.txt b/BlankConsoleLab/large.txt new file mode 100644 index 0000000..1c3dbbb --- /dev/null +++ b/BlankConsoleLab/large.txt @@ -0,0 +1,48 @@ +129 7 3 1.3 7.5 0 +36 69 1 11.41 32 5.76 +7 41 1 4.6 15 5.76 +150 61 2 6.75 23 0 +112 17 1 3.84 15 0 +80 112 6 1.64 9.5 0 +256 183 1 16.08 44.5 0 +138 166 2 7.4 24.5 6.12 +142 50 5 1.7 8 0 +107 163 0 3.6 17 0 +132 3 2 19.1 52 6.12 +48 41 1 4.07 18 4.36 +132 226 1 14.3 39 0 +229 151 1 3.96 14.5 4.58 +238 166 1 0.76 4.5 0 +151 238 2 0.64 5 2.2 +138 82 4 3 12 0 +264 231 3 10.74 32.5 0 +170 114 5 2.01 9 0 +186 87 2 3.45 12 0 +209 256 1 3.79 17 0 +132 107 1 17.2 52 6.12 +232 112 1 3.1 11 0 +164 141 3 2.85 10.5 0 +129 7 3 1.3 7.5 0 +36 69 1 11.41 32 5.76 +7 41 1 4.6 15 5.76 +150 61 2 6.75 23 0 +112 17 1 3.84 15 0 +80 112 6 1.64 9.5 0 +256 183 1 16.08 44.5 0 +138 166 2 7.4 24.5 6.12 +142 50 5 1.7 8 0 +107 163 0 3.6 17 0 +132 3 2 19.1 52 6.12 +48 41 1 4.07 18 4.36 +132 226 1 14.3 39 0 +229 151 1 3.96 14.5 4.58 +238 166 1 0.76 4.5 0 +151 238 2 0.64 5 2.2 +138 82 4 3 12 0 +264 231 3 10.74 32.5 0 +170 114 5 2.01 9 0 +186 87 2 3.45 12 0 +209 256 1 3.79 17 0 +132 107 1 17.2 52 6.12 +232 112 1 3.1 11 0 +164 141 3 2.85 10.5 0 diff --git a/BlankConsoleLab/out.txt b/BlankConsoleLab/out.txt index 15c8169..addee3c 100644 --- a/BlankConsoleLab/out.txt +++ b/BlankConsoleLab/out.txt @@ -5,13 +5,55 @@ 150 61 2 6.75 23 0 3.40741 112 17 1 3.84 15 0 3.90625 80 112 6 1.64 9.5 0 5.79268 +256 183 1 16.08 44.5 0 2.76741 +138 166 2 7.4 24.5 6.12 4.13784 +142 50 5 1.7 8 0 4.70588 +107 163 0 3.6 17 0 4.72222 +132 3 2 19.1 52 6.12 3.04293 +48 41 1 4.07 18 4.36 5.49386 +132 226 1 14.3 39 0 2.72727 +229 151 1 3.96 14.5 4.58 4.81818 +238 166 1 0.76 4.5 0 5.92105 +151 238 2 0.64 5 2.2 11.25 +138 82 4 3 12 0 4 +264 231 3 10.74 32.5 0 3.02607 +170 114 5 2.01 9 0 4.47761 +186 87 2 3.45 12 0 3.47826 +209 256 1 3.79 17 0 4.48549 +132 107 1 17.2 52 6.12 3.37907 +232 112 1 3.1 11 0 3.54839 +164 141 3 2.85 10.5 0 3.68421 +129 7 3 1.3 7.5 0 5.76923 +36 69 1 11.41 32 5.76 3.30938 +7 41 1 4.6 15 5.76 4.51304 +150 61 2 6.75 23 0 3.40741 +112 17 1 3.84 15 0 3.90625 +80 112 6 1.64 9.5 0 5.79268 +256 183 1 16.08 44.5 0 2.76741 +138 166 2 7.4 24.5 6.12 4.13784 +142 50 5 1.7 8 0 4.70588 +107 163 0 3.6 17 0 4.72222 +132 3 2 19.1 52 6.12 3.04293 +48 41 1 4.07 18 4.36 5.49386 +132 226 1 14.3 39 0 2.72727 +229 151 1 3.96 14.5 4.58 4.81818 +238 166 1 0.76 4.5 0 5.92105 +151 238 2 0.64 5 2.2 11.25 +138 82 4 3 12 0 4 +264 231 3 10.74 32.5 0 3.02607 +170 114 5 2.01 9 0 4.47761 +186 87 2 3.45 12 0 3.47826 +209 256 1 3.79 17 0 4.48549 +132 107 1 17.2 52 6.12 3.37907 +232 112 1 3.1 11 0 3.54839 +164 141 3 2.85 10.5 0 3.68421 - ** Total Records: 6 ** + ** Avg Cost Per Person: 10.5204 ** - ** People Transported: 14 ** + ** People Transported: 100 ** - ** Total Cost: 113.52 ** + ** Total Cost: 1052.04 ** The End |