Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
h>
public: int retprodid(); char*retproductname(); float retprice(); void getit(int); void putit(); void add(); void disp();
int check (int quant); void show() { cout << pid << "\t"<< productname << "\t"<< price;} void searchprodname(char*); void modify(); void delete1(); void select(); void updatequantity(int quant)
{ quantity=quantity-quant; } }ob;
void getproc();
void disproc() { show(); cout << "\t" << prquan; cout << "\t" << procprice; } };
const int size=20; class bill { procitem data[size]; int top; float total;
int flag, loop=0; do{ cout << "\n Enter quantity: "; cin >> prquan;
flag=check(prquan);
else {
cout<<"\nERROR: Quantity of product in store is not enough. Please enter a lesser value : \n";
} while(loop==0);
caldynprice();
void bill::buy() { if(top==size-1) cout << "ERROR: OVERFLOW\n"; else { top++; data[top].getproc();
else { cout << "Sno.\tID\tName\tPrice\tQty\tProc\n"; for(i=0;i<=top;i++) { cout << (i+1) << "\t"; data[i].disproc(); cout << "\n"; total+=data[i].retprocprice(); } }
int item::check ( int quant) // Check the avialibility of quantity { fstream item_file; int ret=0; long pos; item_file.open("itemfile.dat",ios::in);
item_file.seekg(0);
return ret; } void item::select() { int val, flag=0; fstream f2; do{ cout << "\n Enter product ID: "; cin>>val;
f2.open("item1.dat",ios::in|ios::binary); while(f2.read((char*)&ob,sizeof(ob))) { if(val==ob.pid) { pid=ob.pid; strcpy(productname,ob.productname); price=ob.price; flag=1; break; } if(flag==0) { cout<<"ERROR: INVALID ID. Please enter the correct code agian : "; } } }while(flag==0); f2.close(); }
void item::getit(int n) {
pid=n; cout<<"\n\t\tEnter name:\t"; gets(productname); cout<<"\n\t\tEnter price:\t"; cin>>price; } void item::putit() { cout<<"\n\n\t\tProduct ID:\t"<<pid; cout<<"\n\n\t\tProduct Name:\t"<<productname; cout<<"\n\n\t\tPrice of the product:\t"<<price; }
f.open("item1.dat",ios::app|ios::binary);
while(loop==0) // to get an appropriate code. ( code entered by the user should not be code of //someother pre-existing product) { ifstream fi("item1.dat",ios::binary|ios::in); while(!fi.eof()) { fi.read((char*)&ob,sizeof(ob)); if(ob.pid==nu) { flag=1; break; } } if(flag==1) { cout<<"\n\n ERROR!!: The entered code is already present\n\n"; cout<<"\n\n Please try again with a different id:\n"; cout<<"\n\t\tEnter product id:\t"; cin>>nu; flag=0; } else loop=1; // loop will end because an appropriate code has been choosen } ob.getit(nu); f.write((char*)&ob,sizeof(ob)); f.close(); }
void item::disp() { fstream f1; f1.open("item1.dat",ios::binary|ios::in); while(f1.read((char*)&ob,sizeof(item))) ob.putit(); f1.close(); } void item::searchprodname(char*val) { fstream f2; int flag=0;
f2.open("item1.dat",ios::in|ios::binary); while(f2.read((char*)&ob,sizeof(ob))) { if(!strcmpi(val,ob.retproductname())) { cout << "\n\t\tDisplaying data\n"; ob.putit(); flag=1; break; } }
f2.close(); if(!flag) cout << "\n\n\t\tRecord not found !!!\n"; } void item::modify() { int c; char found='f'; cout<<"\nEnter the item code : "; cin>>c; fstream fio;
fio.open("item1.dat",ios::app|ios::in|ios::out|ios::binary);
pos=fio.tellg(); fio.read((char*)&ob, sizeof(ob)); if(ob.pid==c) { cout<<"Product id:"<<pid<<endl; cout<<"Product name :"<<productname<<endl; cout<<"Price:"<<price<<endl; cout<<"Quantity:"<<quantity<<endl; char ps[40]=" ";
if(strcmp(ps,".")!=0) strcpy(productname,ps);
fio.seekg(pos); fio.write((char*)&ob,sizeof(ob));
found='t'; break;
void item::delete1() {
int pc; char found = 'f', confirm='n'; cout<<" \nPlease enter the product code :\t\t "; cin>>pc; cout<<endl;
while(!fio.eof()) { fio.read((char*)&ob,sizeof(ob)); if(ob.pid==pc) {cout<<endl; ob.putit(); found='t'; cout<<"\n\n\n\t\t Are you sure you want to delete this record ? (y/n) : "; cin>>confirm ;
if(confirm=='n') item1.write((char*)&ob,sizeof(ob)); // when confirm is 'Y' the record is not written to temp item1.dat
else item1.write((char*)&ob,sizeof(ob)); }
remove("item1.dat"); rename("temp.dat","item1.dat"); // old item1.dat removed and new item1.dat added } void process() { bill s; int ch; char ans;
do { clrscr(); cout << "BILL:\n1.Buy\n2.Cancel\n3.Display Bill\n4. Display items\nEnter choice: "; cin >> ch; switch(ch) { case 1: s.buy(); break;
cout << "Do you want to continue (y/n): "; cin >> ans; } while(ans=='y' || ans=='Y'); getch(); }
void main() { int ch,i1=0; char choice,ans,arr[45][70],answer; char name[20], mname[20], mpass[20], ucode[20], uid[20]; float mcode; int j,i;
do{clrscr();
Z:cout<<"\n\n\n\t ***************** Welcome to the Retail Store ****************\n"; delay(400); cout << "\t\t 1.Do once shopping\n\n"; delay(250); cout << "\t\t 2.Administrator's place\n\n"; delay(250); cout << "\t\t 3.Exit\n\n"; delay(250);
cout << "\t\t Enter your choice\t\t"; delay(250); cin >> ch;
switch(ch) { case 1:
process(); break;
case 2: cout << "\n\n\t\t Computer welcomes you\t\t"; cout << "\n\n\t\t Enter 6 digit code\t\t";
X: cin>>mcode; if(mcode!=250116) { if(i1==2) { cout << "\n\n\t\t Sorry to inform that the usercode entered is wrong"; cout << "\n\n\t\t Thank you. Come back later again"; getch(); exit(0); break; }
else { i1++; cout << "\n\n\t\t" << 3-i1 << "chances left"; cout << "\n\n\t\t Reenter code\t\t"; goto X; }
else { do {
clrscr(); cout<<"\n\n\n\n\n\n\t\t~ * Welcome * ~ \n\n"; cout<<"\t\tYou can make new innovations as per your convenience\n\n\n"; cout<<"\t\t 1.Add products to the store\n\n"; cout<<"\t\t 2.View items list\n\n"; cout<<"\t\t 3.Modify the details of product\n\n"; cout<<"\t\t 4.Remove items from the store\n\n"; cout<<"\t\t 5.Search a product\n\n"; cout<<"\t\t 6.Exit\n\n";
cout << "\n\n\t\t----**** Entering data ****---- \n"; do { ob.add(); cout<<"\n\n\t\tWant to enter more products:"; cin>>choice;
}while(choice=='y'||choice=='Y');
cout<<"Do you want to go back to the administer's menu? "; cin>>ans; break;
case 2:
clrscr(); cout << "\n\n\t\t~~~~~~~~~ Dispalying data ~~~~~~~~\t"; ob.disp(); cout<<"Do you want to go back to the administer's menu? "; cin>>ans; break;
case 3: clrscr(); do {
ob.modify();
}while(choice=='y'||choice=='Y'); cout<<"Do you want to go back to the administer's menu? "; cin>>ans; break;
case 4: clrscr(); do {
ob.delete1();
}while(choice=='y'||choice=='Y');
cout<<"Do you want to go back to the administer's menu? "; cin>>ans; break;
case 5: clrscr(); do { cout << "\n\n\t\tEnter the item to be searched:\t"; gets(name); ob.searchprodname(name);
}while(choice=='y'||choice=='Y'); cout<<"Do you want to go back to the administer's menu? "; cin>>ans; break;
case 6: cout << "\n\n\t\tDo you want to exit to main menu:\t"; cin>>ans;
if(ans=='y'||ans=='Y') goto Z;
else break;
getch(); cout<<"Do you want to go back to the administer's menu? "; cin>>ans; break; }
}while(ans=='y'||ans=='Y'); }
case 3: cout << "\n\t\t Thanks for the visit"; getch(); exit(0); }