diff options
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 105 | ||||
| -rw-r--r-- | BlankConsoleLab/LabResults - Copy.txt (renamed from LabResults.txt) | 0 | ||||
| -rw-r--r-- | BlankConsoleLab/LabResults.txt | 10 | ||||
| -rw-r--r-- | BlankConsoleLab/infile - Copy.txt (renamed from infile.txt) | 0 | ||||
| -rw-r--r-- | BlankConsoleLab/infile.txt | 11 |
5 files changed, 118 insertions, 8 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index 9944142..d404bb7 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -3,8 +3,6 @@ #include <fstream> #include <iomanip> -using namespace std; - using std::cin; using std::cout; using std::endl; @@ -14,12 +12,103 @@ using std::ios; using std::ifstream; using std::ofstream; + +const int MAX = 100; + +int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], 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); + + +//the first 'array' is the descripption of what needs to be done in total 6 equations/things to do +//next tsxt is 6 cols by x rows + int main() -{//the first 'array' is the descripption of what needs to be done in total 6 equations/things to do - //next tsxt is 6 cols by x rows - ifstream inFile; +{ + int pick[MAX]; + int drop[MAX]; + int psgr[MAX]; + float dist[MAX]; + float fare[MAX]; + float toll[MAX]; + int record_counter(0); + + ifstream inFile; + + // Notice how this automatically opens the file + ofstream outFile("LabResults.txt"); + + inFile.open("infile.txt"); + + if (inFile.is_open()) + { + record_counter = ReadData(inFile, pick, drop, psgr, dist, fare, toll); + inFile.close(); + + if (outFile.is_open()) + { + WriteOutputFile(outFile, pick, drop, psgr, dist, fare, toll, record_counter); + PrintTotalsAndSummary(outFile, record_counter); + outFile.close(); + } + else + { + cout << "Trouble Opening File"; + cout << "\n\n\t\t ** About to EXIT NOW! ** "; + } + } + else + { + cout << "Trouble Opening 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; +} - ofstream outFile("infile.txt"); +void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], + int counter) +{ + outFile << " Here is the Output File" << endl; + for (int r = 0; r <= counter - 1; r++) + { + outFile << setiosflags(ios::left) << setw(5) + << pick[r] << resetiosflags(ios::left) + << setw(10) << drop[r] << resetiosflags(ios::left) + << setw(12) << psgr[r] << resetiosflags(ios::left) + << setw(14) << dist[r] << resetiosflags(ios::left) + << setw(14) << fare[r] << resetiosflags(ios::left) + << setw(14) << toll[r] + << endl; + } +} +void PrintTotalsAndSummary(ofstream& outFile, int totalRecords) +{ + // To screen + cout << "\n\n\t** Total Records: " << totalRecords << " **\n" + << "\t\t The End \n"; - inFile.open("LabResults.txt"); -}
\ No newline at end of file + // To file + outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" + << "\t\t The End \n"; +} diff --git a/LabResults.txt b/BlankConsoleLab/LabResults - Copy.txt index bfe34d2..bfe34d2 100644 --- a/LabResults.txt +++ b/BlankConsoleLab/LabResults - Copy.txt diff --git a/BlankConsoleLab/LabResults.txt b/BlankConsoleLab/LabResults.txt new file mode 100644 index 0000000..b355347 --- /dev/null +++ b/BlankConsoleLab/LabResults.txt @@ -0,0 +1,10 @@ + Here is the Output File +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 + + + ** Total Records: 5 ** + The End diff --git a/infile.txt b/BlankConsoleLab/infile - Copy.txt index f9423ec..f9423ec 100644 --- a/infile.txt +++ b/BlankConsoleLab/infile - Copy.txt diff --git a/BlankConsoleLab/infile.txt b/BlankConsoleLab/infile.txt index e69de29..f9423ec 100644 --- a/BlankConsoleLab/infile.txt +++ b/BlankConsoleLab/infile.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 |