summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/CST116_Lab3_BlankConsoleLab_Crawford.cpp
diff options
context:
space:
mode:
authorLloyd Crawford <Lloyd Crawford@LAPTOP-7HJCDLE5>2022-11-30 23:07:44 -0800
committerLloyd Crawford <Lloyd Crawford@LAPTOP-7HJCDLE5>2022-11-30 23:07:44 -0800
commit90992e800c4178ef00d51a4cb0184ceb636e7266 (patch)
tree88d37b659c5228aa543e9abf3cd56a6e4f4f446a /BlankConsoleLab/CST116_Lab3_BlankConsoleLab_Crawford.cpp
parentSetting up GitHub Classroom Feedback (diff)
downloadcst116-lab3-19-ruin-master.tar.xz
cst116-lab3-19-ruin-master.zip
Completed Lab3HEADmaster
Diffstat (limited to 'BlankConsoleLab/CST116_Lab3_BlankConsoleLab_Crawford.cpp')
-rw-r--r--BlankConsoleLab/CST116_Lab3_BlankConsoleLab_Crawford.cpp145
1 files changed, 145 insertions, 0 deletions
diff --git a/BlankConsoleLab/CST116_Lab3_BlankConsoleLab_Crawford.cpp b/BlankConsoleLab/CST116_Lab3_BlankConsoleLab_Crawford.cpp
new file mode 100644
index 0000000..9c358dd
--- /dev/null
+++ b/BlankConsoleLab/CST116_Lab3_BlankConsoleLab_Crawford.cpp
@@ -0,0 +1,145 @@
+// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
+//CST 116_Lab 3_Crawford
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <iomanip>
+// note for me. Remember Palindrome issues in coding!!
+
+using namespace std;
+
+int Pick_up[50];
+int Drop_off[50];
+int Passenger_count[50];
+
+float Distance_travelled[50];
+float Fare_amount[50];
+float Toll_amount[50];
+float CPM[50];
+
+double Total_fare[50];
+
+int numEntries;
+
+int ReadData(ifstream& file)
+{
+ int t = -1;
+
+ while (!file.eof())
+ {
+ t++;
+
+ file >> Pick_up[t] >> Drop_off[t] >> Passenger_count[t] >> Distance_travelled[t] >> Fare_amount[t] >> Toll_amount[t];
+
+ Total_fare[t] = Fare_amount[t] + Toll_amount[t];
+
+ if (Distance_travelled[t] != 0)
+ {
+ CPM[t] = Fare_amount[t] / Distance_travelled[t];
+ }
+ else CPM[t] = 0;
+ }
+
+ t++;
+
+ return t;
+}
+
+
+void GenerateTotals(int numEntries)
+{
+ int Total_Passengers = 0;
+ double Total_Paid = 0;
+
+ for (int i = 0; i <= numEntries; i++)
+ {
+ Total_Passengers += Passenger_count[i];
+ Total_Paid += Total_fare[i];
+
+ }
+ cout << "Total Passengers: " << Total_Passengers << endl;
+ cout << "Total Paid: $" << Total_Paid << endl;
+ cout << "AVG Cost per Person: $" << Total_Paid / Total_Passengers << endl;
+ cout << "Total Trips: " << numEntries << endl;
+
+}
+
+int main()
+{
+ ifstream inFile;
+ string fileName;
+
+ cout << fixed << setprecision(2);
+ char choice = 'Y';
+
+ while (choice == 'Y')
+ {
+ while (!inFile.is_open())
+ {
+ cout << "Please enter data file name with the .txt extention" << endl;
+ cin >> fileName;
+
+ inFile.open(fileName);
+
+ if (inFile.is_open()) {
+ cout << "\nAccess Granted: " << fileName << endl;
+ }
+ else
+ {
+ cout << "\nError 404 Acess Denied....ahh ahh ahh you didn't say the magic word! ahh ahh ahh!" << fileName << endl;
+ }
+
+
+ cout << endl;
+ }
+
+
+ int numEntries = ReadData(inFile);
+
+ GenerateTotals(numEntries);
+
+
+ choice = 'A';
+
+ while (choice != 'Y' && choice != 'N')
+ {
+ cout << "\nWould you like a diplay table of the data? Y/N" << endl;
+ cin >> choice;
+ }
+
+
+ if (choice == 'Y')
+ {
+ cout << left << setw(10) << "\nEntry" << setw(10) << "Pickup"
+ << setw(10) << "Dropoff" << setw(10) << "#PASS"
+ << setw(10) << "DIST" << setw(10) << "Fares"
+ << setw(10) << "Tolls" << setw(10) << "Total$"
+ << setw(10) << "$/Mile" << endl;
+
+ for (int i = 0; i < numEntries; i++)
+ {
+ cout << left << setw(10) << i + 1 << Pick_up[i]
+ << setw(10) << Drop_off[i] << setw(10) << Passenger_count[i]
+ << setw(10) << Distance_travelled[i] << setw(10) << Fare_amount[i]
+ << setw(10) << Toll_amount[i] << setw(10) << Total_fare[i]
+ << setw(10) << CPM[i] << endl;
+
+ }
+ }
+ choice = 'A';
+
+ while (choice != 'Y' && choice != 'N')
+ {
+ cout << "\nWould you like to open another file? Y/N" << endl;
+ cin >> choice;
+ }
+
+
+ inFile.close();
+ cout << endl;
+ }
+
+
+}
+