summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWyatt <[email protected]>2022-11-30 16:10:32 -0800
committerWyatt <[email protected]>2022-11-30 16:10:32 -0800
commite0639aee26f8948cb6cd98191412797f37583dc5 (patch)
treec4abc10c8c149d578b71e267ea80dd7c91bef98b
parentSetting up GitHub Classroom Feedback (diff)
downloadcst116-lab3-johnson-e0639aee26f8948cb6cd98191412797f37583dc5.tar.xz
cst116-lab3-johnson-e0639aee26f8948cb6cd98191412797f37583dc5.zip
guh
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp140
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj8
-rw-r--r--large.txt48
-rw-r--r--small.txt3
4 files changed, 191 insertions, 8 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index ed5f807..48d0966 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -2,15 +2,147 @@
//
#include <iostream>
+#include <iomanip>
+#include <fstream>
using namespace std;
-using std::cout;
-using std::cin;
-using std::endl;
+const int MAX_INPUT_AMOUNT = 100;
+
+
+void ReadData(ifstream& input, int startPos[MAX_INPUT_AMOUNT], int endPos[MAX_INPUT_AMOUNT],
+ int passengerCount[MAX_INPUT_AMOUNT], float distance[MAX_INPUT_AMOUNT], float fareAmount[MAX_INPUT_AMOUNT], float tollAmount[MAX_INPUT_AMOUNT], int& counter);
+
+void ProcessData(int startPos[MAX_INPUT_AMOUNT], int endPos[MAX_INPUT_AMOUNT],
+ int passengerCount[MAX_INPUT_AMOUNT], float fareAmount[MAX_INPUT_AMOUNT], float tollAmount[MAX_INPUT_AMOUNT],
+ float distance[MAX_INPUT_AMOUNT], float totalCost[MAX_INPUT_AMOUNT], float costPerMile[MAX_INPUT_AMOUNT],
+ float& GrandTotal, int& totalPassengers,
+ int& counter);
+
+void OutputData(int passengerCount[MAX_INPUT_AMOUNT], float fareAmount[MAX_INPUT_AMOUNT], float tollAmount[MAX_INPUT_AMOUNT],
+ float distance[MAX_INPUT_AMOUNT], float totalCost[MAX_INPUT_AMOUNT], float costPerMile[MAX_INPUT_AMOUNT],
+ float& GrandTotal, int& totalPassengers,
+ int& counter);
+
+string getPadding(int input);
+
+
+//C:\Users\wythe\Desktop\Homework\C++\cst116-lab3-johnson\small.txt
int main()
{
- cout << "Hello World!\n";
+ ifstream inputStream;
+
+ while (!inputStream.is_open())
+ {
+ string inputFilePath = "";
+ cout << "Please input the location of the data file.\n";
+ cin >> inputFilePath;
+ cout << endl;
+
+ if (inputFilePath[0] != 'C' || inputFilePath[1] != ':')
+ {
+ inputFilePath = "C:\\" + inputFilePath;
+ }
+ inputStream.open(inputFilePath);
+
+ if (!inputStream.is_open())
+ {
+ cout << "Invalid file path." << endl;
+ }
+
+ }
+
+ int startPos[MAX_INPUT_AMOUNT] = {};
+ int endPos[MAX_INPUT_AMOUNT] = {};
+
+ int passengerCount[MAX_INPUT_AMOUNT] = {};
+
+ float distance[MAX_INPUT_AMOUNT] = {};
+
+ float fareAmount[MAX_INPUT_AMOUNT] = {};
+ float tollAmount[MAX_INPUT_AMOUNT] = {};
+
+ int counter = 0;
+
+ ReadData(inputStream, startPos, endPos, passengerCount, distance, fareAmount, tollAmount, counter);
+
+ float totalCost[MAX_INPUT_AMOUNT] = {};
+ float costPerMile[MAX_INPUT_AMOUNT] = {};
+
+ float GrandTotal = 0;
+ int totalPassengers = 0;
+
+ ProcessData(startPos, endPos, passengerCount, fareAmount, tollAmount, distance, totalCost, costPerMile, GrandTotal, totalPassengers, counter);
+ OutputData(passengerCount, fareAmount, tollAmount, distance, totalCost, costPerMile, GrandTotal, totalPassengers, counter);
+
}
+void ReadData(ifstream& input, int startPos[MAX_INPUT_AMOUNT], int endPos[MAX_INPUT_AMOUNT],
+ int passengerCount[MAX_INPUT_AMOUNT], float distance[MAX_INPUT_AMOUNT], float fareAmount[MAX_INPUT_AMOUNT], float tollAmount[MAX_INPUT_AMOUNT], int& counter)
+{
+ while (!input.eof())
+ {
+ input >> startPos[counter];
+ input >> endPos[counter];
+
+ int passengers = 0;
+ input >> passengers;
+ if (passengers > 9) passengers = 9;
+ passengerCount[counter] = passengers;
+
+ input >> distance[counter];
+
+ input >> fareAmount[counter];
+ input >> tollAmount[counter];
+
+ counter++;
+ }
+}
+
+void ProcessData(int startPos[MAX_INPUT_AMOUNT], int endPos[MAX_INPUT_AMOUNT],
+ int passengerCount[MAX_INPUT_AMOUNT], float fareAmount[MAX_INPUT_AMOUNT], float tollAmount[MAX_INPUT_AMOUNT],
+ float distance[MAX_INPUT_AMOUNT], float totalCost[MAX_INPUT_AMOUNT], float costPerMile[MAX_INPUT_AMOUNT],
+ float& GrandTotal, int& totalPassengers,
+ int& counter)
+{
+
+ for (int i = 0; i <= counter; i++)
+ {
+
+ totalCost[i] = fareAmount[i] + tollAmount[i];
+ costPerMile[i] = distance[i] == 0 ? 0 : fareAmount[i] / distance[i];
+
+ GrandTotal += totalCost[i];
+ totalPassengers += passengerCount[i];
+ }
+
+}
+
+void OutputData(int passengerCount[MAX_INPUT_AMOUNT], float fareAmount[MAX_INPUT_AMOUNT], float tollAmount[MAX_INPUT_AMOUNT],
+ float distance[MAX_INPUT_AMOUNT], float totalCost[MAX_INPUT_AMOUNT], float costPerMile[MAX_INPUT_AMOUNT],
+ float& GrandTotal, int& totalPassengers,
+ int& counter)
+{
+ cout << setprecision(3);
+ cout << "|Ride # |Passengers|Distance |Fare Cost| Toll $ |Total $ |$Per Mile|\n";
+
+ for (int i = 0; i <= counter; i++)
+ {
+
+ cout << "|" << i + 1 << getPadding(i + 1) << passengerCount[i] << getPadding(passengerCount[i]) << distance[i] << getPadding(distance[i]) << fareAmount[i] << getPadding(fareAmount[i]) <<
+ tollAmount[i] << getPadding(tollAmount[i]) << totalCost[i] << getPadding(totalCost[i]) << costPerMile[i] << getPadding(costPerMile[i]) << endl;
+
+ }
+
+ cout << "\n\n Grand Total: " << GrandTotal << "$\n Total Passengers: " << totalPassengers << endl;
+}
+
+string getPadding(int input)
+{
+ string padding = " |";
+ if (input >= 10) padding = " |";
+ if (input >= 100) padding = " |";
+ if (input >= 1000) padding = " |";
+ return padding;
+}
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>
diff --git a/large.txt b/large.txt
new file mode 100644
index 0000000..23d31c6
--- /dev/null
+++ b/large.txt
@@ -0,0 +1,48 @@
+128 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
diff --git a/small.txt b/small.txt
new file mode 100644
index 0000000..62feb09
--- /dev/null
+++ b/small.txt
@@ -0,0 +1,3 @@
+128 7 3 1.3 7.5 0
+36 69 1 11.41 32 5.76
+7 41 1 4.6 15 5.76 \ No newline at end of file