Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please have the code in C++ with explanation. Thank you so much! Question 3 (17 points): Fantasy Baseball team Major League Baseball (MLB) is an
Please have the code in C++ with explanation. Thank you so much!
Question 3 (17 points): Fantasy Baseball team Major League Baseball (MLB) is an American professional baseball organization and the oldest of the major professional sports leagues in the United States. A total of 30 teams play in Major League Baseball and the next MLB is planned to start in April 2021. Your friend is playing fantasy baseball league and is asking your help in choosing their team. You decide to select players based on Sabermetrics measures and your task is to come up with a program for that. Sabermetrics or SABRmetrics is the empirical analysis of baseball, especially baseball statistics that measure in-game activity. For the sake of simplicity, let us write a program that chooses 9 players - 5 batters (hitters) and 4 pitchers, to form a team. The program should ask the user to enter the filenames and read those files with player statistics of batters and pitchers, and display the output as mentioned below. Selection criteria for players has been explained later. If there are enough players who satisfy the criteria to form a team, then display the selected players information and print the message "Great, your team is ready!". If there aren't enough players who satisfy the criteria to form a team, then display the selected players information and print the message Not enough players who satisfy the criteria to form a team!". If the file cannot be opened, print "Could not open file(s)." Players information is organized in two text files (one for batters and one for pitchers) such that the data corresponding to each player is on one line, with the values separated by commas. Batters (Hitters): Batters are chosen based on a metric known as on-base plus slugging, which is the sum of two Sabermetrics measures - on-base percentage (OBP) and slugging percentage (SLG). These measurements are computed as follows, H + BB + HBP OBP AB + BB + HBP + SF Here, OBP is On-base percentage (double) His Hits (integer) BB is Bases on Balls (Walks) (integer) HBP is Hit By Pitch (integer) AB is At Bat (integer) SF is Sacrifice fly (integer) (1B) + (2 x 2B) + (3 x 3B) + (4 HR) SLG = AB Here, 1B refers to Singles (integer) 2B refers to Doubles (integer) 3B refers to Triples (integer) HR refers to Home runs (integer) AB refers to At bat (integer) OPS = OBP + SLG Here, OPS is on-base plus slugging (double) OBP is on-base percentage (double) SLG is slugging percentage (double) If the overall score (i.e. on-base plus slugging) is 0.9 or higher, you will select the player in your team. You need to choose 5 such batters for your team in a sequential manner (i.e. you will select the first 5 players whose OPS is 0.9 or higher from the list of players in the input file). Please note that players with an OPS score of O should not be selected. Pitchers: Pitchers are chosen based on Walks plus Hits per Inning Pitched (WHIP). It is computed as follows, BB+H WHIP= IP Here, WHIP is Walks plus Hits per Inning Pitched (double) BB is Bases on Balls (Walks) (integer) His Hits (integer) IP is Innings Pitched (double) You will choose the players with the score 1 or lower, for our team in the sequential manner (i.e. you will select the first 4 players whose WHIP is 1 or lower from the list of players in the input file). Please note that players with WHIP score of O should not be selected. If you're interested to learn more about these terms, you can check out this link. Finally, you will display the players' names selected along with their information - role of the player (batter or pitcher), team for which they are playing in MLB (see sample run 1 below). Please note that you need to display all the selected batters first and then display all the selected pitchers. Note: Remember to account for integer division. The samples files of batters and pitchers are shown below. The data includes the player name, team for which the player is currently playing, and the general metrics discussed above for batters and pitchers. This is the batters.csv file that the user will enter in sample run 1 Doubles Triples At Bats Hits 12 20 21 Hits by Pitch 0 0 6 31 Singles 3 3 7 45 35 29 4 O 9 10 1 Player Team 2 Anthony Alford PIT 3 Nicky Delmonico CWS 4. Brett Phillips KC 5 Anthony Rizzo CHC 6 Kevin Newman PIT 7 Jared Walsh LAA 8 Hernan Perez CHC 9 Ramon Laureano OAK 10 Jaylin Davis SF 11 Joey Rickard SF 12 Jake Lamb OAK 13 Garrett Stubbs HOU 14 Home runs Bases on balls Sacrifice fly 1 1 1 0 2 1 1 3 11 28 1 12 2 9 5 0 203 156 99 6 1 1 HOOOOOOOO 15 26 9 22 37 18 OOOW OWN NOOO ONPOO @ wne 1 0 183 HOUHOMO 39 12 0 2 1 12 5 0 0 12 17 2 45 8 2 0 1 27 1 This is the pitchers.csv file that the user will enter in sample run 1 Hits Innings Pitched 45.2 Walks 31 31 15 9 5 0 0 14 73 9 30 9 4 6 1 Player 2 Justin Dunn 3 Yimi Garcia 4 Foster Griffin 5 Franklyn Kilome 6 Kyle Gibson 7 Mychal Givens 8 Ryan Sherriff 9 Roberto Osuna 10 Richard Rodriguez 11 Tommy Doyle 12 Drew Rasmussen 13 Devin Williams 14 Caleb Baragar 15 Kevin Ginkel 16 Zack Burdi 17 Cody Stashak Team SEA MIA KC NYM TEX COL TB HOU PIT COL MIL MIL SF ARI CWS MIN 1.2 11.1 67.1 9.1 9.2 4.1 23.1 2.1 15.1 27 22.1 16 3 15 NOO 6 17 8 9 17 21 11 7.1 15 11 Sample run 1 Expected Output (user input is in bold): Enter the filename of batters: batters.csv Enter the filename of pitchers: pitchers.csv Selected Players: Anthony Alford, Batter, PIT Jared Walsh, Batter, LAA Hernan Perez, Batter, CHC Jaylin Davis, Batter, SF Joey Rickard, Batter, SF Yimi Garcia, Pitcher, MIA Ryan Sherriff, Pitcher, TB Roberto Osuna, Pitcher, HOU Richard Rodriguez, Pitcher, PIT Great, your team is ready! Sample Run 1 Explanation: For Anthony Alford, OBP & SLG can be computed using the formulas mentioned above. OBP comes out to be equal to (3+1+0)/(12+1+0+0) = 0.3076923077. SLG is equal to (3+2*0+3*1+4*1)/12 = 2.333333333. Now we can get OPS by summing the values of these two metrics, and it is equal to 2.641025641. Since the value of OPS is higher than 0.900, we select this player. For Nicky Delmonico, OBP is equal to (3+2+0)/(20+2+0+0) = 0.2272727273, and SLG is equal to (6+2*0+3*0+4*0)/20 = 0.3. Since the sum of these two values is lower than 0.900, we will not select the player. Similarly, we select the first 5 batters from the input file who satisfy the given criteria. In the case of Justin Dunn, the value of the Sabermetrics measurement WHIP is equal to (31+31)/45.2 = 1.371681416. Since this value is higher than 1.000, we do not select this player. For Yimi Garcia, WHIP is equal to (5+9)/15 = 0.9333333333. As this value satisfies the given criteria, we select the player. Similarly, we select the first 4 pitchers from the input file who satisfy the given criteria. This is batters_sample_2.csv file that the user will enter in sample run 2 At Bats Hits 1 Player 2 Anthony Alford Team PIT Singles 3 Doubles Triples 21 O Home runs Bases on balls Sacrifice fly 1 1 1 Hits by Pitch 0 0 12 This is pitchers_sample_2.csv file that the user will enter in sample run 2 1 Player 2 Justin Dunn 3 Yimi Garcia Team SEA MIA Innings Pitched Hits 45.2 Walks 31 31 15 9 5 Sample Run 2 Expected Output (user input is in bold): Enter the filename of batters: batters_sample_2.csv Enter the filename of pitchers: pitchers_sample_2.csv Selected Players: Anthony Alford, Batter, PIT Yimi Garcia, Pitcher, MIA Not enough players who satisfy th criteri to form a team! The two files that are entered in sample run 3 are not exist so it should prints could not open files Sample Run 3 Expected Output (user input is in bold): Enter the filename of batters: fileNotPresenti.csv Enter the filename of pitchers: fileNotPresent2.csv Could not open file (s)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started