Demo entry 3586628
abc
Submitted by anonymous
on Feb 04, 2016 at 07:51
Language: C++. Code size: 24.7 kB.
#include<iostream.h> #include<conio.h> #include<string.h> #include<fstream.h> #include<stdio.h> #include<process.h> #include<dos.h> class club { protected: int club_number; char club_name[20]; int club_level; int budget_limit; int wage_limit; public: int gcl() { return club_level; } int gbl() { return budget_limit; } int gwl() { return wage_limit; } void sbl(int a) { budget_limit -= a; } void swl(int a) { wage_limit = wage_limit-a; } club(club &x) { strcpy(club_name,x.getclubname()); club_number=x.getclubno (); club_level=x.gcl(); budget_limit=x.gbl(); wage_limit=x.gwl(); } void in() { cprintf("Enter Club Number\n\r"); cin>>club_number; cprintf("Enter Club Name\n\r"); gets(club_name); cprintf("Enter Club Level\n\r"); cin>>club_level; cprintf("Enter the Budget\n\r"); cin>>budget_limit; cprintf("Enter Wage Limit\n\r"); cin>>wage_limit; } char* getclubname() { return club_name; } int getclubno() { return club_number; } void incbl(int a) { budget_limit +=a; } void incwl(int a) { wage_limit -= a; } void out() { cout<<club_number<<"\n\r"; puts(club_name); cout<<club_level<<"\n\r"; cout<<budget_limit<<"\n\r"; } club getobject() { return *this; } club() { } void clubmarket(); }; class player { int player_number; char first_name[10]; char last_name[10]; int age; char position[5]; int rating; int contract; int wages; int importance_level; char old_club_name[20]; char new_club_name[20]; char status[10]; int market_value; int fee; public: club player_club; void in() { cprintf("Enter Player Number\n\r"); cin>>player_number; cprintf("Enter First Name\n\r"); gets(first_name); cprintf("Enter Last Name\n\r"); gets(last_name); cprintf("Enter Age\n\r"); cin>>age; cprintf("Enter Position\n\r"); gets(position); cprintf("Enter Rating\n\r"); cin>>rating; cprintf("Enter Contract Date\n\r"); cin>>contract; cprintf("Enter Weekly Wages\n\r"); cin>>wages; cprintf("Enter Status at the Club\n\r"); cin>>importance_level; cprintf("Enter Club Name\n\r"); gets(old_club_name); strcpy(new_club_name,old_club_name); cprintf("Enter market value\n\r"); cin>>market_value; cprintf("Enter the Transfer status\n\r"); gets(status); cprintf("Enter the fee paid\n\r"); cin>>fee; } char* getoldclubname() { return old_club_name; } char* getnewclubname() { return new_club_name; } void setclub(club &a) { player_club = a; } void setcontract(int a) { contract = a; } void setwages(int a) { wages = a; } void setimportance(int a) { importance_level = a; } void setstatus() { strcpy(status,"Transferred"); } void setfee(int a) { fee = a; } void setclubname(char *a) { strcpy(old_club_name,new_club_name); strcpy(new_club_name,a); } int getwages() { return wages; } int getage() { return age; } int getmarketvalue() { return market_value; } int getplayerno() { return player_number; } club getclub() { return player_club; } char* getfirstname() { return first_name; } char* getlastname() { return last_name; } char* getposition() { return position; } int getrating() { return rating; } int getimportancelevel() { return importance_level; } void out() { cout<<player_number<<"\n"; puts(first_name); player_club.out(); } void display() { cout<<player_number<<" "; printf(last_name); cout<<" "<<age<<" "; printf(position); cout<<" "<<rating<<" "; cout<<wages<<" "; printf(new_club_name); cout<<endl; } int wageaccept(int a); int offeraccept(int a,int b,int c); }; void makeoffer(club a); player returnplayer(int a); void welcome(); void club::clubmarket() { clubmarketstart: clrscr(); char ch; cprintf("Press 1. for Current Contracts\n\r"); cprintf("Press 2. to Buy Players\n\r"); cprintf("Press 3. to See Done Deals\n\r"); cprintf("Press 4. to Exit\n\r"); ch = getche(); if(ch == '1') { char ch_a; player temp_player; ifstream fin; fin.open("players.dat",ios::in|ios::binary); while(!fin.eof()) { fin.read((char*)&temp_player,sizeof(temp_player)); if(strcmp(temp_player.getoldclubname(),club_name) == 0) { temp_player.display(); } } fin.close(); cprintf("Wanna extend the contract of a player?\n\r"); ch_a = getche(); if(ch_a == 'y') { int temp_number,temp_offer,temp_years; cprintf("Enter the player number whose contract is to be extended\n\r"); cin>>temp_number; cprintf("Enter the offer\n\r"); cin>>temp_offer; cprintf("Enter number of years"); cin>>temp_years; fin.open("players.dat",ios::in|ios::binary); while(!fin.eof()) { fin.read((char*)&temp_player,sizeof(temp_player)); if(temp_player.getplayerno() == temp_number) { int result = temp_player.wageaccept(temp_offer); swl(temp_offer-temp_player.getwages()); if(result == 1 && gwl()>= 0) { cprintf("Negotiation Successfull!\n\r"); temp_player.setwages(temp_offer); temp_player.setcontract(temp_years); delay(500); goto clubmarketstart; } else if(result == 0) { cprintf("Negotiation Unsuccessfull!\n\r"); delay(500); incwl(temp_offer-temp_player.getwages()); goto clubmarketstart; } else { cprintf("Sorry, Insufficient Funds\n\r"); delay(500); goto clubmarketstart; } } } fin.close(); } else { goto clubmarketstart; } } else if(ch == '2') { buyplayercondition: clrscr(); char ch_a; cprintf("Choose the parameter to search with\n\r"); cprintf("Press 1. to Search by First Name\n\r"); cprintf("Press 2. to Search by Last Name\n\r"); cprintf("Press 3. to Search by Age\n\r"); cprintf("Press 4. to Search by Position\n\r"); cprintf("Press 5. to Search by Ratings\n\r"); cprintf("Press 6. to Search by Age and Position\n\r"); cprintf("Press 7. to Search by Position and Ratings\n\r"); cprintf("Press 8. to return to Exit from here\n\r"); ch_a = getche(); cout<<endl; ifstream fin; if(ch_a == '1') { char name[10]; cprintf("Enter the name\n\r"); gets(name); cout<<endl; player temp_player; fin.open("players.dat",ios::in|ios::binary); int c = 0; while(!fin.eof()) { fin.read((char*)&temp_player,sizeof(temp_player)); if(strcmp(temp_player.getfirstname(),name) == 0) { temp_player.display(); c++; } } fin.close(); if(c == 0) { cprintf("HOLLA! No matches found.\n\r"); delay(500); goto buyplayercondition; } cprintf("Wanna make an offer?\n\r"); char ch_b; ch_b = getche(); cout<<endl; if(ch_b == 'y') { makeoffer(getobject()); } } else if(ch_a == '2') { char name[10]; cprintf("Enter the name\n\r"); gets(name); cout<<endl; player temp_player; fin.open("players.dat",ios::in|ios::binary); int c = 0; while(!fin.eof()) { fin.read((char*)&temp_player,sizeof(temp_player)); if(strcmp(temp_player.getlastname(),name) == 0) { temp_player.display(); c++; } } fin.close(); if(c == 0) { cprintf("HOLLA! No matches found.\n\r"); delay(500); goto buyplayercondition; } cprintf("Wanna make an offer?\n\r"); char ch_b; ch_b = getche(); cout<<endl; if(ch_b == 'y') { makeoffer(getobject()); } } else if(ch_a == '3') { int age; cprintf("Enter the Maximum age\n\r"); cin>>age; cout<<endl; player temp_player; fin.open("players.dat",ios::in|ios::binary); int c = 0; while(!fin.eof()) { fin.read((char*)&temp_player,sizeof(temp_player)); if(temp_player.getage() <= age) { temp_player.display(); c++; } } fin.close(); if(c == 0) { cprintf("HOLLA! No matches found.\n\r"); delay(500); goto buyplayercondition; } cprintf("Wanna make an offer?\n\r"); char ch_b; ch_b = getche(); cout<<endl; if(ch_b == 'y') { makeoffer(getobject()); } } else if(ch_a == '4') { char pos[10]; cprintf("Enter the position\n\r"); gets(pos); cout<<endl; player temp_player; fin.open("players.dat",ios::in|ios::binary); int c = 0; while(!fin.eof()) { fin.read((char*)&temp_player,sizeof(temp_player)); if(strcmp(temp_player.getposition(),pos) == 0) { temp_player.display(); c++; } } fin.close(); if(c == 0) { cprintf("HOLLA! No matches found.\n\r"); delay(500); goto buyplayercondition; } cprintf("Wanna make an offer?\n\r"); char ch_b; ch_b = getche(); cout<<endl; if(ch_b == 'y') { makeoffer(getobject()); } } else if(ch_a == '5') { int rating; cprintf("Enter the Minimum Rating\n\r"); cin>>rating; cout<<endl; player temp_player; fin.open("players.dat",ios::in|ios::binary); int c = 0; while(!fin.eof()) { fin.read((char*)&temp_player,sizeof(temp_player)); if(temp_player.getrating() >= rating) { temp_player.display(); c++; } } fin.close(); if(c == 0) { cprintf("HOLLA! No matches found.\n\r"); delay(500); goto buyplayercondition; } cprintf("Wanna make an offer?\n\r"); char ch_b; ch_b = getche(); cout<<endl; if(ch_b == 'y') { makeoffer(getobject()); } } else if(ch_a == '6') { char pos[5]; int age; cprintf("Enter the position\n\r"); gets(pos); cout<<endl; cprintf("Enter the Maximum age\n\r"); cin>>age; cout<<endl; player temp_player; fin.open("players.dat",ios::in|ios::binary); int c = 0; while(!fin.eof()) { fin.read((char*)&temp_player,sizeof(temp_player)); if((strcmp(temp_player.getposition(),pos) == 0) && (temp_player.getage() <= age)) { temp_player.display(); c++; } } fin.close(); if(c == 0) { cprintf("HOLLA! No matches found.\n\r"); delay(500); goto buyplayercondition; } cprintf("Wanna make an offer?\n\r"); char ch_b; ch_b = getche(); cout<<endl; if(ch_b == 'y') { makeoffer(getobject()); } } else if(ch_a == '7') { char pos[5]; int rating; cprintf("Enter the position\n\r"); gets(pos); cout<<endl; cprintf("Enter the Minimum Ratings\n\r"); cin>>rating; cout<<endl; player temp_player; fin.open("players.dat",ios::in|ios::binary); int c = 0; while(!fin.eof()) { fin.read((char*)&temp_player,sizeof(temp_player)); if((strcmp(temp_player.getposition(),pos) == 0) && (temp_player.getrating() >= rating)) { temp_player.display(); c++; } } fin.close(); if(c == 0) { cprintf("HOLLA! No matches found.\n\r"); delay(500); goto buyplayercondition; } cprintf("Wanna make an offer?\n\r"); char ch_b; ch_b = getche(); cout<<endl; if(ch_b == 'y') { makeoffer(getobject()); } } else if(ch_a == '8') { goto clubmarketstart; } else { cprintf("Please enter a valid choice.\n\r"); delay(500); goto buyplayercondition; } } else if(ch == '3') { player temp_player; ifstream fin; fin.open("players.dat",ios::in|ios::binary); int c = 0; while(!fin.eof()) { fin.read((char*)&temp_player,sizeof(temp_player)); if((strcmp(temp_player.getnewclubname(),temp_player.getoldclubname()) != 0) && (strcmp(temp_player.getnewclubname(),getclubname()) == 0)) { temp_player.display(); c++; } } fin.close(); if(c == 0) { cprintf("HOLLA! No transfers yet.\n\r"); delay(500); goto clubmarketstart; } } } void makeoffer(club temp_club) { player temp_player; int temp_offer; int temp_wages; int temp_number; int temp_importance; int contract_duration; cprintf("Enter the Player number\n\r"); cin>>temp_number; cprintf("Enter the offer you want to make\n\r"); cin>>temp_offer; cprintf("Enter the wages you want to give\n\r"); cin>>temp_wages; cprintf("Enter the player Importnace level\n\r"); cin>>temp_importance; cprintf("Enter contract lenght offered\n\r"); cin>>contract_duration; cout<<endl; temp_player = returnplayer(temp_number); int result1 = temp_player.wageaccept(temp_wages); int result2 = temp_player.offeraccept(temp_offer,temp_importance,temp_club.gcl()); if((result1 * result2) == 1) { temp_club.swl(temp_wages); temp_club.sbl(temp_offer); if((temp_club.gbl()>=0) && (temp_club.gwl()>=0)) { cprintf("Congratualtion!!! You have bought the player\n\r"); temp_player.setclubname(temp_club.getclubname()); temp_player.setclub(temp_club); temp_player.setcontract(contract_duration); temp_player.setwages(temp_wages); temp_player.setimportance(temp_importance); temp_player.setfee(temp_offer); temp_player.setstatus(); delay(500); temp_club.clubmarket(); } else if((temp_club.gbl()>=0) && (temp_club.gwl()<0)) { cprintf("You have exceeded your Wage Limit!\n\r"); temp_club.incwl(temp_wages); temp_club.incbl(temp_offer); delay(500); temp_club.clubmarket(); } else if((temp_club.gwl()>=0) && (temp_club.gbl()<0)) { cprintf("You have exceeded your Budget Limit!\n\r"); temp_club.incwl(temp_wages); temp_club.incbl(temp_offer); delay(500); temp_club.clubmarket(); } else { cprintf("You have exceeded Wage as well as Budget Limit!\n\r"); temp_club.incwl(temp_wages); temp_club.incbl(temp_offer); delay(500); temp_club.clubmarket(); } } else if(result1 == 0 && result2 == 1) { cprintf("You were unsuccessfull in your effort. The player didn't approve them.\n\r"); cprintf("Better luck next time\n\r"); delay(500); temp_club.clubmarket(); } else if(result1 == 1 && result2 == 0) { cprintf("You were unsuccessfull in your effort. The club didn't approve them.\n\r"); cprintf("Better luck next time\n\r"); delay(500); temp_club.clubmarket(); } else if(result1 == 0 && result2 == 0) { cprintf("You were unsuccessfull in your effort. The player and the club didn't approve them.\n\r"); cprintf("Better luck next time\n\r"); delay(500); temp_club.clubmarket(); } } int player::wageaccept(int temp_wages) { if(age <= 30 && temp_wages >= 13*wages) { return 1; } else if(age > 30 && temp_wages >= 9*wages) { return 1; } else { return 0; } } int player::offeraccept(int temp_offer,int temp_imp,int temp_clublevel) { int counter1 = 0; int counter2 = 0; int counter3 = 0; if(age <= 30) { if(temp_offer >= 13*market_value) { counter1 = 1; } if((importance_level-temp_imp) >= -1) { counter2 = 1; } if((player_club.gcl()-temp_clublevel) >= -1) { counter3 = 1; } } else { if(temp_offer >= 9*market_value) { counter1 = 1; } if((importance_level-temp_imp) >= -1) { counter2 = 1; } if((player_club.gcl()-temp_clublevel) >= -2) { counter3 = 1; } } return counter1*counter2*counter3; } player returnplayer(int a) { ifstream fin; fin.open("players.dat",ios::in|ios::binary); player temp_player; while(!fin.eof()) { fin.read((char*)&temp_player,sizeof(temp_player)); if(temp_player.getplayerno() == a) { break; } } fin.close(); return temp_player; } int editdata() { clrscr(); char ch,pass[10]; cprintf("Enter password to access database.(Enter exit to move out.)\n\r"); gets(pass); if(strcmp(pass,"DoNotOpen") == 0) { cprintf("Enter 1. for Entering Team\n\r"); cprintf("Enter 2. for Entering Players\n\r"); cprintf("Enter 3. to Edit Database\n\r"); cprintf("Enter 9. to Exit\n\r"); ch = getche(); cout<<endl; char counter = '1'; ofstream fout; ifstream fin; if(ch == '1') { fout.open("clubs.dat",ios::app|ios::binary); club new_club; do { new_club.in(); fout.write((char*)&new_club,sizeof(new_club)); cprintf("Do you want to continue? Press Y to continue\n\r"); counter = getche(); cout<<endl; } while(counter == 'y'); fout.close(); editdata(); } else if(ch == '2') { fout.open("players.dat",ios::app|ios::binary); fin.open("clubs.dat",ios::in|ios::binary); club temp_club; player new_player; do { new_player.in(); while(!fin.eof()) { fin.read((char*)&temp_club,sizeof(temp_club)); if(strcmp(temp_club.getclubname(),new_player.getoldclubname())==0) { new_player.player_club = temp_club; break; } } fout.write((char*)&new_player,sizeof(new_player)); cprintf("Want to Continue?\n\r"); counter = getche(); cout<<endl; } while(counter == 'y'); fout.close(); fin.close(); editdata(); } else if(ch == '3') { editthings: fstream f1; char choice; cprintf("Enter 1. to Edit Teams\n\r"); cprintf("Enter 2. to Edit Players\n\r"); cprintf("Enter 3. to Exit\n\r"); choice = getche(); cout<<endl; if(choice == '1') { club temp_club; int cno,pos; f1.open("clubs.dat",ios::in|ios::ate|ios::binary); cprintf("Enter the club number whose data is to be edited\n\r"); cin>>cno; while(!f1.eof()) { pos = f1.tellg(); f1.read((char*)&temp_club, sizeof(temp_club)); if((temp_club.getclubno()) == cno) { temp_club.in(); f1.seekg(pos); f1.write((char*)&temp_club,sizeof(temp_club)); break; } } cprintf("Operation on the file done!\n\r"); f1.close(); } else if(choice == '2') { player temp_player; int pno,pos; f1.open("players.dat",ios::in|ios::ate|ios::binary); cprintf("Enter the player number whose data you want to edit\n\r"); cin>>pno; while(!f1.eof()) { pos = f1.tellg(); f1.read((char*)&temp_player, sizeof(temp_player)); if((temp_player.getplayerno()) == pno) { temp_player.in(); f1.seekg(pos); f1.write((char*)&temp_player,sizeof(temp_player)); break; } } cprintf("Operation on the file done!\n\r"); f1.close(); } else if(choice == '3') { editdata(); } else { goto editthings; } } else if(ch == '4') { ifstream f1; f1.open("players.dat",ios::in|ios::binary); player a; if(f1) { while(!f1.eof()) { f1.read((char*)&a,sizeof(a)); a.out(); } if(!f1.eof()){f1.close();} } //exit(0); f1.close(); } else if(ch == '5') { ifstream f1; f1.open("clubs.dat",ios::in|ios::binary); while(!f1.eof()) { club a; f1.read((char*)&a,sizeof(a)); if(!f1.eof()){a.out();} } f1.close(); } else if(ch == '9') { welcome(); } else { cprintf("Wrong Choice!"); return 1; } } else if(strcmpi(pass,"exit")==0) { welcome(); } else { editdata(); } return 0; } void welcome() { char ch; cprintf("Select what are you headed for?\n\r"); cprintf("Press 1. for club specific things\n\r"); cprintf("Press 2. to access the Database\n\r"); cprintf("Press 3. to Exit\n\r"); ch = getche(); cout<<endl; if(ch == '1') { club temp_club; int ch_a; cprintf("Press 1. for Manchester United\n\r"); cprintf("Press 2. for Chelsea\n\r"); cprintf("Press 3. for FC Barcelona\n\r"); cprintf("Press 4. for Real Madrid\n\r"); cprintf("Press 5. for Juventus\n\r"); cprintf("Press 6. for Bayern Munich\n\r"); cprintf("Press 7. for Borussia Dortmund\n\r"); cprintf("Press 8. for PSG\n\r"); cin>>ch_a; cout<<endl; ifstream fin; fin.open("clubs.dat",ios::in|ios::binary); while(!fin.eof()) { fin.read((char*)&temp_club,sizeof(temp_club)); if(ch_a == temp_club.getclubno()) { break; } } temp_club.clubmarket(); fin.close(); } else if(ch == '2') { while(editdata()==1) {//do nothing } } else if(ch == '3') { char choice; cprintf("Are you sure you want to end this Interactive Game?(Y for Yes)\n\r"); choice = getche(); cout<<endl; if(choice == 'y') { cprintf("Thank you for visiting this virtual world\n\r"); cprintf("ADIEU!"); sleep(1); exit(0); } else { welcome(); } } else { cprintf("Wrong Choice!\n\r"); welcome(); } } void startscreen() { cout<<" /$$ /$$/$$$$$$$$/$$ /$$$$$$ /$$$$$$ /$$ /$$/$$$$$$$$"<<endl; cout<<"| $$ /$ | $| $$_____| $$ /$$__ $$/$$__ $| $$$ /$$| $$_____/"<<endl; cout<<"| $$ /$$$| $| $$ | $$ | $$ \\__| $$ \\ $| $$$$ /$$$| $$"<<endl; cout<<"| $$/$$ $$ $| $$$$$ | $$ | $$ | $$ | $| $$ $$/$$ $| $$$$$"<<endl; cout<<"| $$$$_ $$$| $$__/ | $$ | $$ | $$ | $| $$ $$$| $| $$__/"<<endl; cout<<"| $$$/ \\ $$| $$ | $$ | $$ $| $$ | $| $$\\ $ | $| $$"<<endl; cout<<"| $$/ \\ $| $$$$$$$| $$$$$$$| $$$$$$| $$$$$$| $$ \\/ | $| $$$$$$$$"<<endl; cout<<"|__/ \\__|________|________/\\______/ \\______/|__/ |__|______/"<<endl; sleep(1); clrscr(); cout<<" /$$$$$$$$/$$$$$$"<<endl; cout<<"|__ $$__/$$__ $$"<<endl; cout<<" | $$ | $$ \\ $$"<<endl; cout<<" | $$ | $$ | $$"<<endl; cout<<" | $$ | $$ | $$"<<endl; cout<<" | $$ | $$ | $$"<<endl; cout<<" | $$ | $$$$$$/"<<endl; cout<<" |__/ \\______/"<<endl; sleep(1); clrscr(); cout<<" /$$$$$$$$/$$$$$$$ /$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$$$/$$$$$$$$/$$$$$$$ "<<endl; cout<<"|__ $$__| $$__ $$/$$__ $| $$$ | $$/$$__ $| $$_____| $$_____| $$__ $$"<<endl; cout<<" | $$ | $$ \\ $| $$ \\ $| $$$$| $| $$ \\__| $$ | $$ | $$ \\ $$"<<endl; cout<<" | $$ | $$$$$$$| $$$$$$$| $$ $$ $| $$$$$$| $$$$$ | $$$$$ | $$$$$$$/"<<endl; cout<<" | $$ | $$__ $| $$__ $| $$ $$$$\\____ $| $$__/ | $$__/ | $$__ $$"<<endl; cout<<" | $$ | $$ \\ $| $$ | $| $$\\ $$$/$$ \\ $| $$ | $$ | $$ \\ $$"<<endl; cout<<" | $$ | $$ | $| $$ | $| $$ \\ $| $$$$$$| $$ | $$$$$$$| $$ | $$"<<endl; cout<<" |__/ |__/ |__|__/ |__|__/ \\__/\\______/|__/ |________|__/ |__/"<<endl; sleep(1); clrscr(); cout<<" /$$ /$$ /$$$$$$ /$$$$$$$ /$$ /$$/$$$$$$$$/$$$$$$$$"<<endl; cout<<"| $$$ /$$$/$$__ $| $$__ $| $$ /$$| $$_____|__ $$__/"<<endl; cout<<"| $$$$ /$$$| $$ \\ $| $$ \\ $| $$ /$$/| $$ | $$ "<<endl; cout<<"| $$ $$/$$ $| $$$$$$$| $$$$$$$| $$$$$/ | $$$$$ | $$ "<<endl; cout<<"| $$ $$$| $| $$__ $| $$__ $| $$ $$ | $$__/ | $$ "<<endl; cout<<"| $$\\ $ | $| $$ | $| $$ \\ $| $$\\ $$| $$ | $$ "<<endl; cout<<"| $$ \\/ | $| $$ | $| $$ | $| $$ \\ $| $$$$$$$$ | $$ "<<endl; cout<<"|__/ |__|__/ |__|__/ |__|__/ \\__|________/ |__/ "<<endl; sleep(1); clrscr(); } void main() { clrscr(); startscreen(); welcome(); getch(); }
This snippet took 0.05 seconds to highlight.
Back to the Entry List or Home.