Question: write in c++ Question 3 (17 points): Fantasy Baseball team Major League Baseball (MLB) is an American professional baseball organization and the oldest of the





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, any 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. Here is an example of a Batters text file containing three players' data: Sample Batters File: Player, Team, At Bats, Hits, Singles, Doubles, Triples, Home runs, Bases on balls, Sacrifice fly, Hits by Pitch Anthony Alford, PIT, 12,3,21,0,1,1,1,0,0 Nicky Delmonico, CWS, 20,3,6,0,0,0,2,0,0 Brett Phillips, KC, 31,7,4,0,1,1,3,0,0 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 porcentage (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 x 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 (.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 (.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. 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. Sample Run 1: Batters File (batters_sample_1.csv) Player, Team, At Bats, Hits, Singles, Doubles, Triples, Home runs, Bases on balls, Sacrifice fly, Hits by Pitch Anthony Alford, PIT, 12,3,21,0,1,1,1,0,0 Nicky Delmonico, CWS, 20,3,6,0,0,0,2,0,0 Brett Phillips, KC, 31, 7, 4,0,1,1,3,0,0 Anthony Rizzo, CHC, 203,45,9,6,0,11,28,2,10 Kevin Newman, PIT, 156, 35,15,5,0,1,12,2,1 Jared Walsh, LAA, 99, 29,26,4,2,9,5, 3,1 Hernan Perez, CHC, 6, 1,9,0,0,0,0,0,0 Ramon Laureano, OAK, 183, 39,22,8,1, 6,24,3,12 Jaylin Davis, SF, 12,2, 37,0,0,1,0,0,0 Joey Rickard, SF, 5,0,18,0,0,0,1,0,0 Jake Lamb, OAK, 45,12,17,4,0,3,2,0,2 Garrett Stubbs, HOU, 8,1,27,0,0,0,0,1,0 Pitchers File (pitchers_sample_1.csv) Player, Team, Innings Pitched, Hits, Bases on balls Justin Dunn, SEA, 45.2, 31, 31 Yimi Garcia, MIA, 15, 9,5 Foster Griffin, KC, 1.2,0,0 Franklyn Kilome, NYM, 11.1, 14,9 Kyle Gibson, TEX, 67.1, 73,30 Mychal Givens, COL., 9.1,9,4 Ryan Sherrift, TB, 9.2, 6,2 Roberto Osuna, HOU, 4.1, 3,0 Richard Rodriguez, PIT, 23.1, 15,5 Tommy Doyle, COL, 2.1,6,4 Drew Rasmussen, MIL, 15.1,17,9 Devin Williams, MIL, 27,8,9 Caleb Baragar, SE, 22.1,17,5 Kevin Ginkel, ARI, 16,21,13 Zack Burdi, CWS, 7.1,11,3 Cody Stashak,MIN, 15, 11,3 Expected Output (user input is in bold): Enter the filename of batters: batters.CBV 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 Sherritt, 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*14*1y12 - 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-0720 = 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+31745.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+9y/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. Sample Run 2 Batters File (batters_sample_2.csv) Player, Team, At Bats, Hits, Singles, Doubles, Triples, Home runs, Bases on balls, Sacrifice fly, Bits by Pitch Anthony Alford, PIT, 12,3,21,0,1,1,1,0,0 Pitchers File (pitchers_sample_2.csv) Player, Team, Innings Pitched, Hits, Bases on balls Justin Dunn, SEA, 45.2,31,31 Yimi Garcia, MIA, 15,9,5 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 the criteria to form a team! Sample Run 3 Expected Output (user input is in bold): Enter the filename of batters: FileNotPresenti.csv
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
