diff options
| author | Tim Pearse <[email protected]> | 2022-11-30 19:32:23 -0800 |
|---|---|---|
| committer | Tim Pearse <[email protected]> | 2022-11-30 19:32:23 -0800 |
| commit | 1a965c1d2188663115c6d860120fdb422121684b (patch) | |
| tree | 3ca7bd39f132c92568d070702c12fae0f2cadb11 /BlankConsoleLab | |
| parent | Setting up GitHub Classroom Feedback (diff) | |
| download | cst116-lab3-legokid1503-1a965c1d2188663115c6d860120fdb422121684b.tar.xz cst116-lab3-legokid1503-1a965c1d2188663115c6d860120fdb422121684b.zip | |
Change 1 : Works
Next Step : Needs comments in code proper
Diffstat (limited to 'BlankConsoleLab')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 114 | ||||
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.vcxproj | 8 | ||||
| -rw-r--r-- | BlankConsoleLab/filename.txt | 1 | ||||
| -rw-r--r-- | BlankConsoleLab/small.txt | 6 |
4 files changed, 124 insertions, 5 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index ed5f807..ebf1f80 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -2,15 +2,127 @@ // #include <iostream> +#include <iomanip> +#include <fstream> +#include <string> using namespace std; using std::cout; using std::cin; using std::endl; +using std::setw; + +void Output_Extra_Stats(int total_people, double fares[50]); int main() { - cout << "Hello World!\n"; + // Create a text file + ofstream MyWriteFile("filename.txt"); + + // Write to the file + MyWriteFile << "1 2 3 4 5 6"; + + // Close the file + MyWriteFile.close(); + + double taxi_trips[50][8]; + cout << "Enter the file you'd like to read with the extension"; + string filename; + cin >> filename; + cout << endl; + + int start_point; + int end_point; + int passengers; + double distance; + double fare_amount; + double toll_amount; + std::ifstream input; + input.open(filename); + int total_trips = 0; + if (input.is_open()) { + while (input >> start_point >> end_point >> passengers >> distance >> fare_amount >> toll_amount) { + //Set start point + taxi_trips[total_trips][0] = start_point; + taxi_trips[total_trips][1] = end_point; + taxi_trips[total_trips][2] = passengers; + taxi_trips[total_trips][3] = distance; + taxi_trips[total_trips][4] = fare_amount; + taxi_trips[total_trips][5] = toll_amount; + taxi_trips[total_trips][6] = 0.0; + taxi_trips[total_trips][7] = 0.0; + total_trips++; + } + + for (int i = 0; i < total_trips; i++) { + taxi_trips[i][6] = taxi_trips[i][4] + taxi_trips[i][5]; + if (taxi_trips[i][3] != 0) { + taxi_trips[i][7] = taxi_trips[i][6] / taxi_trips[i][3]; + taxi_trips[i][7] = ceil(taxi_trips[i][7] * 100.0) / 100.0; + } + } + + int total_people = 0; + double fares[50]; + for (int i = 0; i < 50; i++) { + fares[i] = 0; + } + for (int i = 0; i < total_trips; i++) { + total_people += taxi_trips[i][2]; + fares[i] = taxi_trips[i][6]; + } + cout << setw(10) << "Trip#" << setw(10) << "# ppl" << setw(10) << "Dist." << setw(10) << "Fare" << setw(10) << "Toll" << setw(10) << "Total" << setw(10) << "Cost/MI" << endl; + for (int i = 0; i < total_trips; i++) { + cout << setw(4) << setfill(' ') << " " << setw(3) << setfill('0') << taxi_trips[i][0] << setw(3) << setfill('0') << taxi_trips[i][1] << setw(10) + << setfill(' ') << taxi_trips[i][2] << setw(10) << taxi_trips[i][3] << setw(10) << taxi_trips[i][4] << setw(10) << taxi_trips[i][5] << setw(10) + << taxi_trips[i][6] << setw(10) << taxi_trips[i][7] << endl; + } + Output_Extra_Stats(total_people, fares); + } } +void Output_Extra_Stats(int total_people, double fares[50]) { + double total_fares = 0.0; + for (int i = 0; i < 50; i++) { + total_fares += fares[i]; + } + int average_cost_per_person = total_fares / total_people; + + cout << endl; + cout << "People Transported: " << total_people << endl; + cout << "Total Paid: " << total_fares << endl; + cout << "Average Cost Per Person: " << average_cost_per_person << endl; +} + +/* + Pseudocode + +main(){ + taxi_trips[50][8] + read the file + assign each list to an item in taxi_trips. Leaving the last two entries at 0.0 + total_trips = amount of trips counted in file. + + for each trip in the file + set the second to last item to the fare + toll + check if the distance of the trip != 0 + set the last item to the fare / distance + int total_people = 0 + double fares[50] + for each trip in the file (using i) + total_people += [i][2] + fares[i] = taxi_trips[i][6] + print the following from each trip in order + # ppl -> Dist. -> Fare -> Toll -> Total -> Cost/MI + Output_Extra_Stats(total_people, fares) +} + +Output_Extra_Stats(int total_people, double fares[50]){ + double total_fares = 0; + for the amount of fares + total_fares += fares[i] + double average_cost_per_person = total_fares / total_people + print total people, total paid, then average cost per person +} +*/
\ No newline at end of file diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj index db2e734..d2e3ee2 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj @@ -29,26 +29,26 @@ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> - <PlatformToolset>v142</PlatformToolset> + <PlatformToolset>v143</PlatformToolset> <CharacterSet>Unicode</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> - <PlatformToolset>v142</PlatformToolset> + <PlatformToolset>v143</PlatformToolset> <WholeProgramOptimization>true</WholeProgramOptimization> <CharacterSet>Unicode</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> - <PlatformToolset>v142</PlatformToolset> + <PlatformToolset>v143</PlatformToolset> <CharacterSet>Unicode</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> - <PlatformToolset>v142</PlatformToolset> + <PlatformToolset>v143</PlatformToolset> <WholeProgramOptimization>true</WholeProgramOptimization> <CharacterSet>Unicode</CharacterSet> </PropertyGroup> diff --git a/BlankConsoleLab/filename.txt b/BlankConsoleLab/filename.txt new file mode 100644 index 0000000..f904826 --- /dev/null +++ b/BlankConsoleLab/filename.txt @@ -0,0 +1 @@ +1 2 3 4 5 6
\ No newline at end of file diff --git a/BlankConsoleLab/small.txt b/BlankConsoleLab/small.txt new file mode 100644 index 0000000..28a3ae6 --- /dev/null +++ b/BlankConsoleLab/small.txt @@ -0,0 +1,6 @@ +129 7 3 1.3 7.5 0 +36 69 1 11.41 32 5.76 +7 41 1 4.6 15 5.76 +150 61 2 6.75 23 0 +112 17 1 3.84 15 0 +80 112 6 1.64 9.5 0
\ No newline at end of file |