summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacobdw22 <[email protected]>2022-11-28 14:31:11 -0800
committerjacobdw22 <[email protected]>2022-11-28 14:31:11 -0800
commitece631306a70f3e08cc8358b484528456648426e (patch)
tree738bcbb5e010a3f6f286f3414d557970503caea6
parentAdded output file to project (diff)
downloadcst116-lab3-jacobdw22-ece631306a70f3e08cc8358b484528456648426e.tar.xz
cst116-lab3-jacobdw22-ece631306a70f3e08cc8358b484528456648426e.zip
Added small.txt and made some changes to the code. Also added a way to choose which file is opened
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj3
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj.filters3
-rw-r--r--BlankConsoleLab/cst116-lab3-wilson.cpp (renamed from BlankConsoleLab/BlankConsoleLab.cpp)36
3 files changed, 33 insertions, 9 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj
index 1c2a947..c0a5b52 100644
--- a/BlankConsoleLab/BlankConsoleLab.vcxproj
+++ b/BlankConsoleLab/BlankConsoleLab.vcxproj
@@ -139,10 +139,11 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
- <ClCompile Include="BlankConsoleLab.cpp" />
+ <ClCompile Include="cst116-lab3-wilson.cpp" />
</ItemGroup>
<ItemGroup>
<Text Include="..\..\..\..\..\..\TEMP1\lab3_Report.txt" />
+ <Text Include="..\..\..\..\..\..\TEMP1\small.txt" />
<Text Include="..\..\..\..\Downloads\large.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters
index 60f7705..cebb774 100644
--- a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters
+++ b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters
@@ -15,12 +15,13 @@
</Filter>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="BlankConsoleLab.cpp">
+ <ClCompile Include="cst116-lab3-wilson.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="..\..\..\..\Downloads\large.txt" />
<Text Include="..\..\..\..\..\..\TEMP1\lab3_Report.txt" />
+ <Text Include="..\..\..\..\..\..\TEMP1\small.txt" />
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/cst116-lab3-wilson.cpp
index 113ca96..f58bd45 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/cst116-lab3-wilson.cpp
@@ -15,13 +15,16 @@ using std::setw;
using std::ios;
using std::ifstream;
using std::ofstream;
-const int MAX = 100;
-int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float
+
+const int MAX = 60;
+
+int ReadData(ifstream& inFile, ofstream& outFile, 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()
{
int pick[MAX];
@@ -31,21 +34,40 @@ int main()
float fare[MAX];
float toll[MAX];
int record_counter(0);
+
ifstream inFile;
+
// Notice how this automatically opens the file
+
ofstream outFile("lab3_Report.txt");
- inFile.open("large.txt");
+
+ char file = 'a';
+ cout << "Please choose a file to open. Press 's' for small.txt, or press 'l' for large.txt: ";
+ cin >> file;
+ cout << endl;
+ while (file != 's' && file != 'l'){
+ switch (file) {
+ case 's':
+ inFile.open("small.txt");
+ break;
+ case 'l':
+ inFile.open("large.txt");
+ break;
+ default:
+ break;
+ }
+ }
+
if (inFile.is_open())
{
- record_counter = ReadData(inFile, pick, drop, psgr, dist,
+ record_counter = ReadData(inFile, outFile, 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);
+ PrintTotalsAndSummary(outFile, record_counter);
outFile.close();
}
else
@@ -61,7 +83,7 @@ int main()
}
return 0;
}
-int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float
+int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int psgr[], float
dist[], float fare[], float toll[])
{
int counter = 0;