summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor Rogers <[email protected]>2022-11-27 12:34:36 -0800
committerTaylor Rogers <[email protected]>2022-11-27 12:34:36 -0800
commit2d3ab4f111f1f760717ef067b5f68399093ec4b3 (patch)
tree5adba244f2bf7af8cb3142d9c11239c14fcb0cb6
parentAdded directives (diff)
downloadcst116-lab3-taylorrog-2d3ab4f111f1f760717ef067b5f68399093ec4b3.tar.xz
cst116-lab3-taylorrog-2d3ab4f111f1f760717ef067b5f68399093ec4b3.zip
Added filename function
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp102
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj11
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj.filters5
-rw-r--r--BlankConsoleLab/lab3_Report.txt11
-rw-r--r--BlankConsoleLab/lab3_data.txt6
5 files changed, 130 insertions, 5 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index 70f43fd..0716815 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -13,10 +13,110 @@ using std::setw;
using std::ios;
using std::ifstream;
using std::ofstream;
+using std::string;
+const int MAX = 100;
+
+int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[]);
+void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[],
+ int counter);
+void PrintTotalsAndSummary(ofstream& out, int totalRecords);
int main()
{
- cout << "Hello World!\n";
+
+ int pick[MAX];
+ int drop[MAX];
+ int psgr[MAX];
+ float dist[MAX];
+ float fare[MAX];
+ float toll[MAX];
+ int record_counter(0);
+
+ string filename;
+
+ cout << "Enter the file name you wish to read data from: ";
+ cin >> filename;
+ cout << endl;
+
+ ifstream inFile;
+
+ // Notice how this automatically opens the file
+ ofstream outFile("lab3_Report.txt");
+
+ inFile.open(filename);
+
+ if (inFile.is_open())
+ {
+ record_counter = ReadData(inFile, pick, drop, psgr, dist, fare, toll);
+ inFile.close();
+
+ if (outFile.is_open())
+ {
+ WriteOutputFile(outFile, pick, drop, psgr, dist, fare, toll, record_counter);
+ PrintTotalsAndSummary(outFile, record_counter);
+ outFile.close();
+ }
+ else
+ {
+ cout << "Trouble Opening File";
+ cout << "\n\n\t\t ** About to EXIT NOW! ** ";
+ }
+
+ }
+ else
+ {
+ cout << "Trouble Opening File";
+ cout << "\n\n\t\t ** About to EXIT NOW! ** ";
+ }
+ return 0;
}
+int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[])
+{
+ int counter = 0;
+ inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> dist[counter] >> fare[counter] >> toll[counter]; // Priming Read
+ while (!inFile.eof())
+ {
+ cout << setiosflags(ios::left) << setw(5)
+ << pick[counter] << resetiosflags(ios::left)
+ << setw(10) << drop[counter] << resetiosflags(ios::left)
+ << setw(12) << psgr[counter] << resetiosflags(ios::left)
+ << setw(14) << dist[counter] << resetiosflags(ios::left)
+ << setw(14) << fare[counter] << resetiosflags(ios::left)
+ << setw(14) << toll[counter]
+ << endl;
+ counter++;
+ inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> dist[counter] >> fare[counter] >> toll[counter];
+ }
+
+ return counter;
+}
+
+void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[],
+ int counter)
+{
+ outFile << " Here is the Output File" << endl;
+ for (int r = 0; r <= counter - 1; r++)
+ {
+ outFile << setiosflags(ios::left) << setw(5)
+ << pick[r] << resetiosflags(ios::left)
+ << setw(10) << drop[r] << resetiosflags(ios::left)
+ << setw(12) << psgr[r] << resetiosflags(ios::left)
+ << setw(14) << dist[r] << resetiosflags(ios::left)
+ << setw(14) << fare[r] << resetiosflags(ios::left)
+ << setw(14) << toll[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..c9db51f 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>
@@ -141,6 +141,9 @@
<ItemGroup>
<ClCompile Include="BlankConsoleLab.cpp" />
</ItemGroup>
+ <ItemGroup>
+ <Text Include="lab3_data.txt" />
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters
index aca1dd9..b5f4096 100644
--- a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters
+++ b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters
@@ -19,4 +19,9 @@
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
+ <ItemGroup>
+ <Text Include="lab3_data.txt">
+ <Filter>Source Files</Filter>
+ </Text>
+ </ItemGroup>
</Project> \ No newline at end of file
diff --git a/BlankConsoleLab/lab3_Report.txt b/BlankConsoleLab/lab3_Report.txt
new file mode 100644
index 0000000..1b24b39
--- /dev/null
+++ b/BlankConsoleLab/lab3_Report.txt
@@ -0,0 +1,11 @@
+ Here is the Output File
+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
+
+
+ ** Total Records: 6 **
+ The End
diff --git a/BlankConsoleLab/lab3_data.txt b/BlankConsoleLab/lab3_data.txt
new file mode 100644
index 0000000..18f3c16
--- /dev/null
+++ b/BlankConsoleLab/lab3_data.txt
@@ -0,0 +1,6 @@
+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