//Inventory Control #include #include #include using namespace std; void getItem(string &prod, int &quan, double &price); //add one item from keyboard void printList(string product[],int quantity[], double price[], int count); void readFile(string product[],int quantity[], double price[], int &count); //read file void main (void) //main has 3 arrays and count that are passed to other functions { string product[20]={"Widget","Dodad","Thingamajig", "Dohicky"}; int quantity[20] = {20, 100, 12, 40}; double price[20] = {12.95, 7.50, 1.25, 6.00}; int count=4; readFile(product, quantity, price, count); printList(product,quantity,price,count); } //main void getFileItem(string &prod, int &quan, double &price, ifstream &input) { //line of input will be: product; quantity; price\n input>>prod; input>>quan; input>>price; input.ignore(100,'\n'); //ignore rest of line trailing blanks and \n } //getFileItem void readFile(string product[],int quantity[], double price[], int &count) { ifstream prod; //input file stream prod.open("c:/products.txt"); if (!prod.fail()) //always test for fail: file is missing, disk not there etc. { while (!prod.eof()) { getFileItem(product[count],quantity[count],price[count], prod); //read 1 item count++; //add one to count, which was passed by reference. } //read file prod.close(); //close any file you open } //file opened and read } //readFile void getItem(string &prod, int &quan, double &price) //add one item from keyboard { cout<<"Enter name of product:"; cin>>prod; cout<<"Enter quantity:"; cin>>quan; cout<<"Enter price:"; cin>>price; // cin.ignore(100,'\n'); } //getItem void printList(string product[],int quantity[], double price[], int count) //print list of all items { cout<<"PRODUCT \tQUANTITY\tPRICE\n"; for(int i=0;i