summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
blob: 2e3bb479be7efbac11d7b9ff05315940639b4bf0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#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::ifstream;
using std::ofstream;

 
const int MAX = 100;

int ReadData(ifstream& inFile, int pickUP[],int DropO[],int Traveller[],float Dis[],float FareA[],float TollA[]);
void WriteOutputFile(ofstream& outFile, int pickUP[], int DropO[], int Traveller[], float Dis[],float FareA[], float TollA[],
    int counter);
void PrintTotalsAndSummary(ofstream& out, int totalRecords);

int main()
{
    
    int pickUP[MAX];
    int DropO[MAX];
    int Traveller[MAX];
    float Dis[MAX];
    float FareA[MAX];
    float TollA[MAX];
    int record_counter(0);

    ifstream inFile;
    //"C:\Users\speed\TEMP"
    // Notice how this automatically opens the file
    ofstream outFile("C:\\Users\\speed\\TEMP\\Lab3_OutputTest.txt");
    //C:\\TEMP\\Chap_11_data.txt
    inFile.open("C:\\Users\\speed\\TEMP\\Lab3_TestData.txt");

    if (inFile.is_open())
    {
        record_counter = ReadData(inFile,pickUP,DropO,Traveller,Dis,FareA,TollA);
        inFile.close();

        if (outFile.is_open())
        {
            WriteOutputFile(outFile, pickUP,DropO,Traveller,Dis,FareA,TollA, 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, ofstream& outFile, int pickUP[], int DropO[], int Traveller[], float Dis[], float FareA[], float TollA[])
{
    int counter = 0;
    inFile >> pickUP[counter] >> DropO[counter] >> Traveller[counter] >> Dis[counter] >> FareA[counter] >> TollA[counter]; // Priming Read

    while (!inFile.eof())
    {
        cout << setiosflags(ios::left) << setw(5)
            << pickUP[counter] << resetiosflags(ios::left)
            << setw(10) << DropO[counter] << resetiosflags(ios::left)
            << setw(12) << Traveller[counter] << resetiosflags(ios::left)
            << setw(14) << Dis[counter] << resetiosflags(ios::left)
            << setw (14) << FareA[counter] << resetiosflags(ios::left)
            << setw(14) << TollA[counter]
            <<endl;
        counter++;
        inFile >> pickUP[counter] >> DropO[counter] >> Traveller[counter] >> Dis[counter] >> FareA[counter] >> TollA[counter];
    }

    return counter;
}
void WriteOutputFile(ofstream& outFile, int pickUP[], int DropO[], int Traveller[], float Dis[], float FareA[], float TollA[],
    int counter)
{
    outFile << "   Here is the Output File" << endl;
    for (int r = 0; r <= counter; r++)
    {
        cout << setiosflags(ios::left) << setw(5)
            << pickUP[counter] << resetiosflags(ios::left)
            << setw(10) << DropO[counter] << resetiosflags(ios::left)
            << setw(12) << Traveller[counter] << resetiosflags(ios::left)
            << setw(14) << Dis[counter] << resetiosflags(ios::left)
            << setw(14) << FareA[counter] << resetiosflags(ios::left)
            << setw(14) << TollA[counter]
            << endl;
    }
}
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";
}