summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirducken <[email protected]>2022-11-29 13:39:16 -0800
committerBirducken <[email protected]>2022-11-29 13:39:16 -0800
commitbc6ce66dc7656a2c056e0c6c33bd81bde5cfc585 (patch)
treef44457621686c2e322c9d4ddf7d8c47b5fbb3e32
parentAdded summary. (diff)
downloadarchived-cst116-lab3-stark-bc6ce66dc7656a2c056e0c6c33bd81bde5cfc585.tar.xz
archived-cst116-lab3-stark-bc6ce66dc7656a2c056e0c6c33bd81bde5cfc585.zip
Added comments.
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj2
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj.filters2
-rw-r--r--BlankConsoleLab/cst116-lab3-stark-psuedo-code.txt4
-rw-r--r--BlankConsoleLab/cst116-lab3-stark.cpp21
-rw-r--r--BlankConsoleLab/large.txt48
5 files changed, 69 insertions, 8 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj
index 2ff956d..0cd3fe0 100644
--- a/BlankConsoleLab/BlankConsoleLab.vcxproj
+++ b/BlankConsoleLab/BlankConsoleLab.vcxproj
@@ -143,6 +143,8 @@
<ClCompile Include="cst116-lab3-stark.cpp" />
</ItemGroup>
<ItemGroup>
+ <Text Include="cst116-lab3-stark-psuedo-code.txt" />
+ <Text Include="large.txt" />
<Text Include="small.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters
index 970febb..246f02a 100644
--- a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters
+++ b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters
@@ -21,5 +21,7 @@
</ItemGroup>
<ItemGroup>
<Text Include="small.txt" />
+ <Text Include="large.txt" />
+ <Text Include="cst116-lab3-stark-psuedo-code.txt" />
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/BlankConsoleLab/cst116-lab3-stark-psuedo-code.txt b/BlankConsoleLab/cst116-lab3-stark-psuedo-code.txt
new file mode 100644
index 0000000..70971f3
--- /dev/null
+++ b/BlankConsoleLab/cst116-lab3-stark-psuedo-code.txt
@@ -0,0 +1,4 @@
+Trenton Stark
+CST 116
+Lab 3 Psuedo Code
+
diff --git a/BlankConsoleLab/cst116-lab3-stark.cpp b/BlankConsoleLab/cst116-lab3-stark.cpp
index e072d68..b4cca4c 100644
--- a/BlankConsoleLab/cst116-lab3-stark.cpp
+++ b/BlankConsoleLab/cst116-lab3-stark.cpp
@@ -1,3 +1,7 @@
+// Trenton Stark
+// CST 116
+// Lab 3
+
#include <iostream>
#include <fstream>
#include <string>
@@ -12,7 +16,7 @@ using std::setw;
using std::setprecision;
using std::fixed;
-const int width = 10;
+const int width = 10; //Affects all tables
void readFile(ifstream& fin, double fares[], int& totalPass);
void summary(double fares[], int& totalPass);
@@ -20,9 +24,10 @@ void summary(double fares[], int& totalPass);
int main() {
ifstream fin;
string fName;
- double fares[50] = { 0 };
+ double fares[50] = { 0 }; //Initializes all cells to 0
int totalPass = 0;
+ //Loops prompt until user enters openable file
do {
cout << "Input file name: ";
cin >> fName;
@@ -34,8 +39,8 @@ int main() {
cout << endl;
cout << setw(width) << "Pick:" << setw(width) << "Drop:" << setw(width) << "Pass #:" << setw(width) << "Dist:" << setw(width) << "Fare:" << setw(width) << "Toll:" << setw(width) << "Total:" << setw(width) << "Cost/Mi:" << endl;
- readFile(fin, fares, totalPass);
- summary(fares, totalPass);
+ readFile(fin, fares, totalPass); //Inputs data into fares and totalPass while printing out file contents
+ summary(fares, totalPass); //Uses fares and totalPass to create a summary
}
void readFile(ifstream& fin, double fares[], int& totalPass) {
@@ -43,11 +48,11 @@ void readFile(ifstream& fin, double fares[], int& totalPass) {
int pick, drop, pass;
double dist, fare, toll, total, cosMi;
- cout << fixed << setprecision(2);
+ cout << fixed << setprecision(2); //Formats the output down to two decimal points
while (!(fin.eof())) {
fin >> pick >> drop >> pass >> dist >> fare >> toll;
total = fare + toll;
- if (dist == 0) {
+ if (dist == 0) { //Checks if there will be a division by zero, if so set cosMi to 0
cosMi = 0;
}
else {
@@ -63,9 +68,9 @@ void readFile(ifstream& fin, double fares[], int& totalPass) {
}
void summary(double fares[], int& totalPass) {
- float totalPaid = 0, average;
+ float totalPaid = 0, average; //Totals paid must start as zero because each cell is added to the total
int i;
- for (i = 0; i < 50; i++) {
+ for (i = 0; i < 50; i++) { //Adds all cells regardless of how many were written because unwritten cells will be 0
totalPaid += fares[i];
}
average = totalPaid / totalPass;
diff --git a/BlankConsoleLab/large.txt b/BlankConsoleLab/large.txt
new file mode 100644
index 0000000..1c3dbbb
--- /dev/null
+++ b/BlankConsoleLab/large.txt
@@ -0,0 +1,48 @@
+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
+256 183 1 16.08 44.5 0
+138 166 2 7.4 24.5 6.12
+142 50 5 1.7 8 0
+107 163 0 3.6 17 0
+132 3 2 19.1 52 6.12
+48 41 1 4.07 18 4.36
+132 226 1 14.3 39 0
+229 151 1 3.96 14.5 4.58
+238 166 1 0.76 4.5 0
+151 238 2 0.64 5 2.2
+138 82 4 3 12 0
+264 231 3 10.74 32.5 0
+170 114 5 2.01 9 0
+186 87 2 3.45 12 0
+209 256 1 3.79 17 0
+132 107 1 17.2 52 6.12
+232 112 1 3.1 11 0
+164 141 3 2.85 10.5 0
+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
+256 183 1 16.08 44.5 0
+138 166 2 7.4 24.5 6.12
+142 50 5 1.7 8 0
+107 163 0 3.6 17 0
+132 3 2 19.1 52 6.12
+48 41 1 4.07 18 4.36
+132 226 1 14.3 39 0
+229 151 1 3.96 14.5 4.58
+238 166 1 0.76 4.5 0
+151 238 2 0.64 5 2.2
+138 82 4 3 12 0
+264 231 3 10.74 32.5 0
+170 114 5 2.01 9 0
+186 87 2 3.45 12 0
+209 256 1 3.79 17 0
+132 107 1 17.2 52 6.12
+232 112 1 3.1 11 0
+164 141 3 2.85 10.5 0