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
-
Line 1: will have the players name
-
Line 2 Line ??: Have the players stats for a single game.
-
Sample stats for a line in the text file. 5, 3, 0, 0, 1, 2
-
The data is: AtBats, Hits, Double, Triples, Homeruns, Walks.
-
Calculations Needed
-
Batting Average = (Hits / AtBats) * 1000. Truncate any decimal value.
-
Slugging Pct = ( (#Homeruns * 4) + (#Triples * 3) + (#Doubles * 2) + #singles ) / (AtBats)
-
Youll have to calculate the number of singles.
Requirements
-
Create a C++, Windows, Console app named CmpSc122_BaseballStats.
-
You only need one main() function.
-
Once open, read the first line which is the players name
-
Read the other lines (loop) in as a String.
-
Split the string into integers.
-
Convert the stats into integers so can do calculations.
-
Keep a total of the AtBats, Hits, Doubles, Triples, HomeRuns, and Walks.
-
After reading in all of the stats, calculate the batting average and the Slugging Percentage.
-
Display all of the totals and calculations to the monitor.
-
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
Get step-by-step solutions from verified subject matter experts
