Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview For this assignment, write a program that will expand on program 1 to include a calculation of the baseball player's slugging percentage. Slugging percentage

Overview

For this assignment, write a program that will expand on program 1 to include a calculation of the baseball player's slugging percentage.

Slugging percentage represents the total number of bases a player records per at bat, which means that it is essentially a measure of the power of a hitter. It is calculated by taking the total number of bases divided by the number of at bats the player has taken.

Basic Program Logic

The basic logic for this program is similar to program 1.

Add code that will ask the player for the number of at bats they have taken. This should be placed AFTER the code that prompts the player for their number of hits, doubles, triples, and home runs. This is an integer value and MUST be placed into an integer variable.

Add code to calculate the slugging percentage (the calculation is described above). Since this calculation uses the total number of bases, it should be placed AFTER the code from program 1 that calculates the total number of bases. This is a double/float value and MUST be placed into a double or float variable. Note: keep in mind that the use of integer variables means that the calculation has integer division and that will need to be taken into consideration in order to get the correct result.

Finally, add code to display the slugging percentage with EXACTLY 3 digits after the decimal point. This should be placed AFTER the information that was displayed in Program 1.

Program Requirements

  1. At the top of the C++ source code, include a documentation box that resembles the one from program 1. Make sure the Date Due and Purpose are updated to reflect the current program.

  2. Include line documentation. There is no need to document every single line, but logical "chunks" of code should be preceded by a line or two that describes what the "chunk" of code does. This will be a part of every program that is submitted for the remainder of the semester.

  3. As mentioned above, the calculated slugging percentage must be displayed with exactly 3 digits after the decimal point.

  4. Make sure and test the program with values other than the ones supplied in the sample output.

  5. Hand in a copy of the source code (CPP file) using Blackboard.

Output

A few runs of the program should produce the following results:

Run 1

Enter the number of hits: 121 Enter the number of doubles: 34 Enter the number of triples: 4 Enter the number of home runs: 25 Enter the number of at bats: 416 Singles: 58 Doubles: 34 Triples: 4 Home Runs: 25 Total Bases: 238 Slugging Percentage: 0.572 

Run 2

Enter the number of hits: 125 Enter the number of doubles: 15 Enter the number of triples: 4 Enter the number of home runs: 2 Enter the number of at bats: 481 Singles: 104 Doubles: 15 Triples: 4 Home Runs: 2 Total Bases: 154 Slugging Percentage: 0.320

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is management? Have these definitions changed over time?

Answered: 1 week ago

Question

Ty e2y Evaluate the integral dy

Answered: 1 week ago

Question

Question What is a secular trust?

Answered: 1 week ago