summaryrefslogtreecommitdiff
path: root/CST116-Ch11-debugging-Pseudocode-Crawford.txt
blob: fec69e48228557249a06d1d1313bffa783e0be85 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
Ch 11 Debug Pseudocode


Wrote own file & named it CH_11_Data_LC.txt
Replaced location of older file with new file location and name of file.
Had to debug own coding for a new file location as I had made my input my output 
causing it to write over my input. Found errors in the code and fixed them.
Duplicated the while loop to be outside of the while and inside.
Changed <= to < on line 137
 In part 2 if you change the input from double slash to single slash it will cause the program to fail.
 double slash is always a requirement.
 Changing and tampering with input and output placements causes error coding. Best way is to copy the address of the file you use by going
 to the files properties and copying it's address.

 #include <iostream>
#include <fstream>	// For the files!!!! // lol stream......good thing its not a pstream ^o^ .
#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 EMPLOYEES = 20;
const int MAX = 21;

int ReadData(ifstream& inFile, ofstream& outFile, char name[][MAX], int age[]);
void WriteOutputFile(ofstream& outFile, char name[][MAX], int age[],
    int counter);
void PrintTotalsAndSummary(ofstream& out, int totalRecords);

int main()
{
    char name[EMPLOYEES][MAX];
    int age[EMPLOYEES];
    int record_counter(0);

    ifstream inFile;

    // Notice how this automatically opens the file
    ofstream outFile("C:\\Users\\Lloyd Crawford\\source\\repos\\cst116-ch11-debugging-19-Ruin\\CH_11_Report.txt");

    inFile.open("C:\\Users\\Lloyd Crawford\\source\\repos\\cst116-ch11-debugging-19-Ruin\\CH_11_Data_LC.txt");
    // double slash has to be used in all file in or out. If you use a single slach bad things happen.
    if (inFile.is_open())
    {
        record_counter = ReadData(inFile, outFile, name, age);
        inFile.close();

        if (outFile.is_open())
        {
            WriteOutputFile(outFile, name, age, 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, char name[][MAX], int age[])
{
    int counter = 0;
    inFile >> name[counter] >> age[counter]; // Priming Read

    while (!inFile.eof())
    {
        cout << setiosflags(ios::left) << setw(25)
            << name[counter] << resetiosflags(ios::left)
            << setw(4) << age[counter] << endl;
        counter++;
        inFile >> name[counter] >> age[counter];
    }
    // next segment is for reading and priming the file.
    cout << setiosflags(ios::left) << setw(25)    
        << name[counter] << resetiosflags(ios::left)
        << setw(4) << age[counter] << endl;
    counter++;
    inFile >> name[counter] >> age[counter];

    return counter;
}
void WriteOutputFile(ofstream& outFile, char name[][MAX], int age[], int counter)
{
    outFile << "   Here is the Output File" << endl;
    for (int r = 0; r < counter; r++) // femove the = here to stop the report from adding wierd coding to your solution and your file. nasty bug.
    {
        outFile << setiosflags(ios::left) << setw(25)
            << name[r] << setw(4)
            << resetiosflags(ios::left) << age[r]
            << 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";

        Felt like I learned in this lesson and once I found how to do it, it felt like it went quick.
        output
        Vincent                    24
Johnny                     81
Hector                     45
Ranni                      89
Radahn                     90
DrLivesly                  45
Powerwolf                  10
Iggy                       23
Bertrum                    15
Goofy                      99


        ** Total Records: 10 **
                 The End

C:\Users\Lloyd Crawford\source\repos\cst116-ch11-debugging-19-Ruin\x64\Debug\CST116-Ch11-Debugging-Crawford.exe (process 18708) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .