diff options
| author | Birducken <[email protected]> | 2022-11-29 12:59:27 -0800 |
|---|---|---|
| committer | Birducken <[email protected]> | 2022-11-29 12:59:27 -0800 |
| commit | 40977b8bda1a4dfb6586675a1954f7749defe8e1 (patch) | |
| tree | 9dc93d7a590800cee4f3c012613709ed5c7a1080 | |
| parent | Added file read opening system (diff) | |
| download | archived-cst116-lab3-stark-40977b8bda1a4dfb6586675a1954f7749defe8e1.tar.xz archived-cst116-lab3-stark-40977b8bda1a4dfb6586675a1954f7749defe8e1.zip | |
Added file reading system.
| -rw-r--r-- | BlankConsoleLab/cst116-lab3-stark.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/BlankConsoleLab/cst116-lab3-stark.cpp b/BlankConsoleLab/cst116-lab3-stark.cpp index cd6405a..0271537 100644 --- a/BlankConsoleLab/cst116-lab3-stark.cpp +++ b/BlankConsoleLab/cst116-lab3-stark.cpp @@ -9,13 +9,18 @@ using std::endl; using std::ifstream; using std::string; using std::setw; +using std::setprecision; +using std::fixed; const int width = 10; +void readFile(ifstream& fin, double fares[], int totalPass); + int main() { ifstream fin; string fName; - + double fares[50] = { 0 }; + int totalPass = 0; do { cout << "Input file name: "; @@ -26,4 +31,23 @@ int main() { } } while (!(fin.is_open())); + 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); +} +void readFile(ifstream& fin, double fares[], int totalPass) { + int pick, drop, pass; + double dist, fare, toll, total, cosMi; + + cout << fixed << setprecision(2); + while (!(fin.eof())) { + fin >> pick >> drop >> pass >> dist >> fare >> toll; + total = fare + toll; + if (dist == 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;; + } } |