Advertisement
Razali

Football Club

Nov 13th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.58 KB | None | 0 0
  1. a)
  2.  
  3. typedef struct
  4. {
  5.     int clubID, dateSize;
  6.     char venue[50 + 1], nameCoach[50 + 1], namePlayers[20][50 + 1];
  7.     date_t dates[10];
  8. }club_t;
  9.  
  10.  
  11. b)
  12.  
  13. typedef struct
  14. {
  15.     date_t matchDate;
  16.     club_t homeClub, awayClub;
  17.     char venue[50 + 1];
  18. }match_t;
  19.  
  20.  
  21. c)
  22.  
  23. /*
  24.  * <summary> Determines if a club has conflicting dates with a match date </summary>
  25.  * <params>
  26.  *  "club" = The club participating in the match
  27.  *  "date" = The date of the match
  28.  * </params>
  29.  * <return>  "1": Has conflict - "0": No conflict </return>
  30.  */
  31. int conflict(club_t club, date_t date)
  32. {
  33.     int i;
  34.    
  35.     for(i = 0; i < club.dateSize; i++)
  36.         if((club.dates[i].day == date.day) && (club.dates[i].month == date.month) && (club.dates[i].year == date.year))
  37.             return 1;
  38.    
  39.     return 0;
  40. }
  41.  
  42. d)
  43.  
  44. /*
  45.  * <summary> Determines the number of home games a club can play without conflicts </summary>
  46.  * <params>
  47.  *      "tournament" = Contains the details of matches
  48.  *      "numMatches" = Contains the number of matches in the tournament
  49.  *      "club" = The club in the tourney
  50.  * </params>
  51.  * <return> The number of homegames </return>
  52.  * <precond> "numMatches" > 0 </precond>
  53.  */
  54. int numHomeGames(match_t tournament[],int numMatches, club_t club)
  55. {
  56.     /*
  57.         Matches to play AT HOME GROUND.
  58.         Plays with every opponent once on homeground if possible.
  59.     */
  60.     int i, matchesToPlay = 0;
  61.    
  62.     /*
  63.      *If it is the clubs match
  64.      * Check for no conflicts
  65.      */
  66.     for(i = 0; i < numMatches; i++)
  67.         if(tournament[i].homeClub.clubID == club.clubID)
  68.             if(!conflict(club, tournament[i].matchDate))
  69.                 matchesToPlay++;
  70.     return numHomeGames;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement