//Inventory Control #include //iostream is a subset of fstream. #include void getItem2(char prod[], int &quan, double &price); //input as 1 line void getItem(char prod[], int &quan, double &price); //add one item from keyboard void printList(char product[][12],int quantity[], double price[], int count); void readFile(char product[][12],int quantity[], double price[], int &count); //read file void main (void) //main has 3 arrays and count that are passed to other functions { char product[20][12]; int quantity[20]; double price[20]; int count=0; readFile(product, quantity, price, count); //read in products from file printList(product,quantity,price,count); } //main void getItem2(char prod[], int &quan, double &price) //input as 1 line { //line of input will be: product; quantity; price\n cout<<"Enter name of product; quantity; price:"; cin.getline(prod,12,';'); //stop at the ; if (strlen(prod)==11) //maximum letters read, get rid of extra letters and ; cin.ignore(40,';'); cin>>quan; cin>>price; cin.ignore(100,'\n'); //ignore rest of line trailing blanks and \n } //getItem void getFileItem(char prod[], int &quan, double &price, ifstream &input) { //line of input will be: product; quantity; price\n input.getline(prod,12,';'); //stop at the ; if (strlen(prod)==11) //maximum letters read, get rid of extra letters and ; input.ignore(40,';'); input>>quan; input>>price; input.ignore(100,'\n'); //ignore rest of line trailing blanks and \n } //getFileItem void readFile(char product[][12],int quantity[], double price[], int &count) { ifstream prod; //input file stream prod.open("A:/products.txt"); if (!prod.fail()) //always test for fail: file is missing, disk not there etc. { getFileItem(product[count],quantity[count],price[count], prod); //read 1 item while(!prod.eof() && count<20) { count++; //add one to count, which was passed by reference. getFileItem(product[count],quantity[count],price[count], prod); //try to read } //while not end of file prod.close(); //close any file you open } //file opened and read } //readFile void getItem(char prod[], int &quan, double &price) //add one item from keyboard { cout<<"Enter name of product:"; cin.getline(prod,11,'\n'); if (strlen(prod)==11) //maximum letters read, get rid of \n cin.ignore(100,'\n'); cout<<"Enter quantity:"; cin>>quan; cout<<"Enter price:"; cin>>price; cin.ignore(100,'\n'); } //getItem void printList(char product[][12],int quantity[], double price[], int count) //print list of all items { cout<<"PRODUCT\tQUANTITY\tPRICE\n"; for(int i=0;i