0% found this document useful (0 votes)
611 views7 pages

Baseball Simulator in C++

The document defines functions and variables to simulate a baseball season and playoffs. It includes: 1) Functions to create leagues, divisions, and teams. 2) Functions to simulate a season by determining division winners, wild card teams, and setting up playoff matchups. 3) Functions to simulate playoff series using random numbers and determine a champion. It allows for simulating multiple seasons and viewing previous championship results. The code uses data structures like maps, vectors, and sets to organize the teams and results.

Uploaded by

Michael Peterson
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
611 views7 pages

Baseball Simulator in C++

The document defines functions and variables to simulate a baseball season and playoffs. It includes: 1) Functions to create leagues, divisions, and teams. 2) Functions to simulate a season by determining division winners, wild card teams, and setting up playoff matchups. 3) Functions to simulate playoff series using random numbers and determine a champion. It allows for simulating multiple seasons and viewing previous championship results. The code uses data structures like maps, vectors, and sets to organize the teams and results.

Uploaded by

Michael Peterson
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

#include <iostream> #include <string> #include "console.h" #include "vector.h" #include "map.h" #include "set.h" #include "random.

h" #include "simpio.h" #include "foreach.h" using namespace std; /* Constants */ const int TEA !"#$"%#& ' (; const int TEA !"#$")EA*+E ' ,(; /* -unction protot.pes */ ap<string/ &ector<string> > create)eague01; &ector<string> createConference0 ap<string/ &ector<string> > 2 league/ string letter1; void formatTitles0 ap<string/ int> 2 titles1; int get enu01; void pla.!eason0string 2 champion/ ap<string/ &ector<string> > 2 league/ &ector<string> 2 A)Teams/ &ector<string> 2 $)Teams/ ap<string/ int> 2 titles/ int num3er1; void create%ivision0string division/ string team,/ string team4/ string team5/ string team6/ string team(/ ap<string/ &ector<string> > 2 result1; void get7ildCardTeams0&ector<string> 2 A)Teams/ &ector<string> 2 $)Teams/ &ector<string> 2 A)8)a.offTeams/ &ector<string> 2 $)8)a.offTeams/ !et<string> 2 A)chosen/ !et<string> 2 $)chosen/ int num3er1; void determineChampion0string 2 champion/ &ector<string> 2 A)8la.offTeams/ &ector<string> 2 $)8la.offTeams/ ap<string/ int> 2 titles/ int num3er1; /* ain 8rogram */ int main01 9 string champion; int .ear ' 4:,5; ap<string/ &ector<string> > league ' create)eague01; &ector<string> A)Teams ' createConference0league/ "A"1; &ector<string> $)Teams ' createConference0league/ "$"1; ap<string/ int> titles; formatTitles0titles1; int menu ' get enu01; ;hile0menu <' 61 9 if0menu '' ,1 9 string champion; pla.!eason0champion/ league/ A)Teams/ $)Teams/ titles/ menu1; cout << "The ;inner of the " << .ear << " 7orld !eries is the " << champion << "<" << endl; .ear==; > if 0menu '' 41 9

to simulateB "1;

int num?ears ' get#nteger0"@o; man. seasons ;ould .ou liAe

;hile 0num?ears < :1 num?ears ' get#nteger0"8lease enter a positive integerB "1; int count ' :; ;hile 0count < num?ears1 9 pla.!eason0champion/ league/ A)Teams/ $)Teams/ titles/ menu1; cout << "The ;inner of the " << .ear << " 7orld !eries is the " << champion << "<" << endl; .ear==; count==; > > if0menu '' 51 9 cout << "7orld !eries Titles 3efore the " << .ear << " 3ase3all season..." << endl; foreach0string Ae. in titles1 9 cout << Ae. << "B " << titles.get0Ae.1 << endl; > > menu ' get enu01; > return :; > ap<string/ &ector<string> > create)eague01 9 ap<string/ &ector<string> > result; create%ivision0"A) 7est"/ "@ouston Astros"/ ")os Angeles Angels"/ "CaAland Athletics"/ "!eattle ariners"/ "TeDas Eangers"/ result1; create%ivision0"A) Central"/ "Chicago 7hite !oD"/ "Cleveland #ndians"/ "%etroit Tigers"/ "Fansas Cit. Eo.als"/ " innesota T;ins"/ result1; create%ivision0"A) East"/ "Galtimore Crioles"/ "Goston Eed !oD"/ "$e; ?orA ?anAees"/ "Tampa Ga. Ea.s"/ "Toronto Glue Ha.s"/ result1; create%ivision0"$) 7est"/ "AriIona %iamond3acAs"/ "Colorado EocAies"/ ")os Angeles %odgers"/ "!an %iego 8adres"/ "!an -rancisco *iants"/ result1; create%ivision0"$) Central"/ "Chicago Cu3s"/ "Cincinnati Eeds"/ " il;auAee Gre;ers"/ "8itts3urgh 8irates"/ "!t. )ouis Cardinals"/ result1; create%ivision0"$) East"/ "Atlanta Graves"/ " iami arlins"/ "$e; ?orA ets"/ "8hiladelphia 8hillies"/ "7ashington $ationals"/ result1; return result; > &ector<string> createConference0 ap<string/ &ector<string> > 2 league/ string letter1 9 &ector<string> result; &ector<string> ;est ' league.get0letter = string0""1 = ") 7est"1; &ector<string> central ' league.get0letter = string0""1 = ") Central"1; &ector<string> east ' league.get0letter = string0""1 = ") East"1; for0int i ' :; i < ;est.siIe01; i==1 9 result.add0;estJiK1;

result.add0centralJiK1; result.add0eastJiK1; > return result; > void formatTitles0 ap<string/ int> 2 titles1 9 titles.put0"$e; ?orA ?anAees"/ 4L1; titles.put0"!t. )ouis Cardinals"/ ,,1; titles.put0"Goston Eed !oD"/ L1; titles.put0"!an -rancisco *iants"/ L1; titles.put0"CaAland Athletics"/ M1; titles.put0"8itts3urgh 8irates"/ (1; titles.put0")os Angeles %odgers"/ N1; titles.put0"Cincinnati Eeds"/ (1; titles.put0"%etroit Tigers"/ 61; titles.put0"Galtimore Crioles"/ 51; titles.put0" innesota T;ins"/ 51; titles.put0"Chicago 7hite !oD"/ 51; titles.put0"Chicago Cu3s"/ 41; titles.put0"Cleveland #ndians"/ 41; titles.put0" iami arlins"/ 41; titles.put0"$e; ?orA ets"/ 41; titles.put0"8hiladelphia 8hillies"/ 41; titles.put0"Toronto Glue Ha.s"/ 41; titles.put0")os Angeles Angels"/ ,1; titles.put0"Atlanta Graves"/ 51; titles.put0"AriIona %iamond3acAs"/ ,1; titles.put0"Fansas Cit. Eo.als"/ ,1; titles.put0"7ashington $ationals"/ :1; titles.put0"!an %iego 8adres"/ :1; titles.put0" il;auAee Gre;ers"/ :1; titles.put0"TeDas Eangers"/ :1; titles.put0"Tampa Ga. Ea.s"/ :1; titles.put0"Colorado EocAies"/ :1; titles.put0"!eattle ariners"/ :1; titles.put0"@ouston Astros"/ :1; > int get enu01 9 cout << "7ould .ou liAe to... " << endl; cout << ",. !imulate a season and vie; results." << endl; cout << "4. !imulate a specified num3er of seasons." << endl; cout << "5. &ie; championships." << endl; cout << "6. Ouit." << endl; int menu ' get#nteger0"Enter ,/ 4/ 5/ or 6B "1; ;hile0menu <' , 22 menu <' 4 22 menu <' 5 22 menu <' 61 9 menu ' get#nteger0"8lease enter ,/ 4/ 5/ or 6B "1; > return menu; > void pla.!eason0string 2 champion/ ap<string/ &ector<string> > 2 league/ &ector<string> 2 A)Teams/ &ector<string> 2 $)Teams/ ap<string/ int> 2 titles/ int num3er1 9

&ector<string> A)8la.offTeams; !et<string> A)chosen; &ector<string> $)8la.offTeams; !et<string> $)chosen; int count ' :; foreach0string Ae. in league1 9 int random ' random#nteger0:/ TEA !"#$"%#& P ,1; &ector<string> division ' league.get0Ae.1; string ;inner ' divisionJrandomK; if 0num3er '' ,1 cout << "The " << Ae. << " division champion is the " << ;inner << "." << endl; if 0count < 51 9 A)8la.offTeams.add0;inner1; A)chosen.add0;inner1; > else 9 $)8la.offTeams.add0;inner1; $)chosen.add0;inner1; > count==; > get7ildCardTeams0A)Teams/ $)Teams/ A)8la.offTeams/ $)8la.offTeams/ A)chosen/ $)chosen/ num3er1; determineChampion0champion/ A)8la.offTeams/ $)8la.offTeams/ titles/ num3er1; > void create%ivision0string division/ string team,/ string team4/ string team5/ string team6/ string team(/ ap<string/ &ector<string> > 2 result1 9 &ector<string> teams; teams.add0team,1; teams.add0team41; teams.add0team51; teams.add0team61; teams.add0team(1; result.put0division/ teams1; > void get7ildCardTeams0&ector<string> 2 A)Teams/ &ector<string> 2 $)Teams/ &ector<string> 2 A)8la.offTeams/ &ector<string> 2 $)8la.offTeams/ !et<string> 2 A)chosen/ !et<string> 2 $)chosen/ int num3er1 9 int ;ild, ' random#nteger0:/ TEA !"#$")EA*+E P ,1; ;hile0A)chosen.contains0A)TeamsJ;ild,K11 9 ;ild, ' random#nteger0:/ TEA !"#$")EA*+E P ,1; > A)chosen.add0A)TeamsJ;ild,K1; int ;ild4 ' random#nteger0:/ TEA !"#$")EA*+E P ,1; ;hile0A)chosen.contains0A)TeamsJ;ild4K11 9 ;ild4 ' random#nteger0:/ TEA !"#$")EA*+E P ,1; > string ;ildCard, ' A)TeamsJ;ild,K; string ;ildCard4 ' A)TeamsJ;ild4K; if 0num3er '' ,1 cout << "The A) 7ild Card ;inners are " << ;ildCard, << " and " << ;ildCard4 << "." << endl; if0randomChance0:.(:11 9

if 0num3er '' ,1 cout << ;ildCard, << " ;on the A) game<" << endl; A)8la.offTeams.add0;ildCard,1; > else 9 if 0num3er '' ,1 cout << ;ildCard4 << " ;on the A) game<" << endl; A)8la.offTeams.add0;ildCard41; > int ;ild5 ' random#nteger0:/ TEA !"#$")EA*+E P ,1; ;hile0$)chosen.contains0$)TeamsJ;ild5K11 9 ;ild5 ' random#nteger0:/ TEA !"#$")EA*+E P ,1; > $)chosen.add0$)TeamsJ;ild5K1; int ;ild6 ' random#nteger0:/ TEA !"#$")EA*+E P ,1; ;hile0$)chosen.contains0$)TeamsJ;ild6K11 9 ;ild6 ' random#nteger0:/ TEA !"#$")EA*+E P ,1; > string ;ildCard5 ' $)TeamsJ;ild5K; string ;ildCard6 ' $)TeamsJ;ild6K; if 0num3er '' ,1 cout << "The $) 7ild Card ;inners are " << " and " << ;ildCard6 << "." << endl; if0randomChance0:.(:11 9 if 0num3er '' ,1 cout << ;ildCard5 << " ;on the A) game<" << endl; $)8la.offTeams.add0;ildCard51; > else 9 if 0num3er '' ,1 cout << ;ildCard6 << " ;on the $) game<" << endl; $)8la.offTeams.add0;ildCard61; > >

7ild Card

7ild Card

<< ;ildCard5 7ild Card

7ild Card

void determineChampion0string 2 champion/ &ector<string> 2 A)8la.offTeams/ &ector<string> 2 $)8la.offTeams/ ap<string/ int> 2 titles/ int num3er1 9 int random ' random#nteger0:/41; string A)seed, ' A)8la.offTeamsJrandomK; A)8la.offTeams.remove0random1; int random, ' random#nteger0:/,1; string A)seed4 ' A)8la.offTeamsJrandom,K; A)8la.offTeams.remove0random,1; string A)seed5 ' A)8la.offTeamsJ:K; A)8la.offTeams.remove0:1; string A)seed6 ' A)8la.offTeamsJ:K; int random4 ' random#nteger0:/41; string $)seed, ' $)8la.offTeamsJrandom4K; $)8la.offTeams.remove0random41; int random5 ' random#nteger0:/,1; string $)seed4 ' $)8la.offTeamsJrandom5K; $)8la.offTeams.remove0random51; string $)seed5 ' $)8la.offTeamsJ:K; $)8la.offTeams.remove0:1; string $)seed6 ' $)8la.offTeamsJ:K; if 0num3er '' ,1 9 cout << "The 8la.off seedings are... " << endl; cout << "American )eagueB " << endl; cout << ",. " << A)seed, << " vs. 6. " << A)seed6 << endl;

cout cout cout cout

<< << << <<

"4. " << A)seed4 << "$ational )eagueB " ",. " << $)seed, << "4. " << $)seed4 <<

" vs. 5. " << A)seed5 << endl; << endl; " vs. 6. " << $)seed6 << endl; " vs. 5. " << $)seed5 << endl;

> string A)C!,; string A)C!4; string $)C!,; string $)C!4; if0randomChance0:.(:11 9 if 0num3er '' ,1 cout << "The " << A)seed, << " have defeated the " << A)seed6 << " and ;ill advance to the A)C!." << endl; A)C!, ' A)seed,; > else 9 if 0num3er '' ,1 cout << "The " << A)seed6 << " have defeated the " << A)seed, << " and ;ill advance to the A)C!." << endl; A)C!, ' A)seed6; > if0randomChance0:.(:11 9 if 0num3er '' ,1 cout << "The " << A)seed4 << " have defeated the " << A)seed5 << " and ;ill advance to the A)C!." << endl; A)C!4 ' A)seed4; > else 9 if 0num3er '' ,1 cout << "The " << A)seed5 << " have defeated the " << A)seed4 << " and ;ill advance to the A)C!." << endl; A)C!4 ' A)seed5; > if0randomChance0:.(:11 9 if 0num3er '' ,1 cout << "The " << $)seed, << " have defeated the " << $)seed6 << " and ;ill advance to the $)C!." << endl; $)C!, ' $)seed,; > else 9 if 0num3er '' ,1 cout << "The " << $)seed6 << " have defeated the " << $)seed, << " and ;ill advance to the $)C!." << endl; $)C!, ' $)seed6; > if0randomChance0:.(:11 9 if 0num3er '' ,1 cout << "The " << $)seed4 << " have defeated the " << $)seed5 << " and ;ill advance to the $)C!." << endl; $)C!4 ' $)seed4; > else 9 if 0num3er '' ,1 cout << "The " << $)seed5 << " have defeated the " << $)seed4 << " and ;ill advance to the $)C!." << endl; $)C!4 ' $)seed5; > string 7!,; string 7!4; if 0num3er '' ,1 cout << "The A)C! ;ill 3e pla.ed 3et;een the " << A)C!, << " and the " << A)C!4 << "." << endl; if0randomChance0:.(:11 9 if 0num3er '' ,1 cout << "The " << A)C!, << " have defeated the " << A)C!4 << " and ;ill advance to the 7orld !eries." << endl; 7!, ' A)C!,; > else 9 if 0num3er '' ,1 cout << "The " << A)C!4 << " have defeated the " << A)C!, << " and ;ill advance to the 7orld !eries." << endl; 7!, ' A)C!4;

> if 0num3er '' ,1 cout << "The $)C! ;ill 3e pla.ed 3et;een the " << $)C!, << " and the " << $)C!4 << "." << endl; if0randomChance0:.(:11 9 if 0num3er '' ,1 cout << "The " << $)C!, << " have defeated the " << $)C!4 << " and ;ill advance to the 7orld !eries." << endl; 7!4 ' $)C!,; > else 9 if 0num3er '' ,1 cout << "The " << $)C!4 << " have defeated the " << $)C!, << " and ;ill advance to the 7orld !eries." << endl; 7!4 ' $)C!4; > cout << "The 7orld !eries ;ill 3e pla.ed 3et;een the " << 7!, << " and the " << 7!4 << "." << endl; if0randomChance0:.(:11 9 champion ' 7!,; > else 9 champion ' 7!4; > int numTitles ' titles.get0champion1; numTitles==; titles.put0champion/ numTitles1; >

You might also like