This is a continuation of program #1. This program demonstrates the use of arrays, functions, and parameters.
In this program, you will read the team data into an array, print the contents of the array before processing game data, read and process game data, and print the contents of the array after that processing. Copy your p1abc123.c to p2abc123.c so that you can modify it.
Command:
p2 -t teamFileName -g gameFileName
Input:
Team Data (same format as in program #1):
Stream input file which contains many teams. There are two different kinds of lines of data for each team:
- Team Identification Information:
o One line per team (separated by spaces)
szTeamId iWins iLosses dFeeAmount dPaidAmount
6s d d lf lf
- Team Contact Information:
o One line per team (separated by commas)
szTeamNm szEmail szPhone szContactName
12s 30s 13s 20s
o Although szTeamNm is a maximum of 12 characters, it may contain spaces; therefore, you cannot simply use %12s. For szFullName, you will have to use a bracket format code using %12[^,]. The next two values are also terminated by commas.
o For szContactName, it contains spaces and is terminated by a new line character. You will have to use a bracket format code using %20[^n]
Game Data:
Stream input file which contains many games:
o Only one type of data record (separated by spaces):
szTeamId1 szTeamId2 iScore1 iScore2
6s 6s d d
Provided files:
cs1713p2_h.txt include file for this program; rename this to cs1713p2.h
p2Team.txt input file containing team information
p2Game.txt input file containing game information
cs1713p2Provided.txt code for printTeams which you must copy into your new p2abc123.c file.
Process (see the details of the code changes later in this document):
1. Read the team information into an array using a modified getTeams function which is passed an array of teams and returns the count of the
2. Print the current team information before processing any games using the new printTeams function.
3. Print a heading showing Team 1, Team 2, Score 1, and Score 2.
4. Invoke a new processGameFile function which is passed the array of teams and the count of teams. Process the games data by reading the p2Game.txt file until EOF. For each game
5. Print the team array after all of the games have been processed using the printTeams function. You should notice changes in the number of losses and the number of wins.
processGame function:
Error Processing:
Modifications of Program#1:
1. Above the main function:
2. Modify the main function as necessary:
3. processCommandSwitches needs to be modified to return multiple filenames (one for the team file and one for the game file). (See the prototype declaration above.)
4. Modify getTeams to receive the array of teams and return the number of teams.
Parameters:
O Team teamM[] array of teams
Returns:
Count of the number of teams
teamM[i] = team; // You also need to declare i at the beginning of this function
5. Add a new function processGameFile which is passed an array of teams and team count as parameters. It should read data from the game file until EOF. For each game read, it should invoke processGame passing the game, array of teams, and team count. Its prototype is void processGameFile(Team teamM[], int iTeamCnt)
6. Add a new function processGame which processes a game as described above. It is passed a game, the array of teams, and the team count. Its prototype is void processGame(Game game, Team teamM[], int iTeamCnt)
7. Add a new function findTeam which finds the specified Team Id in the teamM array and returns its subscript. If not found, it should return -1. int findTeam(Team teamM[], int iTeamCount, char szTeamId[])
8. exitUsage should show what switches it now needs.
9. Copy the text from cs1713p2Provided.txt into your p2abc123.c file. See how to do that below.
Sample Output (Partial):
Original Team Information
Id Team Name Wins Loss Fee Amt Paid Amt
Contact Name Phone Email
UTSA01 Armadillos 8 0 150.00 80.00
Jean E Us (210)555-1111 utsa@xyz.com
COM001 Comm Eagles 7 1 150.00 75.00
Mae King (210)555-2222 maeking@xyz.com
SOUTH1 Slam Dunk 5 3 120.00 75.00
Jerry Tall (210)555-3333 slamdunk@gmail.com
ALHGHT Cake Eaters 4 4 175.00 100.00
E Z Street (210)555-6666 sliverspoon@xyz.com
UNKN01 Org New Blk 1 7 150.00 50.00
Bob Wire (210)555-1234 bobwire@xyz.com
NEWB01 River Rats 0 8 120.00 75.00
Rock D Boat (210)555-4444 riverrat@xyz.com
UNKN02 Hackers 3 5 150.00 75.00
Tom E Gunn (210)555-5555 cyber@gmail.com
Processing Games
UTSA01 NEWB01 55 12
COMM01 SOUTH1 17 15 *** team (COMM01) not found
SOUTH1 ALHGHT 66 3
UTSA01 SOUTH1 44 45