summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
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 /BlankConsoleLab/BlankConsoleLab.cpp
parentSetting up GitHub Classroom Feedback (diff)
downloadcst116-lab3-johnson-e0639aee26f8948cb6cd98191412797f37583dc5.tar.xz
cst116-lab3-johnson-e0639aee26f8948cb6cd98191412797f37583dc5.zip
guh
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp140
1 files changed, 136 insertions, 4 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;
+}