diff options
| author | Musa Ahmed <[email protected]> | 2022-11-27 17:28:02 -0800 |
|---|---|---|
| committer | Musa Ahmed <[email protected]> | 2022-11-27 17:28:02 -0800 |
| commit | 683c808c9840072b14bcf3395aa85bad8ff2f6e7 (patch) | |
| tree | 93df4c5e67c578aa4b8f2f74614808ed756e4ee7 | |
| parent | added reading for each dataset in file (diff) | |
| download | cst116-lab3-m005a-683c808c9840072b14bcf3395aa85bad8ff2f6e7.tar.xz cst116-lab3-m005a-683c808c9840072b14bcf3395aa85bad8ff2f6e7.zip | |
kinda working for small.txt
| -rw-r--r-- | BlankConsoleLab/Lab3-Ahmed.cpp | 88 | ||||
| -rw-r--r-- | BlankConsoleLab/out.txt | 14 | ||||
| -rw-r--r-- | BlankConsoleLab/read.txt | 11 | ||||
| -rw-r--r-- | BlankConsoleLab/temp.txt | 6 |
4 files changed, 44 insertions, 75 deletions
diff --git a/BlankConsoleLab/Lab3-Ahmed.cpp b/BlankConsoleLab/Lab3-Ahmed.cpp index 9f41313..3efa1aa 100644 --- a/BlankConsoleLab/Lab3-Ahmed.cpp +++ b/BlankConsoleLab/Lab3-Ahmed.cpp @@ -1,57 +1,4 @@ -/******************************************************************** -* File: Chapter 11 Debug.cpp -* -* General Instructions: Complete each step before proceeding to the -* next. -* -* Debugging Exercise 1 -* -* 1) Make your own data file like Troy 12, with the next person on the -* next line and save it to a directory you create on your drive. -* 2) Under the Project menu, select Add Existing Item and -* add the input file you just placed on your drive to your -* current project. Make sure your Solution Explorer window -* is visible. If not, you can display it by selecting Solution -* Explorer (or Ctrl+Alt+L). -* 3) Open the input file by simply double clicking the name of the -* file in your Solution Explorer. -* 4) Build and execute the program. -* 5) Update the file paths below to correctly represent the path you -* created. -* 6) Rebuild and execute the program. -* 7) Examine the code and the output and notice the use of -* parallel arrays. -* 8) Add the output file created via the execution of -* your program to your Project. Execute your program again -* and notice how Visual Studio has rewritten your output file -* and asks if you would like to reload the file (select Yes). -* 9) Examine the contents of both the input and the output file. -* 10) Fix all the problems in your code that exist in relation to -* the output. Verify that your output is appropriate for your - input file. -* 11) Build and execute your code until you have all errors -* removed and all the output is correct. -* -* Debugging Exercise 2 -* -* 1) Replace the double slashes (\\) in the input file open statement -* with only a single slash -* (i.e., inFile.open("C:\TEMP\Chap_11_data.txt"). -* 2) Build your code, noticing the impact of the invalid path you -* created in the previous step. -* 3) Replace the backslashes as they were. -* 4) Change both the input and output filenames so they are -* invalid. -* 5) Update the file related error messages within the code -* to also provide the specific name of the file that is having a -* problem. -* 6) Rebuild and execute your program to verify that your messages -* are correct. -* 7) Correct the path names. -* 8) Build and execute your code and carefully check your -* output on both the console and in the output file. -* -********************************************************************/ + #include <iostream> #include <fstream> // For the files!!!! #include <iomanip> // For manipulators & formatting options @@ -69,7 +16,7 @@ using std::ofstream; using namespace std; -const int EMPLOYEES = 50; + 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[]); @@ -78,11 +25,11 @@ void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int int main() { - int pick[EMPLOYEES]; + int pick[MAX]; int drop[MAX]; - int passCount[EMPLOYEES]; + int passCount[MAX]; float distance[MAX]; - float fare[EMPLOYEES]; + float fare[MAX]; float toll[MAX]; float totalFare[MAX] = { 0 }; float costPMile[MAX] = { 0 }; @@ -107,8 +54,8 @@ int main() if (outFile.is_open()) { - 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, totalFare, costPMile, counter, paid); + PrintTotalsAndSummary(outFile, record_counter, people, pick, drop, passCount, distance, fare, toll, totalFare, costPMile, counter, paid); outFile.close(); } else @@ -126,26 +73,35 @@ int main() } 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[]) { + - + cout << setiosflags(ios::left) << setw(19) + << "# ppl" + << setw(18) << "Distance" << setw(22) + << "Fare" + << setw(20) << "Toll" + << setw(15) << "Total" + << setw(11) << "Cost per Mile" << endl; inFile >> pick[counter] >> drop[counter] >> passCount[counter] >> distance[counter] >> fare[counter] >> toll[counter]; // Priming Read while (!inFile.eof()) { - cout << setiosflags(ios::left) << setw(15) - << pick[counter] - << setw(15) << drop[counter] << setw(15) + totalFare[counter] = fare[counter] + toll[counter]; + cout << setiosflags(ios::left) << setw(20) + //<< pick[counter] + //<< setw(20) << drop[counter] << setw(20) << passCount[counter] - << setw(15) << distance[counter] << setw(15) + << setw(20) << distance[counter] << setw(20) << fare[counter] - << setw(15) << toll[counter]; + << setw(20) << toll[counter] << setw(20) + << totalFare[counter] << setw(20); if (distance[counter] == 0) { costPMile[counter] = 0; } else { costPMile[counter] = (toll[counter] + fare[counter]) / distance[counter]; } - cout << setw(15) << costPMile[counter] << endl; + cout << setw(20) << setprecision(3) << costPMile[counter] << endl; counter++; inFile >> pick[counter] >> drop[counter] >> passCount[counter] >> distance[counter] >> fare[counter] >> toll[counter]; diff --git a/BlankConsoleLab/out.txt b/BlankConsoleLab/out.txt index 35ec2bd..15c8169 100644 --- a/BlankConsoleLab/out.txt +++ b/BlankConsoleLab/out.txt @@ -1,3 +1,10 @@ + Here is the Output File +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 ** Total Records: 6 ** @@ -8,10 +15,3 @@ ** Total Cost: 113.52 ** The End - Here is the Output File -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 diff --git a/BlankConsoleLab/read.txt b/BlankConsoleLab/read.txt index 2bfcbd5..d5ff001 100644 --- a/BlankConsoleLab/read.txt +++ b/BlankConsoleLab/read.txt @@ -1,4 +1,11 @@ -John 19 +129 7 3 1.3 7.5 0 + +36 69 1 11.41 32 5.76 + +7 41 1 4.6 15 5.76 + + +John 19 Molly 23 Tim 48 Keil 42 @@ -9,4 +16,4 @@ Kevin 27 Cheryl 32 Kim 16 Dave 25 -Will 34
\ No newline at end of file +Will 34
\ No newline at end of file diff --git a/BlankConsoleLab/temp.txt b/BlankConsoleLab/temp.txt new file mode 100644 index 0000000..94e4c00 --- /dev/null +++ b/BlankConsoleLab/temp.txt @@ -0,0 +1,6 @@ +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 |