Code:
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <conio.h>
#include <iomanip>
class Inventory {
private:
int ProdID, qty_stock, reord_lev;
string ProdDesc, manu;
float unitcost;
public:
Inventory(int, string, string, float, int, int);
void listcurinv_1();
void listcurinv_2();
void add_stock();
void rmv_stock();
void add_prod();
void rmv_prod();
void calc_inv();
void list_reord();
};
Inventory::Inventory(int id, string desc, string manufac, float cost, int qty, int r_level) {
ProdID = id;
ProdDesc = desc;
manu = manufac;
unitcost = cost;
qty_stock = qty;
reord_lev = r_level;
}
void Inventory::listcurinv_1() {
int i = 0;
ifstream infile("a:\\CO856 Assignment 1\\sportsstore.txt");
// initial read of data
infile.getline(record[i].ProdID, 10, ',');
infile.getline(record[i].ProdDesc, 30, ',');
infile.getline(record[i].manu, 15, ',');
infile.getline(record[i].unitcost, 10, ',');
infile.getline(record[i].qty_stock, 5, ',');
infile.getline(record[i].reord_lev, 5);
i++;
// test for either EOF or 100 records in the file and stop reading
records when one of those statements is true
while (!infile.eof() || i < 100) {
infile.getline(record[i].ProdID, 10, ',');
infile.getline(record[i].ProdDesc, 30, ',');
infile.getline(record[i].manu, 15, ',');
infile.getline(record[i].unitcost, 10, ',');
infile.getline(record[i].qty_stock, 5, ',');
infile.getline(record[i].reord_lev, 5);
i++;
}
// sort by product description
string spare;
for (int j = 0; j < i-1; j++) {
for (int k = 0; k < i; k++) {
if (record[j].ProdDesc > record[k].ProdDesc) {
spare = record[j].ProdDesc;
record[j].ProdDesc = record[k].ProdDesc;
record[k].ProdDesc = spare;
}
}
}
i = 0;
// display records on screen
while (!infile.eof() || i < 100) {
cout << setw(10) << record[i].ProdID;
cout << setw(30) << record[i].ProdDesc;
cout << setw(15) << record[i].manu;
cout << setw(10) << record[i].unitcost;
cout << setw(5) << record[i].qty_stock;
cout << setw(5) << record[i].reord_lev << endl;
}
}
int main() {
Inventory record[100];
record.listcurinv_1();
getche();
return 0;
}
This is probably one of the last obsctales I need to get through to be well on my way with this program. How is it not recognizing 'record' as being declared when I have it declared in main()?