summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan <[email protected]>2022-11-02 15:03:28 -0700
committerEvan <[email protected]>2022-11-02 15:03:28 -0700
commitc5199f4951d3c6d80dbd65b3bcc2c33a3b03ddcd (patch)
treeccccf2e63dc5962c9679ce3844147a07161e2711
parentbn (diff)
downloadcst116-ch11-debugging-evanmihm-c5199f4951d3c6d80dbd65b3bcc2c33a3b03ddcd.tar.xz
cst116-ch11-debugging-evanmihm-c5199f4951d3c6d80dbd65b3bcc2c33a3b03ddcd.zip
f
-rw-r--r--CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp46
1 files changed, 24 insertions, 22 deletions
diff --git a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp b/CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp
index 3f8732e..4ecd4d1 100644
--- a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp
+++ b/CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp
@@ -38,7 +38,7 @@
*
* 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").
+* (i.e., Input.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.
@@ -69,8 +69,8 @@ using std::ofstream;
const int EMPLOYEES = 20;
const int MAX = 21;
-int ReadData(ifstream& inFile, ofstream& outFile, char name[][MAX], int age[]);
-void WriteOutputFile(ofstream& outFile, char name[][MAX], int age[],
+int ReadData(ifstream& Input, ofstream& Output, char name[][MAX], int age[]);
+void WriteOutputFile(ofstream& Output, char name[][MAX], int age[],
int counter);
void PrintTotalsAndSummary(ofstream& out, int totalRecords);
@@ -80,23 +80,25 @@ int main()
int age[EMPLOYEES];
int record_counter(0);
- ifstream inFile;
+ ifstream Input;
// Notice how this automatically opens the file
- ofstream outFile("C:\\Users\\iceag\\source\\CHPT11.txt");
+ ofstream Output("C:\\TEMP\\Chap_11_Report.txt");
- inFile.open("C:\\Users\\iceag\\source\\CHPT11.txt");
+ //C:\\Users\\iceag\\source\\CHPT11I.txt
+
+ Input.open("C:\\TEMP\\Chap_11_data.txt");
- if (inFile.is_open())
+ if (Input.is_open())
{
- record_counter = ReadData(inFile, outFile, name, age);
- inFile.close();
+ record_counter = ReadData(Input, Output, name, age);
+ Input.close();
- if (outFile.is_open())
+ if (Output.is_open())
{
- WriteOutputFile(outFile, name, age, record_counter);
- PrintTotalsAndSummary(outFile, record_counter);
- outFile.close();
+ WriteOutputFile(Output, name, age, record_counter);
+ PrintTotalsAndSummary(Output, record_counter);
+ Output.close();
}
else
{
@@ -111,40 +113,40 @@ int main()
}
return 0;
}
-int ReadData(ifstream& inFile, ofstream& outFile, char name[][MAX], int age[])
+int ReadData(ifstream& Input, ofstream& Output, char name[][MAX], int age[])
{
int counter = 0;
- inFile >> name[counter] >> age[counter]; // Priming Read
+ Input >> name[counter] >> age[counter]; // Priming Read
- while (!inFile.eof())
+ while (!Input.eof())
{
cout << setiosflags(ios::left) << setw(25)
<< name[counter] << resetiosflags(ios::left)
<< setw(4) << age[counter] << endl;
counter++;
- inFile >> name[counter] >> age[counter];
+ Input >> name[counter] >> age[counter];
}
return counter;
}
-void WriteOutputFile(ofstream& outFile, char name[][MAX], int age[], int counter)
+void WriteOutputFile(ofstream& Output, char name[][MAX], int age[], int counter)
{
- outFile << " Here is the Output File" << endl;
+ Output << " Here is the Output File" << endl;
for (int r = 0; r <= counter; r++)
{
- outFile << setiosflags(ios::left) << setw(25)
+ Output << setiosflags(ios::left) << setw(25)
<< name[r] << setw(4)
<< resetiosflags(ios::left) << age[r]
<< endl;
}
}
-void PrintTotalsAndSummary(ofstream& outFile, int totalRecords)
+void PrintTotalsAndSummary(ofstream& Output, int totalRecords)
{
// To screen
cout << "\n\n\t** Total Records: " << totalRecords << " **\n"
<< "\t\t The End \n";
// To file
- outFile << "\n\n\t** Total Records: " << totalRecords << " **\n"
+ Output << "\n\n\t** Total Records: " << totalRecords << " **\n"
<< "\t\t The End \n";
}