Sie sind auf Seite 1von 3

#include<conio.h> #include<process.h> #include<stdio.h> #include<fstream.

h>
#include<string.h> //Function prototype declaration void main_menu(); void add_shop();
void show_shop(); void rem_shop(); void mod_shop(); void cus_slip(); // Global Variables
char g; float today_sale=0; class shop // Class for the products' records { int code; float price;
char name[32]; public : void getdata() { cout<<"nEnter Item code => ";

cin>>code; cout<<"nEnter Item name => "; gets(name); cout<<"nEnter Price => ";
cin>>price; } void putdata() { cout<<"Item Code => "<<code<<"t Price => "<<price<<"t
Name => "; puts(name); } int getcode() { return code; } float getp() { return price; } }; //end
of class void main() // Main Function of the program { clrscr();
char n[32]; cout<<"nnEnter username => "; cin>>n; if( ( (strcmp(n,"Kunal")==0) ||
(strcmp(n,"Mohit")==0)||(strcmp(n,”Sudhi”)==0) ) ) { main_menu(); } else {
cout<<"nInvalid Username !!! "; cout<<"nDo you want to retry (y/n) => "; cin>>g; if (g=='y')
{ main(); } else { exit(0); } } getch(); } // End of the main function void main_menu() //
Function for displaying main_menu { clrscr(); cout<<"ntt*********************";
textattr(9+128); textbackground(15); cprintf(" t AFWWA t "); textattr(15);
cout<<"************************";
cout<<"ntt ( Air Force Wives Welfare Association )"; int ch; cout<<"nChoose from the
selected option(s) --> nn"; textattr(6); cprintf("1 . Add item to the Shop "); cout<<endl;
cprintf("2 . Remove item from the the Shop "); cout<<endl; cprintf("3 . Modify Details of a
item"); cout<<endl; cprintf("4 . Show all available items"); cout<<endl; cprintf("5 . Customer
Slip"); cout<<endl; cprintf("6 . Today's sale "); cout<<endl; cprintf("7 . Exit");
cout<<"nnEnter your choice => "; cin>>ch; switch(ch) { case 1: add_shop(); break; case 2:
rem_shop(); break; case 3: mod_shop(); break;
case 4: show_shop(); break; case 5: cus_slip(); break; case 6: { clrscr(); cout<<"nToday's
total sale => "<<today_sale; cout<<"nnnDo you want to go to main menu (y/n) => "; cin>>g;
if(g=='y') main_menu(); } break; case 7: exit(0); break; default: cout<<"nInvalid Choice !!n";
cout<<"nChoose againn"; } //Switch case closed } //End of main function
void add_shop() // Function to adding items to Shop { clrscr(); textattr(15);
cout<<"ntt*********************"; textbackground(15); textattr(9); cprintf(" t AFWWA t
"); cout<<"************************ntt ( Air Force Wives Welfare Association )";
fstream f1; shop s1; char c='y'; f1.open("affwa.txt",ios::app|ios::binary); while(c== 'y') {
cout<<"nnEnter the detail of the Item => "; s1.getdata(); f1.write( (char*)&s1,sizeof(s1));
cout<<"nDo you want to enter more details (y/n) => "; cin>>c; } f1.close(); cout<<"nDo you
want to go main menu (y/n) => "; cin>>g;
if(g=='y') { clrscr(); main_menu(); } else { exit(0); } } // End of add_shop() function void
show_shop() // Function to show all available items { clrscr(); fstream f1; shop s1;
cout<<"nt**** Item list ****n"; f1.open("affwa.txt",ios::in|ios::binary); f1.seekg(0,ios::beg);
while(!f1.eof()) { f1.read((char*)&s1,sizeof(s1)); cout<<"n"; s1.putdata(); } f1.close();
cout<<"nDo you want to go to main menu (y/n) => ";
cin>>g; if(g=='y') main_menu(); else exit(0); } // End of show_shop() function void
mod_shop() // Function for modifying details of items { clrscr(); int k; fstream f1; shop s1;
cout<<"nEnter the item code whoose data is to be modified => "; cin>>k;
f1.open("affwa.txt",ios::in|ios::binary); f1.seekg(0,ios::beg); int pos; while(!f1.eof()) {
pos=f1.tellg(); f1.read((char*)&s1,sizeof(s1)); if ( k==s1.getcode() ) { cout<<"nEnter new
details => n";
s1.getdata(); f1.seekp(pos); f1.write((char*)&s1,sizeof(s1)); break; } } f1.close();
main_menu(); } void rem_shop() // Function for removing the details of a item { clrscr();
fstream m1,m2; shop s1; m1.open("affwa.txt",ios::in|ios::out|ios::binary);
m2.open("a_temp.txt",ios::out|ios::binary); m1.seekg(0,ios::beg); int k; cout<<"nnEnter the
item code whose record you want to delete => "; cin>>k; while(!m1.eof()) {
m1.read((char*)&s1,sizeof(s1)); if ( k==s1.getcode() ) { }
else { m2.write((char*)&s1,sizeof(s1)); } } m1.close(); m2.close(); remove("affwa.txt");
rename("a_temp.txt","affwa.txt"); cout<<"nThe item has been removed !!n "; cout<<"nDo
you want to go to main menu (y/n) => "; cin>>g; if(g=='y') { clrscr(); main_menu(); } else {
exit(0); } } void cus_slip() // Function for displaying customers’ bill { clrscr();
cout<<"ntt*************** Customer Slip **************nnn"; fstream f1; shop s; int
qty; float cost , tot_cost=0;
int tno; f1.open("affwa.txt",ios::in|ios::binary); f1.seekp(0,ios::beg); char ch='y';
while(ch=='y') // while 1 { while( !f1.eof()) // while 2 { f1.read((char*)&s,sizeof(s));
cout<<"nEnter the item no .=> "; cin>>tno; if( (s.getcode())==tno ) // if 1 { cout<<"nEnter
quantity => "; cin>>qty; cost=qty*(s.getp()); tot_cost+=cost; today_sale+=tot_cost;
cout<<"nCost => "<<cost; } // if 1 cout<<"nDo you want to enter more items to your cart
(y/n) => "; cin>>ch; if(ch=='y') { continue; } else { break; }
} // while 2 } // while 1 f1.close(); cout<<"nnnTotal Amount to be paid by the Customer =>
"<<tot_cost;; cout<<"nnDo you want to go to main menu (y/n) => "; cin>>g; if(g=='y') {
main_menu(); } }

Das könnte Ihnen auch gefallen