A. The Functions of My Program: 1. Library
A. The Functions of My Program: 1. Library
❖ Function 1: User can enter student’s information into the program: IDs & grades
❖ Function 2: User can see all the information that was previously entered.
❖ Function 3: User can find students who has the highest grades with their IDs.
❖ Function 4: User can find students who has the lowest grades with their IDs.
❖ Function 5: Exit the program.
b) Explanation
❖ Declare “int i = 0;” and “int j = 0;”
❖ Initialize the “do ... while ( )” loop with the condition i < n
❖ Initialize the “for (j = 0; j <i; j ++)” loop and use the loop “while” for the condition
(IDs [i] = = IDs [j]) to check for duplicate IDs and the program will display the text
“ERROR: WRONG FORMAT. PLEASE ENTER AGAIN!” with the request to
re-enter if the user enters it incorrectly.
2
❖ Initialize the “do…while( )” loop with condition: (grades[i]<0 || grades[i]>10),
❖ Use “if ” with (grades[i]<0 || grades[i]>10) to check if the user enters grades “< 0”
and “> 10” and the program displays the text "ERROR:WRONG FORMAT.
PLEASE ENTER AGAIN!" with the request to re-enter.
b) Explanation
❖ Declare “int i = 0;”
❖ Initialize the “do ... while ( )” loop with the condition i < n and the program will
display the IDs and grades previously entered.
3
3. Function 3: Find student who has highest grade
a) Source Code
b) Explanation
❖ Declare “int i, j = 0;”
“int maxID;”
“float max;”
❖ Initialize the “for (i = 0; i<n; i ++)” loop and use “if ”with the condition (max <=
grades[i]) then “max = grades[j];” and “j = i;” to find student who has highest grade.
❖ Additional condition “maxID = IDs[j];” for the program to show IDs and student
grade have the highest.
4
4. Function 4: Find student who has lowest grade
a) Source Code
b) Explanation
❖ Declare “int i, j = 0;”
“int maxID;”
“float max;”
❖ Initialize the “for (i = 0; i<n; i ++)” loop and use “if ”with the condition (min >=
grades[i]) then “min = grades[j];” and “j = i;” to find student who has highest grade.
❖ Additional condition “minID = IDs[j];” for the program to show IDs and student
grade have the lowest
5
5. Main function
a) Source code
6
7
b) Explanation
❖ Declare “int main()”
“int option;”
“bool run1 = false;”
❖ Initialize the “do ... while ( )” loop with the condition “option !=0”
❖ Enter the options display on the program.
❖ Use “switch…case ”:
• "case 1": Initialize the “do…while()” loop with condition “(n<10 || n>30)”
and use “if ” with “(n<10 || n>30)” to check if the user enters wrong
condition and the program displays the text "ERROR:WRONG FORMAT.
PLEASE ENTER AGAIN!" with the request to re-enter. Next, run function
“input( IDs, grades, n);” and “run1 = true;”.
• “case 2”: Use “if-else” with “(run1 = = true)” to check if the user selects
option 2 without entering the previous data and the program displays the text
“PLEASE CHOOSE OPTION 1 AND ENTER DATA BEFORE !” with
the request to re-enter. Next, run function “display( IDs, grades, n);”
• “case 3”: Use “if-else” with “(run1 = = true)” to check if the user selects
option 3 without entering the previous data and the program displays the text
“PLEASE CHOOSE OPTION 1 AND ENTER DATA BEFORE !” with
the request to re-enter. Next, run function “maxGrade( IDs, grades, n);”
• “case 4”: Use “if-else” with “(run1 = = true)” to check if the user selects
option 4 without entering the previous data and the program displays the text
“PLEASE CHOOSE OPTION 1 AND ENTER DATA BEFORE !” with
the request to re-enter. Next, run function “minGrade( IDs, grades, n);”
• “case 5”: If the user selects option 5, the program will display the text
“EXITING PROGRAM ...”
• “case 6”: If the user selects an option that is not in the "Menu Option" then
the program will display the text “YOU HAVE ENTERED INVALID
VALUE, PLEASE ENTER AGAIN !”