loading
open in
main.cpp
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 Problem: Read data from an ASCII (text file) and calculate the value of inventory for each item and Total Cost. Then output to a file
 
 Algorithm and Pseudo Code
1. Create text file in windows with supplied data
2. Call header files, iostream, fstream, iomanip, string
 2. Declare and initialize variables
 a. ifstream inFile;
 b. ofstream outFile;
 c. other int, char, double, string, etc.
3. Open the in and out files
 a. inFile.open("input.txt");
    i. Get data
 b. outFile.open("output.txt")
4. Assign data to program variables
5. Output desired content into a file
6. Close files
 */



#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;

int main() {
    
    //Declarations & Initializations
    string partName = string();
    int numUnits = int();
    double unitPrice = double();
    double unitsValue = double();
    double totalValue = 0;
    int f = 1;

    
    ifstream inFile; //Declaring fstream variables
    ofstream outFile;
    
    
    
    cout << "================================================" << endl;
    cout << "Description: Intventory Report" << endl;
    cout << "Author: Christian Araya" << endl;
    cout << "================================================\n\n\n" << endl;
    
    
    cout << fixed << showpoint << setprecision(2); //Gen format
    outFile << fixed << showpoint << setprecision(2);
    
    //Opening input and output files
    inFile.open("input.txt");
    outFile.open("output.txt");
    
    
    //WHAT TO DO FOR EACH ROW
    while (f <= 10 )
    {
        if (f == 1) //ROW 1
        {
            //TOP BORDER ROOF WITH LEFT AND RIGHT BORDERS ON THE SIDE
            cout << "|";
            outFile << "|";
            for (int a = 1; a < 71; a++)
            {
                cout << "-";
                outFile << "-";
            }
            cout << "|\n";
            outFile << "|\n";
        }
        else if (f == 2) //Beginning of Header
        {
            cout << "|  ";
            outFile << "|  ";
            for (int i = 1; i < 67; i++) //First Horizontal squiggly line
            {
                cout << "~";
                outFile << "~";
            }
            cout << "  |\n";
            outFile << "  |\n";
        }
        else if (f == 3)
        {
            cout << "|" << right << setw(72) << "Intentory Report for Long Beach International Hardware        |\n"; // Box Name
            outFile << "|" << right << setw(72) << "Intentory Report for Long Beach International Hardware        |\n";
        }
        else if (f == 4)
        {
            cout << "|  ";
            outFile << "|  ";
            for (int i = 1; i < 67; i++) //Second Horizontal squiggly line
            {
                cout << "~";
                outFile << "~";
            }
            cout << "  |\n";
            outFile << "  |\n";
        }
        else if (f == 5)
        {
            //COLUMN TITLES IN TABLE
            outFile << setw(10) << left << "|ITEM"
                << setw(20) << right << "NUMBER OF UNITS"
                << setw(20) << right << "UNIT COST ($)"
                << setw(23) << right << "TOTAL VALUE ($)|\n";
            cout    << setw(10) << left << "|ITEM"
                << setw(20) << right << "NUMBER OF UNITS"
                << setw(20) << right << "UNIT COST ($)"
                << setw(23) << right << "TOTAL VALUE ($)|\n";
        }
        else if (f == 6)
        {
            cout << "|";
            outFile << "|";
            for (int j = 1; j <71; j++) // horizontal line
            {
                cout << "-";
                outFile << "-";
            }
            cout << "|\n";
            outFile << "|\n";
        }
        else if (f == 7) //Rows 7-12 contain the table of data
        {
            //COLUMN VALUES
            while(!inFile.eof())
            {
                inFile >> partName >> numUnits >> unitPrice;
                unitsValue = numUnits * unitPrice;
                
                outFile << "|" << setw(10) << left << partName
                        << setw(13) << right << numUnits << "        "
                        << setw(13) << right << unitPrice << "       "
                        << setw(15) << right << unitsValue << "    |" << endl;
                cout    << "|" << setw(10) << left << partName
                        << setw(13) << right << numUnits << "        "
                        << setw(13) << right << unitPrice << "       "
                        << setw(15) << right << unitsValue << "    |" << endl;
                totalValue = totalValue + unitsValue;
                
            }
        }
        else if (f == 8)
        {
            cout << "|";
            outFile << "|";
            for (int j = 1; j <71; j++) // horizontal line
            {
                cout << "-";
                outFile << "-";
            }
            cout << "|\n";
            outFile << "|\n";
        }
        else if (f == 9)
        {
            outFile << left << "|Inventory Total ($)" << setw(47) << right << totalValue << "    |\n";
            cout << left << "|Inventory Total ($)" << setw(47) << right << totalValue << "    |\n";
        }
        else if (f == 10)
        {
            cout << "|";
            outFile << "|";
            for (int j = 1; j <71; j++) // horizontal line
            {
                cout << "-";
                outFile << "-";
            }
            cout << "|\n\n\n";
            outFile << "|\n\n\n";
        }
        
        f++;
    }
        

    
    //Closing input and output files
    inFile.close();
    outFile.close();
    
    
    return 0;
}
gcc version 4.6.3