Last active
December 7, 2018 16:40
-
-
Save Binay1/9c38b6c0dd9154d49ae187814dfb2aa8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<fstream.h> | |
#include<conio.h> | |
#include<stdio.h> | |
#include<process.h> | |
#include<string.h> | |
#include<iomanip.h> | |
class game | |
{ | |
char gno[6]; | |
char gname[50]; | |
char pname[20]; | |
public: | |
void create_game() | |
{ | |
cout<<"\nNEW game ENTRY...\n"; | |
cout<<"\nEnter The game no."; | |
cin>>gno; | |
cout<<"\n\nEnter The Name of The game "; | |
gets(gname); | |
cout<<"\n\nEnter The Publisher's Name "; | |
gets(aname); | |
cout<<"\n\n\ngame Created.."; | |
} | |
void show_game() | |
{ | |
cout<<"\ngame no. : "<<gno; | |
cout<<"\ngame Name : "; | |
puts(gname); | |
cout<<"Publisher Name : "; | |
puts(aname); | |
} | |
void modify_game() | |
{ | |
cout<<"\ngame no. : "<<gno; | |
cout<<"\nModify game Name : "; | |
gets(gname); | |
cout<<"\nModify Publisher's Name of game : "; | |
gets(aname); | |
} | |
char* retgno() | |
{ | |
return gno; | |
} | |
void report() | |
{cout<<gno<<setw(30)<<gname<<setw(30)<<aname<<endl;} | |
}; | |
class customer | |
{ | |
char custid[6]; | |
char name[20]; | |
char stgno[6]; | |
int token; | |
public: | |
void create_customer() | |
{ | |
clrscr(); | |
cout<<"\nNEW CUSTOMER ENTRY...\n"; | |
cout<<"\nEnter The customer id "; | |
cin>>custid; | |
cout<<"\n\nEnter The Name of The customer "; | |
gets(name); | |
token=0; | |
stgno[0]='/0'; | |
cout<<"\n\nCustomer Record Created.."; | |
} | |
void show_customer() | |
{ | |
cout<<"\nCustomer id : "<<custid; | |
cout<<"\nCustomer Name : "; | |
puts(name); | |
cout<<"\nNo of game issued : "<<token; | |
if(token==1) | |
cout<<"\ngame No "<<stgno; | |
} | |
void modify_customer() | |
{ | |
cout<<"\nCustomer id : "<<custid; | |
cout<<"\nModify customer Name : "; | |
gets(name); | |
} | |
char* retcustid() | |
{ | |
return custid; | |
} | |
char* retstgno() | |
{ | |
return stgno; | |
} | |
int rettoken() | |
{ | |
return token; | |
} | |
void addtoken() | |
{token=1;} | |
void resettoken() | |
{token=0;} | |
void getstgno(char t[]) | |
{ | |
strcpy(stgno,t); | |
} | |
void report() | |
{cout<<"\t"<<custid<<setw(20)<<name<<setw(10)<<token<<endl;} | |
}; | |
fstream fp,fp1; | |
game bk; | |
customer st; | |
void write_game() | |
{ | |
char ch; | |
fp.open("game.dat",ios::out|ios::app); | |
do | |
{ | |
clrscr(); | |
bk.create_game(); | |
fp.write((char*)&bk,sizeof(game)); | |
cout<<"\n\nDo you want to add more record..(y/n?)"; | |
cin>>ch; | |
}while(ch=='y'||ch=='Y'); | |
fp.close(); | |
} | |
void write_customer() | |
{ | |
char ch; | |
fp.open("customer.dat",ios::out|ios::app); | |
do | |
{ | |
st.create_customer(); | |
fp.write((char*)&st,sizeof(customer)); | |
cout<<"\n\ndo you want to add more record..(y/n?)"; | |
cin>>ch; | |
}while(ch=='y'||ch=='Y'); | |
fp.close(); | |
} | |
void display_spb(char n[]) | |
{ | |
cout<<"\ngame DETAILS\n"; | |
int flag=0; | |
fp.open("game.dat",ios::in); | |
while(fp.read((char*)&bk,sizeof(game))) | |
{ | |
if(strcmpi(bk.retgno(),n)==0) | |
{ | |
bk.show_game(); | |
flag=1; | |
} | |
} | |
fp.close(); | |
if(flag==0) | |
cout<<"\n\ngame does not exist"; | |
getch(); | |
} | |
void display_sps(char n[]) | |
{ | |
cout<<"\ncustomer DETAILS\n"; | |
int flag=0; | |
fp.open("customer.dat",ios::in); | |
while(fp.read((char*)&st,sizeof(customer))) | |
{ | |
if((strcmpi(st.retcustid(),n)==0)) | |
{ | |
st.show_customer(); | |
flag=1; | |
} | |
} | |
fp.close(); | |
if(flag==0) | |
cout<<"\n\ncustomer does not exist"; | |
getch(); | |
} | |
void modify_game() | |
{ | |
char n[6]; | |
int found=0; | |
clrscr(); | |
cout<<"\n\n\tMODIFY GAME REOCORD.... "; | |
cout<<"\n\n\tEnter The game no. of The game"; | |
cin>>n; | |
fp.open("game.dat",ios::in|ios::out); | |
while(fp.read((char*)&bk,sizeof(game)) && found==0) | |
{ | |
if(strcmpi(bk.retgno(),n)==0) | |
{ | |
bk.show_game(); | |
cout<<"\nEnter The New Details of game"<<endl; | |
bk.modify_game(); | |
int pos=-1*sizeof(bk); | |
fp.seekp(pos,ios::cur); | |
fp.write((char*)&bk,sizeof(game)); | |
cout<<"\n\n\t Record Updated"; | |
found=1; | |
} | |
} | |
fp.close(); | |
if(found==0) | |
cout<<"\n\n Record Not Found "; | |
getch(); | |
} | |
void modify_customer() | |
{ | |
char n[6]; | |
int found=0; | |
clrscr(); | |
cout<<"\n\n\tMODIFY CUSTOMER RECORD... "; | |
cout<<"\n\n\tEnter The CUSTOMER id of The customer"; | |
cin>>n; | |
fp.open("customer.dat",ios::in|ios::out); | |
while(fp.read((char*)&st,sizeof(customer)) && found==0) | |
{ | |
if(strcmpi(st.retcustid(),n)==0) | |
{ | |
st.show_customer(); | |
cout<<"\nEnter The New Details of customer"<<endl; | |
st.modify_customer(); | |
int pos=-1*sizeof(st); | |
fp.seekp(pos,ios::cur); | |
fp.write((char*)&st,sizeof(customer)); | |
cout<<"\n\n\t Record Updated"; | |
found=1; | |
} | |
} | |
fp.close(); | |
if(found==0) | |
cout<<"\n\n Record Not Found "; | |
getch(); | |
} | |
void delete_customer() | |
{ | |
char n[6]; | |
int flag=0; | |
clrscr(); | |
cout<<"\n\n\n\tDELETE customer..."; | |
cout<<"\n\nEnter The customer id of the customer You Want To Delete : "; | |
cin>>n; | |
fp.open("customer.dat",ios::in|ios::out); | |
fstream fp2; | |
fp2.open("Temp.dat",ios::out); | |
fp.seekg(0,ios::beg); | |
while(fp.read((char*)&st,sizeof(customer))) | |
{ | |
if(strcmpi(st.retcustid(),n)!=0) | |
fp2.write((char*)&st,sizeof(customer)); | |
else | |
flag=1; | |
} | |
fp2.close(); | |
fp.close(); | |
remove("customer.dat"); | |
rename("Temp.dat","customer.dat"); | |
if(flag==1) | |
cout<<"\n\n\tRecord Deleted .."; | |
else | |
cout<<"\n\nRecord not found"; | |
getch(); | |
} | |
void delete_game() | |
{ | |
char n[6]; | |
clrscr(); | |
cout<<"\n\n\n\tDELETE game ..."; | |
cout<<"\n\nEnter The game no. of the game You Want To Delete : "; | |
cin>>n; | |
fp.open("game.dat",ios::in|ios::out); | |
fstream fp2; | |
fp2.open("Temp.dat",ios::out); | |
fp.seekg(0,ios::beg); | |
while(fp.read((char*)&bk,sizeof(game))) | |
{ | |
if(strcmpi(bk.retgno(),n)!=0) | |
{ | |
fp2.write((char*)&bk,sizeof(game)); | |
} | |
} | |
fp2.close(); | |
fp.close(); | |
remove("game.dat"); | |
rename("Temp.dat","game.dat"); | |
cout<<"\n\n\tRecord Deleted .."; | |
getch(); | |
} | |
void display_alls() | |
{ | |
clrscr(); | |
fp.open("customer.dat",ios::in); | |
if(!fp) | |
{ | |
cout<<"ERROR!!! FILE COULD NOT BE OPEN "; | |
getch(); | |
return; | |
} | |
cout<<"\n\n\t\tcustomer LIST\n\n"; | |
cout<<"==================================================================\n"; | |
cout<<"\tcustomer id"<<setw(10)<<"Name"<<setw(20)<<"game Issued\n"; | |
cout<<"==================================================================\n"; | |
while(fp.read((char*)&st,sizeof(customer))) | |
{ | |
st.report(); | |
} | |
fp.close(); | |
getch(); | |
} | |
void display_allb() | |
{ | |
clrscr(); | |
fp.open("game.dat",ios::in); | |
if(!fp) | |
{ | |
cout<<"ERROR!!! FILE COULD NOT BE OPEN "; | |
getch(); | |
return; | |
} | |
cout<<"\n\n\t\tgame LIST\n\n"; | |
cout<<"=========================================================================\n"; | |
cout<<"game Number"<<setw(20)<<"game Name"<<setw(25)<<"Publisher\n"; | |
cout<<"=========================================================================\n"; | |
while(fp.read((char*)&bk,sizeof(game))) | |
{ | |
bk.report(); | |
} | |
fp.close(); | |
getch(); | |
} | |
void game_issue() | |
{ | |
char sn[6],bn[6]; | |
int found=0,flag=0; | |
clrscr(); | |
cout<<"\n\ngame ISSUE ..."; | |
cout<<"\n\n\tEnter The customer's customer id"; | |
cin>>sn; | |
fp.open("customer.dat",ios::in|ios::out); | |
fp1.open("game.dat",ios::in|ios::out); | |
while(fp.read((char*)&st,sizeof(customer)) && found==0) | |
{ | |
if(strcmpi(st.retcustid(),sn)==0) | |
{ | |
found=1; | |
if(st.rettoken()==0) | |
{ | |
cout<<"\n\n\tEnter the game no. "; | |
cin>>bn; | |
while(fp1.read((char*)&bk,sizeof(game))&& flag==0) | |
{ | |
if(strcmpi(bk.retgno(),bn)==0) | |
{ | |
bk.show_game(); | |
flag=1; | |
st.addtoken(); | |
st.getstgno(bk.retgno()); | |
int pos=-1*sizeof(st); | |
fp.seekp(pos,ios::cur); | |
fp.write((char*)&st,sizeof(customer)); | |
cout<<"\n\n\t game issued successfully\n\nPlease Note: Write the current date in backside of your game and submit within 15 days fine Rs. 1 for each day after 15 days period"; | |
} | |
} | |
if(flag==0) | |
cout<<"game no does not exist"; | |
} | |
else | |
cout<<"You have not returned the last game "; | |
} | |
} | |
if(found==0) | |
cout<<"customer record not exist..."; | |
getch(); | |
fp.close(); | |
fp1.close(); | |
} | |
void game_deposit() | |
{ | |
char sn[6],bn[6]; | |
int found=0,flag=0,day,fine; | |
clrscr(); | |
cout<<"\n\ngame DEPOSIT ..."; | |
cout<<"\n\n\tEnter The customer’s customer id"; | |
cin>>sn; | |
fp.open("customer.dat",ios::in|ios::out); | |
fp1.open("game.dat",ios::in|ios::out); | |
while(fp.read((char*)&st,sizeof(customer)) && found==0) | |
{ | |
if(strcmpi(st.retcustid(),sn)==0) | |
{ | |
found=1; | |
if(st.rettoken()==1) | |
{ | |
while(fp1.read((char*)&bk,sizeof(game))&& flag==0) | |
{ | |
if(strcmpi(bk.retgno(),st.retstgno())==0) | |
{ | |
bk.show_game(); | |
flag=1; | |
cout<<"\n\ngame deposited in no. of days"; | |
cin>>day; | |
if(day>15) | |
{ | |
fine=(day-15)*1; | |
cout<<"\n\nFine has to deposited Rs. "<<fine; | |
} | |
st.resettoken(); | |
int pos=-1*sizeof(st); | |
fp.seekp(pos,ios::cur); | |
fp.write((char*)&st,sizeof(customer)); | |
cout<<"\n\n\t game deposited successfully"; | |
} | |
} | |
if(flag==0) | |
cout<<"game no does not exist"; | |
} | |
else | |
cout<<"No game is issued..please check!!"; | |
} | |
} | |
if(found==0) | |
cout<<"customer record not exist..."; | |
getch(); | |
fp.close(); | |
fp1.close(); | |
} | |
void intro() | |
{ | |
clrscr(); | |
gotoxy(35,11); | |
cout<<"Game"; | |
gotoxy(35,14); | |
cout<<"Rental"; | |
gotoxy(35,17); | |
cout<<"SYSTEM"; | |
cout<<"\n\nMADE BY : Binay Singh Chawla"; | |
cout<<"\n\nSCHOOL : DPS Mathura Road"; | |
getch(); | |
} | |
void admin_menu() | |
{ | |
clrscr(); | |
int ch2; | |
cout<<"\n\n\n\tADMINISTRATOR MENU"; | |
cout<<"\n\n\t1.CREATE customer RECORD"; | |
cout<<"\n\n\t2.DISPLAY ALL customerS RECORD"; | |
cout<<"\n\n\t3.DISPLAY SPECIFIC customer RECORD "; | |
cout<<"\n\n\t4.MODIFY customer RECORD"; | |
cout<<"\n\n\t5.DELETE customer RECORD"; | |
cout<<"\n\n\t6.CREATE GAME "; | |
cout<<"\n\n\t7.DISPLAY ALL GAMES "; | |
cout<<"\n\n\t8.DISPLAY SPECIFIC GAME "; | |
cout<<"\n\n\t9.MODIFY GAME "; | |
cout<<"\n\n\t10.DELETE GAME "; | |
cout<<"\n\n\t11.BACK TO MAIN MENU"; | |
cout<<"\n\n\tPlease Enter Your Choice (1-11) "; | |
cin>>ch2; | |
switch(ch2) | |
{ | |
case 1: clrscr(); | |
write_customer();break; | |
case 2: display_alls();break; | |
case 3: | |
char num[6]; | |
clrscr(); | |
cout<<"\n\n\tPlease Enter The customer id "; | |
cin>>num; | |
display_sps(num); | |
break; | |
case 4: modify_customer();break; | |
case 5: delete_customer();break; | |
case 6: clrscr(); | |
write_game();break; | |
case 7: display_allb();break; | |
case 8: { | |
char num[6]; | |
clrscr(); | |
cout<<"\n\n\tPlease Enter The game No. "; | |
cin>>num; | |
display_spb(num); | |
break; | |
} | |
case 9: modify_game();break; | |
case 10: delete_game();break; | |
case 11: return; | |
default:cout<<"\a"; | |
} | |
admin_menu(); | |
} | |
void main() | |
{ | |
char ch; | |
intro(); | |
do | |
{ | |
clrscr(); | |
cout<<"\n\n\n\tMAIN MENU"; | |
cout<<"\n\n\t01. GAME ISSUE"; | |
cout<<"\n\n\t02. GAME DEPOSIT"; | |
cout<<"\n\n\t03. ADMINISTRATOR MENU"; | |
cout<<"\n\n\t04. EXIT"; | |
cout<<"\n\n\tPlease Select Your Option (1-4) "; | |
ch=getche(); | |
switch(ch) | |
{ | |
case '1':clrscr(); | |
game_issue(); | |
break; | |
case '2':game_deposit(); | |
break; | |
case '3':admin_menu(); | |
break; | |
case '4':exit(0); | |
default :cout<<"\a"; | |
} | |
}while(ch!='4'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment