summaryrefslogtreecommitdiff
path: root/CST116-Ch11-Debugging
diff options
context:
space:
mode:
Diffstat (limited to 'CST116-Ch11-Debugging')
-rw-r--r--CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp72
1 files changed, 35 insertions, 37 deletions
diff --git a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp b/CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp
index 98c776a..3246402 100644
--- a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp
+++ b/CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp
@@ -9,38 +9,38 @@
* 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
+* add the inFile 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
+* 3) Open the inFile 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
+* 7) Examine the code and the outFile and notice the use of
* parallel arrays.
-* 8) Add the output file created via the execution of
+* 8) Add the outFile 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 notice how Visual Studio has rewritten your outFile 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.
+* 9) Examine the contents of both the inFile and the outFile 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.
+* the outFile. Verify that your outFile is appropriate for your
+ inFile file.
* 11) Build and execute your code until you have all errors
-* removed and all the output is correct.
+* removed and all the outFile is correct.
*
* Debugging Exercise 2
*
-* 1) Replace the double slashes (\\) in the input file open statement
+* 1) Replace the double slashes (\\) in the inFile file open statement
* with only a single slash
-* (i.e., Input.open("C:\TEMP\Chap_11_data.txt").
+* (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
+* 4) Change both the inFile and outFile 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
@@ -49,7 +49,7 @@
* 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.
+* outFile on both the console and in the outFile file.
*
********************************************************************/
#include <iostream>
@@ -67,8 +67,8 @@ using std::ofstream;
const int EMPLOYEES = 20;
const int MAX = 21;
-int ReadData(ifstream& Input, ofstream& Output, char name[][MAX], int age[]);
-void WriteOutputFile(ofstream& Output, char name[][MAX], int age[],
+int ReadData(ifstream& inFile, ofstream& outFile, char name[][MAX], int age[]);
+void WriteOutputFile(ofstream& outFile, char name[][MAX], int age[],
int counter);
void PrintTotalsAndSummary(ofstream& out, int totalRecords);
@@ -78,25 +78,23 @@ int main()
int age[EMPLOYEES];
int record_counter(0);
- ifstream Input;
+ ifstream inFile;
// Notice how this automatically opens the file
- ofstream Output("C:\\Users\\iceag\\source\\TestO.txt");
+ ofstream outFile("C:\\Users\\iceag\\source\\TestO.txt");
+
+ inFile.open("C:\\Users\\iceag\\source\\repos\\cst116-ch11-debugging-evanmihm\\Chap_11_data.txt");
- //C:\\Users\\iceag\\source\\CHPT11I.txt
-
- Input.open("C:\\Users\\iceag\\source\\TestI.txt");
-
- if (Input.is_open())
+ if (inFile.is_open())
{
- record_counter = ReadData(Input, Output, name, age);
- Input.close();
+ record_counter = ReadData(inFile, outFile, name, age);
+ inFile.close();
- if (Output.is_open())
+ if (outFile.is_open())
{
- WriteOutputFile(Output, name, age, record_counter);
- PrintTotalsAndSummary(Output, record_counter);
- Output.close();
+ WriteOutputFile(outFile, name, age, record_counter);
+ PrintTotalsAndSummary(outFile, record_counter);
+ outFile.close();
}
else
{
@@ -111,40 +109,40 @@ int main()
}
return 0;
}
-int ReadData(ifstream& Input, ofstream& Output, char name[][MAX], int age[])
+int ReadData(ifstream& inFile, ofstream& outFile, char name[][MAX], int age[])
{
int counter = 0;
- Input >> name[counter] >> age[counter]; // Priming Read
+ inFile >> name[counter] >> age[counter]; // Priming Read
- while (!Input.eof())
+ while (!inFile.eof())
{
cout << setiosflags(ios::left) << setw(25)
<< name[counter] << resetiosflags(ios::left)
<< setw(4) << age[counter] << endl;
counter++;
- Input >> name[counter] >> age[counter];
+ inFile >> name[counter] >> age[counter];
}
return counter;
}
-void WriteOutputFile(ofstream& Output, char name[][MAX], int age[], int counter)
+void WriteOutputFile(ofstream& outFile, char name[][MAX], int age[], int counter)
{
- Output << " Here is the Output File" << endl;
+ outFile << " Here is the outFile File" << endl;
for (int r = 0; r <= counter; r++)
{
- Output << setiosflags(ios::left) << setw(25)
+ outFile << setiosflags(ios::left) << setw(25)
<< name[r] << setw(4)
<< resetiosflags(ios::left) << age[r]
<< endl;
}
}
-void PrintTotalsAndSummary(ofstream& Output, int totalRecords)
+void PrintTotalsAndSummary(ofstream& outFile, int totalRecords)
{
// To screen
cout << "\n\n\t** Total Records: " << totalRecords << " **\n"
<< "\t\t The End \n";
// To file
- Output << "\n\n\t** Total Records: " << totalRecords << " **\n"
+ outFile << "\n\n\t** Total Records: " << totalRecords << " **\n"
<< "\t\t The End \n";
}