From 828e51f9db32fe8147e05bf9111d823b0b9c2277 Mon Sep 17 00:00:00 2001 From: matthewtaeza <114624219+matthewtaeza@users.noreply.github.com> Date: Tue, 29 Nov 2022 20:18:37 -0800 Subject: Add files via upload --- Lab 3.txt | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Lab 3.txt diff --git a/Lab 3.txt b/Lab 3.txt new file mode 100644 index 0000000..257cf45 --- /dev/null +++ b/Lab 3.txt @@ -0,0 +1,97 @@ +#include +#include +#include +#include + +using std::cout; +using std::cin; +using namespace std; + +int PickUp[50]; +int DropOff[50]; +int Passenger[50]; + +float Distance[50]; +float Fare[50]; +float Toll[50]; +float CPM[50]; //cost per minute + +double TotalCost[50]; + +int NumberEntries; + +int ReadData(ifstream& file) +{ + int f = -1; //f is the number of entries + + while (!file.eof()) + { + f++; + + file >> PickUp[f] >> DropOff[f] >> Passenger[f] >> Distance[f] >> Fare[f] >> Toll[f]; + + TotalCost[f] = Fare[f] + Toll[f]; + + if (Distance[f] != 0) + { + CPM[f] = Fare[f] / Distance[f]; + + } + + else CPM[f] = 0; + + } + f++; + + return f; + +} + +void GenerateTotals(int NumberEntries) +{ + int PassengersTotal = 0; + double TotalPaid = 0; + + for (int i = 0; i <= NumberEntries; i++) + { + PassengersTotal += Passenger[i]; + TotalPaid += TotalCost[i]; + } + + cout << "Total passenger count ->> " << PassengersTotal << endl; + cout << "Total paid ->> " << TotalPaid << endl; + cout << "The average cost per person is ->> $" << TotalPaid / PassengersTotal << endl; + cout << "Total trips ->> " << NumberEntries << endl; + +} + +int main() +{ + ifstream inFile; + string fileName; + + cout << fixed << setprecision(2); + + while (!inFile.is_open()) { + + cout << "Enter your file name with .txt extension ->>" << endl; + cin >> fileName; + + inFile.open(fileName); + + if (inFile.is_open()) { + + cout << "\nOpened " << fileName << endl; + + } + else { + + cout << "\nCould not open " << fileName << endl; + } + cout << endl; + } + + int NumberEntries = ReadData(inFile); + + GenerateTotals(NumberEntries); +} \ No newline at end of file -- cgit v1.2.3