0% found this document useful (0 votes)
43 views8 pages

A. The Functions of My Program: 1. Library

The program allows users to (1) enter student IDs and grades, (2) view entered data, (3) find the highest grade and corresponding ID, (4) find the lowest grade and ID. It uses arrays to store IDs and grades for up to 30 students, and loops through the arrays to find max/min grades. User input is validated to ensure valid IDs, grades between 0-10, and data is entered before other functions are selected. The program exits when the user selects option 5 from the main menu.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views8 pages

A. The Functions of My Program: 1. Library

The program allows users to (1) enter student IDs and grades, (2) view entered data, (3) find the highest grade and corresponding ID, (4) find the lowest grade and ID. It uses arrays to store IDs and grades for up to 30 students, and loops through the arrays to find max/min grades. User input is validated to ensure valid IDs, grades between 0-10, and data is entered before other functions are selected. The program exits when the user selects option 5 from the main menu.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

A.

The functions of my program


My program includes 5 main functions:

❖ 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. The library, data types and variables required in my program


1. Library
❖ stdio.h: This is standard input/output header file in which Input/Output functions are
declared.
❖ string.h: All string related functions are defined in this header file.
❖ stdbool.h: This header file contains four macros for a boolean data type.
❖ stdlib.h: This header file contains general functions used in program.

2. The data types and variables


❖ Show student IDs: int IDs[30];
❖ Present student’s grades: float grades[30];
1
❖ Declare number of students: int n;
❖ Declare highest grade: float max;
❖ Declare lowest grade: float min;
❖ Show student ID who highest grade: int maxID;
❖ Show student ID who lowest grade: int minID;
❖ Reports option that user choose: int option;
❖ Used in loop function and be numeral number in array function: int i, j;

C. Source code in the functions


1. Function 1: Input student’s IDs and grades
a) Source Code

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.

2. Function 2: View student’s IDs and grades


a) Source Code

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 !”

You might also like