Spring 2025 CS 14 Individual Project
CSCI 14 Course Project, Baseball, 200 Points
Draft on 5/2/25, Final Expected on May 6 or May 7.
(This doc will be slightly revised after student feedback to include clarifications, improvements,
and more defined grading criteria. Assignment to be fully launched on May 7.)
Array of Struct with file input and output & Functions
The local baseball team is computerizing its records. You were asked to write a program that computes batting averages and other statistics.
There are 20 players on the team, identified by the numbers 1 through 20.
You will have two input files: (find them in Canvas).
You need to test run your program using those 2 files
(1) A Roster File –
A file contains 21 lines, first line is an integer indicating the season. The rest is in the format “last name first name” (separated by a space) for each player, as follows:
2022
Smith Sam
Jones Bob
Miller Miles (20 names for 20 players)
and etc….. (The players’ ID are numbered 1-20 in the order listed in this file.)
Noted: this file contains no player numbers, just their names. Assign the player ID while reading
(2) A Statistic File –
A separate file contains the game-by game statistics for the players as a “player ID number, hits, walks, outs”
3 4 3 0
9 7 3 0
11 4 2 2
9 1 1 1
3 5 2 8
and etc…….
Here is an example:
20 2 1 1
The example above indicates that during a particular game in the season, player number 20 was at bat four
times and made 2 hits, 1 walk, and 1 out.
There might be several lines in the file for a player. (a player can play more than one game in a season)
The file is organized by the batting line-ups (it is not sorted by player number).
Each player’s batting average is computed by adding the player’s total number of hits dividing by
the total number of times at bat.
A walk does not count as either a hit or a time at bat when the batting average is being calculated.
When your statistics file contains no data, print message to the output file saying, “The [2025] baseball season was cancelled” and end the execution. [2025] is stored in a variable that was read from the Roster file.
Create an array of PlayerInfo struct to hold the players’ data. The array is local to main function and passes to other functions as argument.
struct PlayerInfo
{
int PlayerID;
string LastName; //struct declared in global area (above main & function prototypes)
string FirstName;
int Hits, Walks, Outs;
double Batting, OnBase;
};
PlayerInfo Player[20]; //array declared inside main function and pass it to sub functions.
GRADING POINTS will be given based largely on the BASE requirements and the PROGRAM EXECUTION requirements.
BASE Requirements: (All Functions must Be below the main function!!!)
Don’t use the following in your program at all: no vectors, no stacks, no multi-dimensional arrays, no parallel arrays or any other C++ coding techniques not covered by the Course. Significant number of points may be taken off
No global variables allowed. Global area can only have function prototypes, named constants, and struct declaration.
(your program must follow this logic)
Functions must be called in this order inside the main function.
1. In the main function, you will call a function GetPlayer to read from Roster file and store the player names and id into the array and return the year for the season.
int GetPlayer (PlayerInfo [ ] ); // function prototype
(Be careful! The players’ identification numbers are 1 through 20, but C++ array index starts at 0).
2. Call a PrintRoster function to send the roster of the team with player ID in order to an output file
3. Call a SortPlayer function to sort players by last name. (i.e. Use Selection or Bubble Sort)
NOTE: The (index + 1) of the array is no longer the player’s ID after sorting.
4. Then call a GetStatistics function to read the statistics file, updating each player’s statistics of hits, walks and outs.
NOTE: – you need to keep the player identification numbers with the player names and the data in the struct.
When you read a player’s game line, look up the player in the array of structs before you adding up the hits, walks and outs.
Hints: use Linear (or Binary Search)Search to look up the player id, before adding hits, walks, and outs to that player.
if (ID = = Player[index].PlayerID) {
Player[index].Hits += H;
Player[index].Walks += W;
Player[index].Outs += O; }
5. A function to calculate each player’s batting average and on base average and store them into the array.
(remember to do casting in order to retain the factional part)
batting average = double (hits) / (hits + outs)
on base average = double (hits + walks) / (hits + walks + outs)
6. A function to Send the players’ statistic to the output file including their Batting Average, On Base Average, in DL list, the best hitter, the worst hitter, the best base runner (based on OBA) and the worst base runner.
Note: A player is in the DL (disabled list) if he didn’t play at all in the entire season.
Sample of an output file:
Baseball Season 2025
--------------------------------
Smith Sam Player 1
Jones Bob Player 2
Miller Miles Player 3
and etc……
Rutter Jack Player 20
Player Statistic with their total hits, total walks, total outs, batting and on base average for season 2025
Player Number Hits Walks Outs Batting Average On Base Average In Disable List
-------------------------------------------------------------------------------------------------------------------------------------------
Apbee Cory 5 5 3 5 0.50 0.62
Buzz Bee 8 3 0 0 1.00 1.00
Carter John 4 Yes
Crane David 19 3 4 4 0.43 0.64
and etc……
Give the name(s) and batting average of the best hitter (i.e. highest batting average).
Give the name(s) and on-base average of the best base runner
Give the name(s) and batting average of the worst hitter
Give the name(s) and on-base average of the worst base runner
If there is a tie for best or worst, Print all the players’ names.
Just an Example: (might not be true for your input file)
The best hitter with batting average of 0.68: Jones
The worst hitter with batting average of 0.04: Miller, Smith
2) Program Execution Requirements: Possible adjustments to grade
Points included in 200 points, fully or partially deducted if not done or done partially.
You are required to use the provided dataset named statistic.txt and roster.txt and not only your own custom dataset, - 20 pts
Attach documentation of a screenshot of program compilation and execution, your choice of dataset with date/time included, - 20 pts
Attach the output file with the results of the program - 20 pts. If you only print it to the screen you can lose up to 20 pts
If you provide any file names that have file paths (or are not just one filename), your program will be considered non-executable and you will receive a maximum of ONLY 100 points, with other possible deductions based on compilation and reviewing your code.
Points possible that can be added to 200 points (Considered extra credit, where this can help offset other points off or allow to get more than 20 points) – there is some risk to choosing these options. If you don’t try this, it is ok, but you not received extra credit points. If you try and it is not done well, you can receive minimal extra credit points or worse yet it can impact points on the other grading criteria.
Datasets Options: Encourages you to use the file naming convention or file name entry
1) Use the provided datasets and one other custom dataset, specify the file names in two different .cpp files
a. Provided dataset file names are: statisticxx1.txt, rosterxx1.txt1 and resultsxx1 for the first .cpp file, +10 pts
b. This can only be done if you choose to do a test run also with a Custom dataset file names are: statisticxx1.txt, rosterxx2.txt2 and resultsxx2 for the first .cpp file, +10 pts
OR
2) Allows the user to enter the statistics, experts and output file names. +15 pts to +25 pt. You must attach all three files after the completion of each test run (for one test for the provided dataset +15 pts and two tests if you also run it for a custom dataset. +25 pts
No need to test your program more than one test for the provided dataset and one test for the custom dataset. You will not receive additional extra credit points.