diff options
| author | matthewtaeza <[email protected]> | 2022-11-29 20:18:37 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-29 20:18:37 -0800 |
| commit | 828e51f9db32fe8147e05bf9111d823b0b9c2277 (patch) | |
| tree | f63fe196d383b5d6a298c71880b95e83d4d5c001 | |
| parent | Submission (diff) | |
| download | cst116-lab3-matthewtaeza-828e51f9db32fe8147e05bf9111d823b0b9c2277.tar.xz cst116-lab3-matthewtaeza-828e51f9db32fe8147e05bf9111d823b0b9c2277.zip | |
Add files via upload
| -rw-r--r-- | Lab 3.txt | 97 |
1 files changed, 97 insertions, 0 deletions
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 <iostream>
+#include <iomanip>
+#include <fstream>
+#include <string>
+
+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 |