C Language Student Grade Management System

Click the blue text above to follow us

Embedded Training – Find JuFeng Smart Link

1. Functionality Implementation

1. The system runs and opens the following interface. It lists the system help menu (i.e., command menu) and prompts for command input.

2. At the beginning, since no grades have been entered, inputting command L will not list any grades. It should prompt “The grade table is empty! Please use command T to enter student grades first.”

Similarly, when other grade processing commands are input, corresponding handling should also be done.

3. Input command T to call the T function to enter grades.

The interface prompts for the number of students.

Input 3, then prompt for the grades of 3 subjects for 3 students, listing the header of the grade sheet “Student ID Chinese Math English”,

Prompt for Student ID: 1

Input the grades of student 1 for 3 subjects, separated by spaces, press Enter to finish. Prompt for Student ID: 2

Input the grades of student 2 for 3 subjects, separated by spaces, press Enter to finish. Prompt for Student ID: 3

Input the grades of student 3 for 3 subjects, separated by spaces, press Enter to finish. The T function call ends and returns. Prompt for command input.

4. Input command L to call the List sub-function to output the grade table. The List sub-function call ends and returns. Prompt for command input.

5. Input command A to call the aver function to calculate the average score, prompting “The average score has been calculated. Please use command L to view.” The aver function call ends and returns. Prompt for command input.

6. Input command P to call the Sort function to sort each student’s record by average score from low to high, prompting “Sorting completed. Please use command L to view.” The Sort sub-function call ends and returns. Prompt for command input.

7. Input command S to call the search sub-function to query student grades, prompting “Input the student ID to query.”

8. Input command C to execute the clear screen function statement system(“clear”);

9. Input command H to call the menu function to display the help menu. Prompt for command input.

10. Input command Q to exit the system.

You can use exit(0);

2. Design Approach

The program is written using a file management approach, where the main function mainly contains a menu function and an input function. The menu function serves as the entry point of the program, encapsulating the input function which includes various functional functions such as entering student grades, calculating averages, etc.; a structure for “student” is defined in the header file, along with a primary pointer to that structure, managed through a makefile for multi-file management.

1. Main Function

#include <stdio.h>
#include "head.h"
int main(){
    menu();
    Input();
    return 0;
}

2. Menu Function

#include "head.h"
void menu(){
    printf("**********************************************\n");
    printf("  *        Student Grade Management System--Help Menu        *   \n");
    printf("**********************************************\n");
    printf("  *        H=Display Help Menu                    *  \n");
    printf("  *        T=Grade Entry                        *  \n");
    printf("  *        A=Calculate Student Average Score                  *  \n");
    printf("  *        L=List Grade Table                      *  \n");
    printf("  *        P=Sort by Average Score from High to Low          *  \n");
    printf("  *        S=Query Student Grades by ID              *  \n");
    printf("  *        C=Clear Screen                            *  \n");
    printf("  *        Q=Exit System                        *  \n");
    printf("**********************************************\n");
    printf("  *  Copyright <C> 2025.03.01  By  ZMH    *  \n");
    printf("**********************************************\n");
    printf("\n");
}

3. Input Function

#include "head.h"
#include <stdlib.h>
extern int n;
void Input(){
    while(1)      // Ensure functional functions can loop until the exit function is called
    {
        printf("Please enter a command:\n");
        char choose;
        scanf("%c",&choose);
        if(n==0&&choose!='T')
        {
            printf("The grade table is empty! Please use command T to enter student grades\n");
            getchar();
            continue;
        }
        switch (choose)   // Switch loop executes different commands based on input abbreviation
        {
        case 'H':
            menu();
            break;
        case 'T':
            T();
            break;
        case 'L':
            List();
            break;
        case 'A':
            aver();
            break;
        case 'P':
            sort();
            break;
        case 'S':
            search();
            break;
        case 'C':
            system("clear");
            break;
        case 'Q':
            exit(0);
            break;
        }
        getchar();   // Used to consume the Enter key or other end symbols after input
    }
}

4. Makefile Function

CC=gcc
CFLAGS= -c -g
OBJS=main.o T.o Input.o menu.o List.o aver.o sort.o search.o
main:$(OBJS)
    $(CC) $^ -o $@
%.o:%.c
    $(CC) $(CFLAGS) $<<br/> -o $@.
.PHONY:clean
clean:
    $(RM) *.o main

5. Entering Student Grades

#include "head.h"
#include <stdlib.h>
int n;
void T(){
    printf("Please enter the number of students:\n");
    scanf("%d",&n);
    s=(struct student*)malloc(sizeof(struct student)*n);
    printf("Please enter the grades for %d students in three subjects:\n",n);
    printf("Student ID    Chinese    Math    Foreign Language\n");
    for(int i=0;i<n;i++)
    {
        s[i].idcard = i+1;
        printf("%d\t",s[i].idcard);
        scanf("%f %f %f",&s[i].chinese,&s[i].math,&s[i].english);
    }
}

6. Listing Student Grades

#include <stdio.h>
#include "head.h"
extern int n;
void List(){
    printf("Student grades are as follows:\n");
    printf("Student ID    Chinese    Math    Foreign Language    Average Score\n");
    for(int i=0;i<n;i++)
    {
        printf("%d %.2f  %.2f   %.2f    %.2f\t\n",s[i].idcard,s[i].chinese,s[i].math,s[i].english,s[i].average);
    }
}

7. Calculating Average Score

#include <stdio.h>
#include "head.h"
extern int n;
void aver(){
    int sum=0;
    for(int i=0;i<n;i++)
    {
        sum=(s[i].chinese+s[i].math+s[i].english);
        s[i].average=sum/3;
        sum=0;
    }
    printf("Average score calculation completed, please use command L to view");
}

8. Sorting by Average Score

#include <stdio.h>
#include "head.h"
extern int n;
void sort(){
    struct student p;
    for(int i=0;i<n-1;i++ )
    {
        for(int j=0;j<n-1-i;j++)
        {
            if(s[j].average>s[j+1].average)
            {
               p=s[j];
               s[j]=s[j+1];
               s[j+1]=p;
            }
        }
    }
    printf("Sorting completed, please use command L to view");
}

9. Searching Student Grades by ID

#include <stdio.h>
#include "head.h"
extern int n;
void search(){
    printf("Please enter the student ID to query:");
    scanf("%d",&n);
    printf("%d       %.2f   %.2f   %.2f    %.2f\t\n",s[n-1].idcard,s[n-1].chinese,s[n-1].math,s[n-1].english,s[n-1].average);
}

10. Clear Screen Function and Exit FunctionThe clear screen function and exit function can be directly referenced using system(“clear”) and exit(0), remember to include the header file #include <stdlib.h> for declaration.

C Language Student Grade Management System

Original link: https://blog.csdn.net/m0_71284871/article/details/146322744

Leave a Comment