diff options
| author | Birducken <[email protected]> | 2022-11-29 14:16:36 -0800 |
|---|---|---|
| committer | Birducken <[email protected]> | 2022-11-29 14:16:36 -0800 |
| commit | 76afbcff67b47f4d81b110b37ceb5c6d267fb804 (patch) | |
| tree | 9d1908d4826f5cce788a4c09ac3beb3ee7b5720e /BlankConsoleLab/cst116-lab3-stark.cpp | |
| parent | Finished. (diff) | |
| download | archived-cst116-lab3-stark-master.tar.xz archived-cst116-lab3-stark-master.zip | |
Diffstat (limited to 'BlankConsoleLab/cst116-lab3-stark.cpp')
| -rw-r--r-- | BlankConsoleLab/cst116-lab3-stark.cpp | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/BlankConsoleLab/cst116-lab3-stark.cpp b/BlankConsoleLab/cst116-lab3-stark.cpp deleted file mode 100644 index b4cca4c..0000000 --- a/BlankConsoleLab/cst116-lab3-stark.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Trenton Stark -// CST 116 -// Lab 3 - -#include <iostream> -#include <fstream> -#include <string> -#include <iomanip> - -using std::cout; -using std::cin; -using std::endl; -using std::ifstream; -using std::string; -using std::setw; -using std::setprecision; -using std::fixed; - -const int width = 10; //Affects all tables - -void readFile(ifstream& fin, double fares[], int& totalPass); -void summary(double fares[], int& totalPass); - -int main() { - ifstream fin; - string fName; - double fares[50] = { 0 }; //Initializes all cells to 0 - int totalPass = 0; - - //Loops prompt until user enters openable file - do { - cout << "Input file name: "; - cin >> fName; - fin.open(fName); - if (!(fin.is_open())) { - cout << "File couldn't be opened. Try again." << endl; - } - } while (!(fin.is_open())); - cout << endl; - - cout << setw(width) << "Pick:" << setw(width) << "Drop:" << setw(width) << "Pass #:" << setw(width) << "Dist:" << setw(width) << "Fare:" << setw(width) << "Toll:" << setw(width) << "Total:" << setw(width) << "Cost/Mi:" << endl; - readFile(fin, fares, totalPass); //Inputs data into fares and totalPass while printing out file contents - summary(fares, totalPass); //Uses fares and totalPass to create a summary -} - -void readFile(ifstream& fin, double fares[], int& totalPass) { - int i = 0; - int pick, drop, pass; - double dist, fare, toll, total, cosMi; - - cout << fixed << setprecision(2); //Formats the output down to two decimal points - while (!(fin.eof())) { - fin >> pick >> drop >> pass >> dist >> fare >> toll; - total = fare + toll; - if (dist == 0) { //Checks if there will be a division by zero, if so set cosMi to 0 - cosMi = 0; - } - else { - cosMi = fare / dist; - } - cout << setw(width) << pick << setw(width) << drop << setw(width) << pass << setw(width) << dist << setw(width) << fare << setw(width) << toll << setw(width) << total << setw(width) << cosMi << endl; - - totalPass += pass; - fares[i] = total; - i++; - } - cout << endl; -} - -void summary(double fares[], int& totalPass) { - float totalPaid = 0, average; //Totals paid must start as zero because each cell is added to the total - int i; - for (i = 0; i < 50; i++) { //Adds all cells regardless of how many were written because unwritten cells will be 0 - totalPaid += fares[i]; - } - average = totalPaid / totalPass; - - cout << "Total Passangers: " << totalPass << endl; - cout << "Total Fares: " << totalPaid << endl; - cout << "Mean fare per passanger: " << average << endl; -} |