Sale!

CSCI 240 Program 1 Arithmetic solution

$30.00 $25.50

Category:

Description

5/5 - (6 votes)

Overview

Write a program to calculate the number of singles and total number of bases for a baseball player using information supplied by the player.

If you’re not familiar with baseball, keep reading. Otherwise, move ahead to the section titled “Basic Program Logic.” A lot of baseball terms are pretty self-explanatory: a single is a 1 base hit, a double is a 2 base hit, and a triple is a 3 base hit. The one that may not be familiar is a home run, which is a 4 base hit.

Basic Program Logic

    • prompt the player for the total number of hits. This is an integer value that should be stored in an integer variable.
    • prompt the player for the number of doubles they have hit. This is an integer value that should be stored in an integer variable.
    • prompt the player for the number of triples they have hit. This is an integer value that should be stored in an integer variable.
    • prompt the player for the number of home runs they have hit. This is an integer value that should be stored in an integer variable.
    • calculate the number of singles and the total number of bases the player has earned:
number of singles = total number of hits - number of doubles - number of triples - number of home runs
  
total number of bases = number of singles + (number of doubles * 2) + (number of triples * 3) + (number of home runs * 4)
  • display the number of each type of hit (single, double, triple, and home run) with an appropriate label
  • display the total number of bases with an appropriate label

Processing Requirements

    1. At the top of your C++ source code, include a documentation box that resembles the following, making sure to put your name after the “Programmer” label, the section of CSCI 240 that you’re in after the “Section” label, and the due date for the program after the “Date Due” label. A box similar to this one will be put in EVERY source code file that is handed in this semester.

Note: DO NOT put this box within cout statements. It should NOT be displayed as part of the output from the program.

/***************************************************************
CSCI 240         Program 1     Fall 2016

Programmer:

Section:

Date Due:

Purpose: This program calculates the number of singles and total
         number of bases for a baseball player.
***************************************************************/
    1. Include the following lines of code BELOW the documentation box:
#include <iostream>
#include <iomanip>

using namespace std;
  1. Use type int for all of the variables. Make sure to use meaningful variable names.
  2. Make sure and test your program with values other than the ones supplied in the sample output.
  3. Hand in a copy of your source code (the .cpp file) on Blackboard.

Sample Output:

A single run of the program should resemble the following:

Enter the number of hits: 167
Enter the number of doubles: 32
Enter the number of triples: 4
Enter the number of home runs: 19


Singles: 112   Doubles: 32   Triples: 4   Home Runs: 19

Total Bases: 264

Or

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


Singles: 58   Doubles: 34   Triples: 4   Home Runs: 25

Total Bases: 238