Page 454 - C++
P. 454
iword.open("word.txt");
iword.getline(word,25,'\n');
iword.close();
}
//Destructor for end values
item::~item()
{ofstream ocode,oname,oprice,oword;
oname.open("name.txt");
for(int i=0;name[i][0]!='\0';i++)
oname<<name[i]<<"\n";
oname.close();
ocode.open("code.txt");
for(i=0;name[i][0]!='\0';i++)
ocode<<code[i]<<"\n";
ocode.close();
oprice.open("price.txt");
for(i=0;name[i][0]!='\0';i++)
oprice<<price[i]<<"\n";
oprice.close();
oword.open("word.txt");
oword<<word<<"\n";
oword.close();
}
//Fn for adding inventory
void item::add ()
{char choice,choice1;
int temp;
do{clrscr();
cout<<"\n\t\t\t Add item!";
cout<<"\n\n Enter item code:";
cin>>temp;
for(int i=0;name[i][0]!='\0'&&code[i]!=temp;i++);
if(code[i]==temp)
{clrscr();
cout<<"\n\t\t\t Replace item!";
cout<<"\n\n\a The following code already exists. Do you want to
replace it?(press y/any other key):";
choice1=getch();
if(choice1=='y'||choice1=='Y')
{cout<<"\n\n Enter item code:"<<temp;
cout<<"\n\n Enter name of item:";
gets(name[i]);
cout<<"\n Enter price:Rs. ";
cin>>price[i];}
cout<<"\n\t Do you want to add/replace more items?(press y/any
other key):";
choice=getch();
continue;
}