












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A c program that allows users to enter student ids and grades, and then provides various functionalities such as displaying all student information, finding the student with the highest and lowest grades, and rating students as fail, pass, or merit based on their grades. The program utilizes arrays to store the student ids and grades, and implements several functions to handle the different operations. Detailed explanations of the program's structure, including the use of loops, conditional statements, and function calls. It also provides test cases to demonstrate the program's functionality under ideal conditions.
Typology: Assignments
1 / 20
This page cannot be seen from the preview
Don't miss anything!













Qualification BTEC Level 5 HND Diploma in Computing Unit number and title PROG102: Procedural Programming Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Mai Le Thanh Hoang Student ID GCD19 1206 Class GCD 1101 Assessor name Pham Thanh Son Student declaration I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that making a false declaration is a form of malpractice. Student’s signature Hoang Grading grid P4 P5 M3 M4 D
Grade: Assessor Signature: Date: Lecturer Signature:
#include <stdio.h> int main() { int MAX = 50 ; // Maximum quantity int studentID[MAX]; float grades[MAX]; int a, n , u = 0 , p = 0 ; // a is the select of user in MENU float max, min; printf("Enter number of student:"); do { scanf("%d", &n); if(n == 0 || n > MAX) { printf("\nRe-enter the number of students: "); } } while(n == 0 || n > MAX); printf("\nEnter ID of student:\n"); for (int i = 0 ; i < n; i++) { printf("Student ID %d: ", i + 1 ); scanf("%d", &studentID[i]); } printf("\nEnter grades of student:\n"); I. Write a program that implements the designed solution (P4): In Assignment 1, I created the algorithm and flowchart for a software that enters student codes and grades into a class. Then determine which student has the highest and lowest score. The program will be built and presented in further depth in this Assignment 2 by creating and implementing software in the C programming language. Code for the program requested by teacher:
for (int i = 0 ; i < n; i++) { printf("Grades of student %d: ", studentID[i] ); scanf(" %f", &grades[i]); } char c = 'y'; while (c == 'y'|| c == 'Y') { printf("\n===================FUNCTION=====================\n"); printf("\n== 1. Show all student IDs and grades =="); printf("\n== 2. Find Student IDs has highest grades =="); printf("\n== 3. Find Student IDs has lowest grades =="); printf("\n== 4. Rating all student =="); printf("\n== 5. Exit! =="); printf("\n Select an activity you want: "); printf("\n================================================\n"); scanf("%d", &a); if (a == 1 ) for (int i = 0 ; i < n; i++) // use for loops to print all ID and grades of student { printf("\nStudent with ID %d: %.2f Point", studentID[i], grades[i]); } if (a == 2 ) { max = grades[ 0 ]; for (int i = 1 ; i < n; i++) { if ( grades[i] > max) { max = grades[i]; u = i; } } printf("\nStudent ID %d gets %.2f, Student has highest grades!", studentID[u], max);
1. Declare variables: Figure 1: Declare variables Float max, min: variable to find the highest and lowest score using float data type. Initialize the student ID and grades variable with an array equal to the Max value as declared before so that the program can import and save information about the student's ID and grades. 2. Do – While loop: Figure 2: Do - While loop (used to count the number of students) 3. For loops: } return 0 ; }
Figure 3: For loops (used to enter the number of IDs equal to the number of n students initially entered) For example, initially enter n students as 10 (n is the number of students), then when entering ID the program will run from the first value to the last value with a for loop Figure 4: For loop (used to enter the number of Grades equal to the number of n students initially entered) Similar to the above, initially enter n students as 10 (n is the number of students), then when entering the grade, the program will run from the first value to the last value by a for loop
4. Menu Functions: Figure 5: Menu Functions
8. Function to show information of student and evaluate students: Figure 9: Function 4 (Display information of student and evaluate students) The above code allows the program to give a student's rating based on the score when the user enters it with 3 types of evaluation: Merit if grades >= 8 and Student Pass if grades > 5 , and if grades <= 5 then the student will be assessed as Fail. 9. Program exit function: Figure 10: Function 5 (Exit program) If Y is selected and the program continues, select function 5 to exit the program. If you want to end the day program immediately without using function 5, then when the system asks "Do you want to continue or stop the program", we choose N to end the program. **II. Test the program with proper test plan (P5):
In this program, MAX is the number of students in a class. If the class has 50 students then the value of MAX = 50 and the teacher can enter student IDs and grades of 30 students in one run of the program. In this case I only entered 5 out of 50 students in a class. Figure 11: Enter number of student Enter the number of students you want to enter: 5 students. Figure 12: Enter five Student IDs and Grades Enter the IDs and grades of 5 students: IDs:
Figure 15: Result of Function 1 After executing function 1, enter Y to continue other functions and enter N to end the program. Figure 16: Enter Y and choose function 2 After entering Y, the program will display Menu Functions again and I choose function 2 (function to find the student with the highest grade)
Figure 17: Result of function 2 (Finding the student has highest grade) After selecting function number 2, the system will display the student with the highest score (displayed information includes Student ID and score achieved) Figure 18: Result of function 3 (Finding the student has lowest grade) Enter Y, the program displays Menu Function again and select function number 3 (function to find the student with the lowest score).
Figure 20: Result of function 5 (End the program) To exit the program, we can enter N after completing function 4 or enter Y to continue executing function 5 (function to exit the program).
2. Test case: Test data Expected Result Actual Result Pass/Fail 1 - Enter number of - Enter number of student: 2 student: 2
2 - Enter number of student: 3
4 - Enter number of student: 3
5 - Enter number of student: 2
•Student ID 2: