summaryrefslogtreecommitdiff
path: root/BlankConsoleLab
diff options
context:
space:
mode:
authorTrevor Bouchillon <[email protected]>2022-11-28 19:04:34 -0800
committerTrevor Bouchillon <[email protected]>2022-11-28 19:04:34 -0800
commit139c71911071c0b55355f2b2813e81d34bad49bc (patch)
tree954d6c1079c834ec330561639972d4d5f853a83c /BlankConsoleLab
parentSetting up GitHub Classroom Feedback (diff)
downloadcst116-lab3-daboochillin-139c71911071c0b55355f2b2813e81d34bad49bc.tar.xz
cst116-lab3-daboochillin-139c71911071c0b55355f2b2813e81d34bad49bc.zip
Starting with Ch11 Debug
Diffstat (limited to 'BlankConsoleLab')
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp93
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj8
2 files changed, 89 insertions, 12 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index ed5f807..f590282 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -1,16 +1,93 @@
-// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
-//
-
#include <iostream>
-
-using namespace std;
-
-using std::cout;
+#include <fstream> // For the files!!!!
+#include <iomanip> // For manipulators & formatting options
using std::cin;
+using std::cout;
using std::endl;
+using std::setw;
+using std::ios;
+using std::string;
+
+using std::ifstream;
+using std::ofstream;
+
+const int EMPLOYEES = 20;
+const int MAX = 21;
+
+string OutFileName = "C:\\TEMP\\Chap_11_ReportOut.txt";
+string InFileName = "C:\\TEMP\\Chap_11_Report.txt";
+
+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);
int main()
{
- cout << "Hello World!\n";
+ char name[EMPLOYEES][MAX];
+ int age[EMPLOYEES];
+ int record_counter(0);
+
+ ifstream inFile;
+
+ // Notice how this automatically opens the file
+ ofstream outFile(OutFileName); //changed output file to be seperate.
+
+ inFile.open(InFileName);
+
+ if (inFile.is_open())
+ {
+ record_counter = ReadData(inFile, outFile, name, age);
+ inFile.close();
+
+ if (outFile.is_open())
+ {
+ WriteOutputFile(outFile, name, age, record_counter);
+ PrintTotalsAndSummary(outFile, record_counter);
+ outFile.close();
+ }
+ else
+ {
+ cout << "Trouble Opening: " << OutFileName;
+ cout << "\n\n\t\t ** About to EXIT NOW! ** ";
+ }
+ }
+ else
+ {
+ cout << "Trouble Opening: " << InFileName;
+ cout << "\n\n\t\t ** About to EXIT NOW! ** ";
+ }
+ return 0;
+}
+int ReadData(ifstream& inFile, ofstream& outFile, char name[][MAX], int age[])
+{
+ int counter = 0;
+ inFile >> name[counter] >> age[counter]; // Priming Read
+
+ while (!inFile.eof())
+ {
+ cout << setiosflags(ios::left) << setw(25) << name[counter] << resetiosflags(ios::left) << setw(4) << age[counter] << endl;
+ counter++;
+ inFile >> name[counter] >> age[counter];
+ }
+
+ return counter;
+}
+void WriteOutputFile(ofstream& outFile, char name[][MAX], int age[], int counter)
+{
+ outFile << " Here is the Output File" << endl;
+ for (int r = 0; r < counter; r++) //made r a less than rather than less than or equal to.
+ {
+ outFile << setiosflags(ios::left) << setw(25) << name[r] << setw(4) << resetiosflags(ios::left) << age[r] << endl;
+ }
+}
+void PrintTotalsAndSummary(ofstream& outFile, 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"
+ << "\t\t The End \n";
}
diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj
index db2e734..d2e3ee2 100644
--- a/BlankConsoleLab/BlankConsoleLab.vcxproj
+++ b/BlankConsoleLab/BlankConsoleLab.vcxproj
@@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>