Description
KEY ITEMS: Key items are marked in red. Failure to include or complete key items will incur additional deductions as noted beside the item.
Submission and Grading:
• Programs must compile using gcc 7.3.0 or higher with the following flags enabled o -Wall o -Wextra o -Wuninitialized o -pedantic-errors o -Wconversion
• Type your name and netID in the comments at the top of all files submitted. (-5 points)
Objective: Use programming fundamentals (loops, functions, arrays and file-based I/O) to construct a program in C++
Problem: Nintendo is developing a new Mario baseball game for Nintendo Switch. As an intern for Nintendo this semester, you have been given the task of developing a system to calculate player stats and determine the league leaders in several different baseball categories, such as hits, strikeouts and walks.
Zybooks Information:
• The Java source file will be named Main.java
• Your C++ source file will be named main.cpp
• Both implementations will have unlimited submissions
• Java warnings o To avoid potential errors when grading, do not create multiple Scanner objects for System.in.
▪ If the Scanner object is needed in multiple functions, please pass the Scanner object into the function.
o Do not create a package
Details:
• Start the program by prompting the user for the input filename
• Stats will be calculated for the following categories:
o Batting Average (BA)
▪ Batting average = hits / at-bats o On-base percentage (OB%)
▪ On-base percentage = (hits + walks + hit by pitch) / plate appearances o Strikeouts (K)
o Walks (BB) o Hit by Pitch (HBP) o Hits (H)
• Calculate all stats per person and record the highest value for each category o Search through the arrays to find the league leaders o There may be ties for the leaders o If there is a tie, output all names for tied value o Strikeout (K) leaders will be batters with the smallest value
• Arrays must be implemented in the program (-10 points if not) o Consider using an array for each category in parallel or multi-dimensional arrays o No array should have a size larger than 30
▪ For C++ implementation, use a size of 30 since this size must be known at compile time
• The program must use a minimum of 3 functions other than main (-5 points if not) o Remember each major, logical piece of the program should be a separate function
• The main function must call at least 3 of the functions you create (-5 points if not)
Input: All input will be read from a file. Each player’s data will be listed on separate lines in the file and will follow the same format.
• Format: <name><space><batting record>
o Mario HOOKWSHHKOHPWWHO
• The name will be a single word.
• The batting record will be a series of capital letters representing various results during a baseball game o H – hit o O – out o K – strikeout o W – walk
o P – hit by pitch o S – sacrifice
• A plate appearance is any valid result
• Walks, sacrifices and hit by pitches are not considered an at-bat
• Batting records may contain invalid characters. o If an invalid character is encountered, disregard it o Invalid characters are not counted as an at-bat
• Each line in the file will end in a newline except the last line which may or may not have a newline at the end
• The batting record for each person may not have the same number of results
Output: All output will be written to the console. Output will only occur at the end of the program. Each person’s individual stats should be written to the console followed by the league leaders for each category. All floating point values are displayed to three decimal places.
• Individual stats for each player – each item on a new line
o Name o BA:<space><value> o OB%:<space><value> o H:<space><value> o BB:<space><value> o K:<space><value> o HBP:<space><value> o Blank line
• If a tie for league leaders, separate each name with a comma and a space o The names will be listed in the same order they exist in the input file
• League leaders format – each item on a new line o LEAGUE LEADERS o BA:<space><name list><space><value> o OB%:<space><name list><space><value> o H:<space><name list><space><value> o BB:<space><name list><space><value> o K:<space><name list><space><value> o HBP:<space><name list><space><value>
Reviews
There are no reviews yet.