diff options
| author | tafaar <[email protected]> | 2022-11-28 19:56:00 -0800 |
|---|---|---|
| committer | tafaar <[email protected]> | 2022-11-28 19:56:00 -0800 |
| commit | af639ae820b892881fdd0807186a0888acc71f75 (patch) | |
| tree | d42040ae8344f2d9bd452163297c79dfad3b73c1 | |
| parent | Setting up GitHub Classroom Feedback (diff) | |
| download | archived-cst116-lab3-hill-af639ae820b892881fdd0807186a0888acc71f75.tar.xz archived-cst116-lab3-hill-af639ae820b892881fdd0807186a0888acc71f75.zip | |
first commit
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 78 | ||||
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.vcxproj | 11 | ||||
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.vcxproj.filters | 5 | ||||
| -rw-r--r-- | BlankConsoleLab/small.txt | 11 |
4 files changed, 97 insertions, 8 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index ed5f807..28f2ddc 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -2,15 +2,85 @@ // #include <iostream> +#include <fstream> +#include <string> +#include <iomanip> using namespace std; -using std::cout; -using std::cin; -using std::endl; +int pickUp[50]; +int dropOff[50]; +int passengerCount[50]; + +float distanceTravelled[50]; +float fareAmount[50]; +float tollAmount[50]; +float costPerMile[50]; + +double totalFare[50]; + +void ReadData(ifstream file) { + +} int main() { - cout << "Hello World!\n"; + + ifstream inFile; + string fileName; + + cout << fixed << setprecision(2); + + cout << "Please enter your data file name with the .txt extension:" << endl; + cin >> fileName; + + inFile.open(fileName); + + if (inFile.is_open()) { + cout << "Opened " << fileName << endl; + } + else { + cout << "Failed to open " << fileName << endl; + } + + int t = -1; + + while (!inFile.eof()) { + + t++; + + inFile >> pickUp[t] >> dropOff[t] >> passengerCount[t] >> distanceTravelled[t] >> fareAmount[t] >> tollAmount[t]; + + totalFare[t] = fareAmount[t] + tollAmount[t]; + + if (distanceTravelled[t] != 0) { + + costPerMile[t] = fareAmount[t] / distanceTravelled[t]; + + } + else costPerMile[t] = 0; + + } + + cout << "Found " << t << " entries" << endl; + + for (int i = 0; i < t; i++) { + cout << "Total fare for entry " << i + 1 << ": $" << totalFare[i] << endl; + } + + int totalPassengers = 0; + double totalPaid = 0; + + for (int i = 0; i < t; i++) { + + totalPassengers += passengerCount[i]; + totalPaid += totalFare[i]; + + } + + cout << "A total of " << totalPassengers << " passengers were transported." << endl; + cout << "Altogether, the total amount paid was $" << totalPaid << endl; + cout << "The average cost per person was $" << totalPaid / totalPassengers << endl; + } diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj index db2e734..dfe725d 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> @@ -141,6 +141,9 @@ <ItemGroup> <ClCompile Include="BlankConsoleLab.cpp" /> </ItemGroup> + <ItemGroup> + <Text Include="small.txt" /> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters index aca1dd9..cfb09a9 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters @@ -19,4 +19,9 @@ <Filter>Source Files</Filter> </ClCompile> </ItemGroup> + <ItemGroup> + <Text Include="small.txt"> + <Filter>Source Files</Filter> + </Text> + </ItemGroup> </Project>
\ No newline at end of file diff --git a/BlankConsoleLab/small.txt b/BlankConsoleLab/small.txt new file mode 100644 index 0000000..3d94536 --- /dev/null +++ b/BlankConsoleLab/small.txt @@ -0,0 +1,11 @@ +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 |