Question: (C++ Program) Lab: Read Baseball Stats from a Text File Purpose Practice reading data from a text file. Format of the Text File Line 1:

(C++ Program)

Lab: Read Baseball Stats from a Text File

Purpose

Practice reading data from a text file.

Format of the Text File

  1. Line 1: will have the players name

  2. Line 2 Line ??: Have the players stats for a single game.

    1. Sample stats for a line in the text file. 5, 3, 0, 0, 1, 2

    2. The data is: AtBats, Hits, Double, Triples, Homeruns, Walks.

Calculations Needed

  1. Batting Average = (Hits / AtBats) * 1000. Truncate any decimal value.

  2. Slugging Pct = ( (#Homeruns * 4) + (#Triples * 3) + (#Doubles * 2) + #singles ) / (AtBats)

  3. Youll have to calculate the number of singles.

Requirements

  1. Create a C++, Windows, Console app named CmpSc122_BaseballStats.

  2. You only need one main() function.

  3. Once open, read the first line which is the players name

  4. Read the other lines (loop) in as a String.

  5. Split the string into integers.

  6. Convert the stats into integers so can do calculations.

  7. Keep a total of the AtBats, Hits, Doubles, Triples, HomeRuns, and Walks.

  8. After reading in all of the stats, calculate the batting average and the Slugging Percentage.

  9. Display all of the totals and calculations to the monitor.

  10. Input File:

    Scott Kingery 5 5 0 0 0 0 6 3 1 0 1 1 3 0 0 0 0 1 4 1 0 0 0 0 4 4 1 1 1 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!