Sale!

CSCI 240 Program 2 Formatted Output and Integer Division solution

$30.00 $25.50

Category:

Description

5/5 - (5 votes)

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 is the 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:

  • prompt 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.
  • calculate the slugging percentage (the calculation is described above). This is a double/float value and MUST be placed into a double or float variable.
  • display the slugging percentage with EXACTLY 3 digits after the decimal point

Processing Requirements

 

  1. At the top of your 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. As mentioned above, the calculated slugging percentage should be displayed with exactly 3 digits after the decimal point.
  3. Make sure and test your program with values that you have calculated.
  4. Hand in a copy of your source code 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