diff options
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 143 | ||||
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.vcxproj | 2 | ||||
| -rw-r--r-- | BlankConsoleLab/lab3_report.txt | 0 | ||||
| -rw-r--r-- | BlankConsoleLab/re is the Output File | 0 | ||||
| -rw-r--r-- | LabResults.txt | 1 | ||||
| -rw-r--r-- | lab3_data.txt | 48 | ||||
| -rw-r--r-- | lab3_report.txt | 54 |
7 files changed, 241 insertions, 7 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index ed5f807..492267d 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -2,15 +2,148 @@ // #include <iostream> - -using namespace std; - -using std::cout; +#include <string> +#include <fstream> // For the files!!!! +#include <iomanip> // For manipulators & formatting options using std::cin; +using std::cout; using std::endl; +using std::setw; +using std::ios; +using std::string; +using std::ifstream; +using std::ofstream; + +const int MAX = 100; +int ReadData(ifstream& inFile, int pickUp[], int dropOff[], int passenger[], float + dist[], float fare[], float toll[]); +void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int + psgr[], float dist[], float fare[], float toll[], + int counter); +void PrintTotalsAndSummary(ofstream& out, int totalRecords); +float totalFare(float fare[], float toll[], int counter); +float cpm(float fare[], float dist[], int counter); int main() { - cout << "Hello World!\n"; + int pickUp[MAX]; + int dropOff[MAX]; + int passenger[MAX]; + float dist[MAX]; + float fare[MAX]; + float toll[MAX]; + int record_counter(0); + string outputLoc; + string outputName; + string inputLoc; + string inputName; + cout << "Where do you want the OUTPUT file to be saved?(C:\\.....) "; + cin >> outputLoc; + cout << endl << "What do you want the OUTPUT file to be called?(include .txt) "; + cin >> outputName; + cout << endl << "Where is your INPUT file saved?(C:\\....) "; + cin >> inputLoc; + cout << endl << "What is your INPUT file called?(include .txt) "; + cin >> inputName; + ifstream inFile; + + ofstream outFile(outputLoc + "\\" + outputName); + + inFile.open(inputLoc + "\\" + inputName); + + if (inFile.is_open()) + { + record_counter = ReadData(inFile, pickUp, dropOff, passenger, dist, fare, toll); + inFile.close(); + + if (outFile.is_open()) + { + WriteOutputFile(outFile, pickUp, dropOff, passenger, dist, fare, toll, record_counter); + PrintTotalsAndSummary(outFile, record_counter); + outFile.close(); + } + else + { + cout << "Trouble Opening Output File"; + cout << "\n\n\t\t ** About to EXIT NOW! ** "; + } + } + else + { + cout << "Trouble Opening Input File"; + cout << "\n\n\t\t ** About to EXIT NOW! ** "; + } + return 0; +} +int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float + dist[], float fare[], float toll[]) +{ + int counter = 0; + inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> + dist[counter] >> fare[counter] >> toll[counter]; // Priming Read + while (!inFile.eof()) + { + cout << setiosflags(ios::left) << setw(5) + << pick[counter] << resetiosflags(ios::left) + << setw(10) << drop[counter] << + resetiosflags(ios::left) + << setw(12) << psgr[counter] << + resetiosflags(ios::left) + << setw(14) << + dist[counter] << resetiosflags(ios::left) + << setw(14) << fare[counter] << + resetiosflags(ios::left) + << setw(14) << toll[counter] + << endl; + counter++; + inFile >> pick[counter] >> drop[counter] >> psgr[counter] + >> dist[counter] >> fare[counter] >> toll[counter]; + } + return counter; +} +void WriteOutputFile(ofstream& outFile, int pickUp[], int dropOff[], int passenger[], float + dist[], float fare[], float toll[], int counter) +{ + outFile << " Here is the Output File" << endl; + outFile << "Pickup " << setw(15) << "Dropoff " << setw(15) << "Passengers " << setw(15) << "Distance " << setw(15) << "Fare " << setw(15) << "Toll " << setw(15) << + "Total Fare " << setw(15) << "Cost per Mile "<< endl; + cout.precision(2); + for (int r = 0; r <= counter; r++) + { + outFile << setiosflags(ios::left) << setw(4) + << pickUp[r] << resetiosflags(ios::left) + << setw(15) << dropOff[r] + << setw(15) << passenger[r] + << setw(15) << dist[r] + << setw(15) << fare[r] + << setw(15) << toll[r] << setw(15) + << totalFare(fare, toll, r)<< setw(15) << + cpm(fare, dist, r)<< + endl; + } +} +float totalFare(float fare[], float toll[], int counter) { + float total = fare[counter] + toll[counter]; + return total; +} +float cpm(float fare[], float dist[], int counter) { + float cpm; + if (dist[counter] == 0) { + cpm = 0; + } + else { + cpm = fare[counter] / dist[counter]; + } + return cpm; +} +void PrintTotalsAndSummary(ofstream& outFile, int totalRecords) +{ + // To screen + cout << "\n\n\t** Total Records: " << totalRecords << " **\n" + << "\t\t The End \n"; + + // To file + outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" + << "\t\t The End \n"; } diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj index db2e734..21a7b20 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj @@ -42,7 +42,7 @@ <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"> diff --git a/BlankConsoleLab/lab3_report.txt b/BlankConsoleLab/lab3_report.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/BlankConsoleLab/lab3_report.txt diff --git a/BlankConsoleLab/re is the Output File b/BlankConsoleLab/re is the Output File new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/BlankConsoleLab/re is the Output File diff --git a/LabResults.txt b/LabResults.txt deleted file mode 100644 index bfe34d2..0000000 --- a/LabResults.txt +++ /dev/null @@ -1 +0,0 @@ -RunResults
\ No newline at end of file diff --git a/lab3_data.txt b/lab3_data.txt new file mode 100644 index 0000000..d9fa1b1 --- /dev/null +++ b/lab3_data.txt @@ -0,0 +1,48 @@ +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 +256 183 1 16.08 44.5 0 +138 166 2 7.4 24.5 6.12 +142 50 5 1.7 8 0 +107 163 0 3.6 17 0 +132 3 2 19.1 52 6.12 +48 41 1 4.07 18 4.36 +132 226 1 14.3 39 0 +229 151 1 3.96 14.5 4.58 +238 166 1 0.76 4.5 0 +151 238 2 0.64 5 2.2 +138 82 4 3 12 0 +264 231 3 10.74 32.5 0 +170 114 5 2.01 9 0 +186 87 2 3.45 12 0 +209 256 1 3.79 17 0 +132 107 1 17.2 52 6.12 +232 112 1 3.1 11 0 +164 141 3 2.85 10.5 0 +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 +256 183 1 16.08 44.5 0 +138 166 2 7.4 24.5 6.12 +142 50 5 1.7 8 0 +107 163 0 3.6 17 0 +132 3 2 19.1 52 6.12 +48 41 1 4.07 18 4.36 +132 226 1 14.3 39 0 +229 151 1 3.96 14.5 4.58 +238 166 1 0.76 4.5 0 +151 238 2 0.64 5 2.2 +138 82 4 3 12 0 +264 231 3 10.74 32.5 0 +170 114 5 2.01 9 0 +186 87 2 3.45 12 0 +209 256 1 3.79 17 0 +132 107 1 17.2 52 6.12 +232 112 1 3.1 11 0 +164 141 3 2.85 10.5 0
\ No newline at end of file diff --git a/lab3_report.txt b/lab3_report.txt new file mode 100644 index 0000000..3709629 --- /dev/null +++ b/lab3_report.txt @@ -0,0 +1,54 @@ + Here is the Output File +Pickup Dropoff Passengers Distance Fare Toll Total Fare Cost per Mile +129 7 3 1.3 7.5 0 7.5 5.76923 +36 69 1 11.41 32 5.76 37.76 2.80456 +7 41 1 4.6 15 5.76 20.76 3.26087 +150 61 2 6.75 23 0 23 3.40741 +112 17 1 3.84 15 0 15 3.90625 +80 112 6 1.64 9.5 0 9.5 5.79268 +256 183 1 16.08 44.5 0 44.5 2.76741 +138 166 2 7.4 24.5 6.12 30.62 3.31081 +142 50 5 1.7 8 0 8 4.70588 +107 163 0 3.6 17 0 17 4.72222 +132 3 2 19.1 52 6.12 58.12 2.72251 +48 41 1 4.07 18 4.36 22.36 4.4226 +132 226 1 14.3 39 0 39 2.72727 +229 151 1 3.96 14.5 4.58 19.08 3.66162 +238 166 1 0.76 4.5 0 4.5 5.92105 +151 238 2 0.64 5 2.2 7.2 7.8125 +138 82 4 3 12 0 12 4 +264 231 3 10.74 32.5 0 32.5 3.02607 +170 114 5 2.01 9 0 9 4.47761 +186 87 2 3.45 12 0 12 3.47826 +209 256 1 3.79 17 0 17 4.48549 +132 107 1 17.2 52 6.12 58.12 3.02326 +232 112 1 3.1 11 0 11 3.54839 +164 141 3 2.85 10.5 0 10.5 3.68421 +129 7 3 1.3 7.5 0 7.5 5.76923 +36 69 1 11.41 32 5.76 37.76 2.80456 +7 41 1 4.6 15 5.76 20.76 3.26087 +150 61 2 6.75 23 0 23 3.40741 +112 17 1 3.84 15 0 15 3.90625 +80 112 6 1.64 9.5 0 9.5 5.79268 +256 183 1 16.08 44.5 0 44.5 2.76741 +138 166 2 7.4 24.5 6.12 30.62 3.31081 +142 50 5 1.7 8 0 8 4.70588 +107 163 0 3.6 17 0 17 4.72222 +132 3 2 19.1 52 6.12 58.12 2.72251 +48 41 1 4.07 18 4.36 22.36 4.4226 +132 226 1 14.3 39 0 39 2.72727 +229 151 1 3.96 14.5 4.58 19.08 3.66162 +238 166 1 0.76 4.5 0 4.5 5.92105 +151 238 2 0.64 5 2.2 7.2 7.8125 +138 82 4 3 12 0 12 4 +264 231 3 10.74 32.5 0 32.5 3.02607 +170 114 5 2.01 9 0 9 4.47761 +186 87 2 3.45 12 0 12 3.47826 +209 256 1 3.79 17 0 17 4.48549 +132 107 1 17.2 52 6.12 58.12 3.02326 +232 112 1 3.1 11 0 11 3.54839 +164 141 3 2.85 10.5 0 10.5 3.68421 + + + ** Total Records: 47 ** + The End |