Created
December 14, 2021 04:08
-
-
Save wise-introvert/15600603be68e1bfe64ce6585f3146e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1: Import the Standard Input Output library | |
3,4,5,6: Define four macros: | |
a. MAX_JUDGES | |
b. MAX_STRING | |
c. MAX_CONTESTANTS | |
d. WINNER_CUTOFF | |
8. Declare a struct called "Score" with the following datatypes: | |
a. "judgeScore": an array of doubles with a maximum capacity of 3 | |
13. Declare a struct called "Contestant" with the following datatypes: | |
a. "name": an array of characters with a maximum capacity of 25 | |
b. "score": an instance of the struct "Score" | |
c. "average": a double | |
20. Declare a struct called "Competition" with the following datatypes: | |
a. "compName": an array of characters with a maximum capacity of 25 | |
b. "contestants": an array of instances of the struct "Contestant" with a maximum length of 10 | |
c. "numContestants": an integer | |
27. Declare a function called "avg" with the return type of "double" and which accepts a constant pointer argument of type "Contestant" | |
29. Function definition for "avg". | |
Returns the value of the following expression: | |
(c->score.judgeScore[0] + c->score.judgeScore[1] + c->score.judgeScore[2]) / 3.0; | |
Where "c" is the argument passed into the function | |
32. "main" function begins | |
34. Declare an array of instances of the type "Contestant" called "winners" with a maximum capacity of 10, and initialize it with one item with the value of 0 | |
35. Declare an instance of the type "Competition" called "national" and initialize it with the following data: | |
{ "National", { { "Jill Smith", { 8, 8, 7 } }, { "Ellen Jones", { 8.5, 5.5, 8 } }, { "Joan Bell", { 9.5, 3.5, 6 } } } } | |
45. Declare four integer variables: "i", "j", "k" and "numWinners" and initialize them with 0 | |
47. FOR LOOP | |
CONDITION: i < national.numContestants | |
0 < 3 (TRUE. Execute for loop body:) | |
49. Call "avg" with the following argument: | |
&national.contestants[i] | |
&({"Jill Smith", {8, 8, 7}}) | |
Assign result to national.contestants[i].average | |
national.contestants[0].average = 7.666666666666667 | |
50. Check if the following expression is TRUE: | |
national.contestants[0].average >= WINNER_CUTOFF | |
7.666666666666667 >= 6.5 (TRUE: Execute IF block) | |
52. FOR LOOP | |
CONDITION: j < numWinners && winners[j].average < national.contestants[i].average | |
0 < 0 && 0 < 7.666666666666667 (FALSE: Skip the loop) | |
56. FOR LOOP | |
CONDITION: k > j | |
1 > 0 (TRUE: Execute IF block) | |
60. assign value of national.contestants[i] to winners[j] | |
-> winners[0] = {"Jill Smith", {8, 8, 7}, 7.666666666666667} | |
61. Increment the value of "numWinners" by 1: numWinners = 1 | |
47. FOR LOOP | |
CONDITION: i < national.numContestants | |
1 < 3 (TRUE: Execute for loop body) | |
49. Call "avg" with the following argument: | |
&national.contestants[i] | |
&({"Ellen Jones", {8.5, 5.5, 8}}) | |
Assign result to national.contestants[i].average | |
national.contestants[1].average = 7.333333333333333 | |
50. Check if the following expression is TRUE: | |
national.contestants[1].average >= WINNER_CUTOFF | |
7.333333333333333 >= 6.5 (TRUE: Execute IF block) | |
52. FOR LOOP | |
CONDITION: j < numWinners && winners[j].average < national.contestants[i].average | |
0 < 0 && 0 < 7.333333333333333 (FALSE: Skip the loop) | |
56. FOR LOOP | |
CONDITION: k > j | |
1 > 0 (TRUE: Enter the loop) | |
57. Assign the value of winners[k - 1] to winners[k] | |
->winners[1] = {"Jill Smith", {8, 8, 7}, 7.666666666666667} | |
60. assign value of national.contestants[i] to winners[j] | |
-> {"Ellen Jones", { 8.5, 5.5, 8 }, 7.333333333333333} | |
61. Increment the value of "numWinners" by 1: numWinners = 2 | |
47. FOR LOOP | |
CONDITION: i < national.numContestants | |
2 < 3 (TRUE: Execute for loop body) | |
TRUE. Execute for loop body: | |
49. Call "avg" with the following argument: | |
&national.contestants[i] | |
&({"Joan Bell", {9.5, 3.5, 6}}) | |
Assign result to national.contestants[i].average | |
national.contestants[2].average = 6.333333333333333 | |
50. Check if the following expression is TRUE: | |
national.contestants[2].average >= WINNER_CUTOFF | |
6.333333333333333 >= 6.5 (FALSE: Skip IF block) | |
64. Call the printf function. | |
OUTPUT: "Winners of the national competition\n" | |
65. FOR LOOP | |
CONDITION: i < numWinners | |
0 < 2 (TRUE: Enter the loop) | |
67. Call the printf function | |
OUTPUT: "Ellen Jones 7.3" | |
65. FOR LOOP | |
CONDITION: i < numWinners | |
1 < 2 (TRUE: Enter the loop) | |
67. Call the printf function | |
OUTPUT: "Jill Smith 7.7" | |
70. Return 0, hand-over control to the shell. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment