Assignment #3 – Commands, Sorted Array, Binary Search, Separate C file(40 pts) Solution

$30.00

Description

This assignment is similar to #2 except

  • You must sort the Team Array. Print it before sorting, after sorting, and after all of the teams have been processed.
  • You must use a binary search to find a team id.
  • Instead of an game file, we will have a command file.
  • You will be provided with a driver program (cs1713p3Driver.c) (see below)
  • Your code must be created in a separate C file (p3abc123.c). I provided a file named p3abc123.c. Rename it using your abc123 ID. (see below)
  • There is a new include file, cs1713p3.h
  • The output is different due to the driver printing the commands as they are encountered. Please see the sample output.

Input:

Team same as Programming Assignment #2 although there may be different data.

Command This is different from the previous assignment. The file contains text in the form of commands:

GAME RESULT szTeamId1 szTeamId2 iScore1 iScore2

This should use processGame to process this

GAME FIX szTeamId1 szTeamId2 iOldScoreTeam1 iOldScoreTeam2 iNewScore1 iNewScore2

if the winner changes:

– decrement the old winner’s iWin the old loser’s iLoss

– increment the new winner’s iWin the new loser’s iLoss

Otherwise, don’t change the wins and losses.

This functionality should be placed in the processGameFix function.

If a team doesn’t exist, show a warning.

TEAM PAID szTeamId dAmount

Add the amount to this team’s dPaidAmount. If the team doesn’t exist,

show a warning.

TEAM SHOW szTeamId

Show all the team information for this one team. If the team doesn’t exist,

show a warning.

Larry provided:

cs1713p3_h.txt – include file for program #3; please rename it to cs1713p3.h

cs1713p3Driver_c.txt – driver C file which will invoke some of your functions; please rename to cs1713p3Driver.c

p3abc123_c.txt – skeletal code which you must modify; please rename to p3abc123.c using your abc123 ID.

p3Command.txt – command input file

p3Team.txt – team data input file

Driver program (cs1713p3Driver.c):

You will be provided with a driver program, cs1713p3Driver.c, which

  1. invokes the driver’s processCommandSwitches
  2. invokes your getTeams (in p3abc123.c) to read the original team information.
  3. invokes printTeams (in p3abc123.c) to print the original team information
  4. invokes your sortTeams (in p3abc123.c) to sort the original team information
  5. invokes printTeams to print the sorted team information
  6. invokes a driver-provided processCommands which
    • reads input lines from the command file until eof:
      • prints the input line
      • determines command and subcommand
      • invokes either
        • your processGameCommand to process a GAME subcommand (you should be able to reuse some of your program 2 code, although you must change it) Note that your sscanf will use pzRemainingInput instead of szInputBuffer.
        • your processTeamCommand to process a TEAM subcommand. Note that your sscanf will use pzRemainingInput.
  1. invokes printTeams to print the resulting team information

Your p3abc123.c code:

  • You have been furnished with skeletal code p3abc123.c (rename it from p3abc123_c.txt). Your code will be in the file p3abc123.c. You must not place it in the cs1713p3Driver.c file.
  • p3abc123.c already has code for many useful functions including printTeams.
  • It does the following includes:

#include <stdio.h>

#include <string.h>

#include “cs1713p3.h”

  • It must not include cs1713p3Driver.c within your p3abc123.c file. Look at the notes below on compiling. The “link” step is where the functions you call in the driver and the functions the driver calls in your code get resolved.
  • You must create/complete the following routines (see the include file):
    • getTeams- reads and returns the teams and returns a count of teams (most of this is in program #2)
    • sortTeams – sorts the team information using a bubble sort (see your course notes)
    • searchTeams – find a team ID in the sorted team array using a binary search algorithm. You will use this in your routines.
    • processTeamCommand – processes the various TEAM commands
    • processGameCommand – processes the various GAME commands (most of this is in program #2; however, use pszRemainingInput instead of szInputBuffer). Skeletal code is provided.
    • processGame – processes a game using mostly your code from program #2. You must change it to invoke searchteams.
    • processGameFix – processes a GAME FIX command.

Please review the cs1713p3.h include file.

Compiling

  • (Before doing these steps, make a copy of your code called p3Saved.c in case you incorrectly type them and wipe out your .c file.)
  • Compile the driver using

gcc -g -c -o cs1713p3Driver.o cs1713p3Driver.c

(you can do this instead: gcc -g -c cs1713p3Driver.c

causing it to automatically create the cs1713p3Driver.o)

  • Compile your code using

gcc -g -c -o p3abc123.o p3abc123.c

(you can do this instead: gcc -g -c p3abc123.c

causing it to automatically create the p3abc123.o)

  • Link them together using:

gcc -g -o p3 cs1713p3Driver.o p3abc123.o

  • You only have to compile code that changes. Since the driver shouldn’t change, you only have to compile it once.

Executing the p3 executable:

./p3 -c p3Command.txt -t p3Team.txt

Turn in:

Your C code (p3abc123.c)

Your output based on the data provided.

Sample Output (partial):

Initial Teams

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

Sorted Teams

Id Team Name Wins Loss Fee Amt Paid Amt

Contact Name Phone Email

ALHGHT Cake Eaters 4 4 175.00 100.00

E Z Street (210)555-6666 sliverspoon@xyz.com

COM001 Comm Eagles 7 1 150.00 75.00

Mae King (210)555-2222 maeking@xyz.com

NEWB01 River Rats 0 8 120.00 75.00

Rock D Boat (210)555-4444 riverrat@xyz.com

SOUTH1 Slam Dunk 5 3 120.00 75.00

Jerry Tall (210)555-3333 slamdunk@gmail.com

UNKN01 Org New Blk 1 7 150.00 50.00

Bob Wire (210)555-1234 bobwire@xyz.com

UNKN02 Hackers 3 5 150.00 75.00

Tom E Gunn (210)555-5555 cyber@gmail.com

UTSA01 Armadillos 8 0 150.00 80.00

Jean E Us (210)555-1111 utsa@xyz.com

GAME RESULT UTSA01 NEWB01 55 12

GAME RESULT COMM01 SOUTH1 17 15

*** team (COMM01) not found

GAME RESULT SOUTH1 ALHGHT 66 3

GAME RESULT UTSA01 SOUTH1 44 45

GAME RESULT UNKN01 UNKN02 33 39

GAME RESULT COM001 UNKN02 43 37

GAME RESULT ALHGHT UNKN02 20 20

*** game was a tie

GAME RESULT NEWB01 NEWB01 30 20

*** same team

TEAM SHOW UTSA01

UTSA01 Armadillos 9 1 150.00 80.00

Jean E Us (210)555-1111 utsa@xyz.com

TEAM PAID UTSA01 50.00

TEAM SHOW UTSA01

UTSA01 Armadillos 9 1 150.00 130.00

Jean E Us (210)555-1111 utsa@xyz.com

TEAM SHOW UNKN01

UNKN01 Org New Blk 1 8 150.00 50.00

Bob Wire (210)555-1234 bobwire@xyz.com

TEAM PAID UNKN01 30.00

TEAM PAID UNKN01 30.00

TEAM SHOW UNKN01

UNKN01 Org New Blk 1 8 150.00 110.00

Bob Wire (210)555-1234 bobwire@xyz.com

TEAM PAID YYYY01 50.00

*** team (YYYY01) not found

TEAM SHOW YYYY01

*** team (YYYY01) not found

TEAM SHOW NEWB01

NEWB01 River Rats 0 9 120.00 75.00

Rock D Boat (210)555-4444 riverrat@xyz.com

GAME FIX UTSA01 NEWB01 55 12 55 2

TEAM SHOW UTSA01

UTSA01 Armadillos 9 1 150.00 130.00

Jean E Us (210)555-1111 utsa@xyz.com

TEAM SHOW NEWB01

NEWB01 River Rats 0 9 120.00 75.00

Rock D Boat (210)555-4444 riverrat@xyz.com