summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnibal LopezBonilla <[email protected]>2022-11-24 11:11:24 -0800
committerAnibal LopezBonilla <[email protected]>2022-11-24 11:11:24 -0800
commitb959c63972f80c1f7db8bc40d12f44d9f32ae3ce (patch)
tree94e9f4f432613ecd1201501441f0b3f21b750873
parentSetting up GitHub Classroom Feedback (diff)
downloadcst116-lab3-lopez-bonilla-b959c63972f80c1f7db8bc40d12f44d9f32ae3ce.tar.xz
cst116-lab3-lopez-bonilla-b959c63972f80c1f7db8bc40d12f44d9f32ae3ce.zip
Push 1
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp97
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj8
2 files changed, 96 insertions, 9 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index ed5f807..bb8a6ba 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -2,15 +2,102 @@
//
#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::ifstream;
+using std::ofstream;
+
+
+const int MAX = 100;
+
+int ReadData(ifstream& inFile, ofstream& outFile,int pickUP[],int DropO[],int Traveller[],float Dis[],float TollA[]);
+void WriteOutputFile(ofstream& outFile, int pickUP[], int DropO[], int Traveller[], float Dis[], float TollA[],
+ int counter);
+void PrintTotalsAndSummary(ofstream& out, int totalRecords);
int main()
{
- cout << "Hello World!\n";
+
+ int pickUP[MAX];
+ int dropO[MAX];
+ int Traveller[MAX];
+ float Dis[MAX];
+ float FareA[MAX];
+ float TollA[MAX];
+
+ ifstream inFile;
+ //"C:\Users\speed\TEMP"
+ // Notice how this automatically opens the file
+ ofstream outFile("C:\\Users\\speed\\TEMP\\Apollo17Output.txt");
+ //C:\\TEMP\\Chap_11_data.txt
+ inFile.open("C:\\Users\\speed\\TEMP\\Apollo_17.txt");
+
+ 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 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, 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++)
+ {
+ 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>