大一上学期写的学生成绩管理系统

简介: 大一上学期写的学生成绩管理系统

今天在电脑上偶然看到自己大一上学期写的学生管理系统,当时写是因为C与看课本的课后习题有这个,老师没有让写,我当时为了挑战一下自己,就开始搞,前前后后修改了很多次,最后终于完成了。嘿嘿,特地来分享一下。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 30
#define MAX 150
void InputRecord(int num[], char name[][MAX], int score[], int n);
int CaculateTotal(int score[], int n);
float CaculateAverage(int n, int sum);
void DescendingSort(int num[], char name[][MAX], int score[], int n);
void AscendingSort(int num[], char name[][MAX], int score[], int n);
void AscendingNumSort(int num[], char name[][MAX], int score[], int n);
void AscendingNameSort(int num[], char name[][MAX], int score[], int n);
void LinNumSearch(int num[], char name[][MAX], int score[], int n);
void LinNameSearch(int num[], char name[][MAX], int score[], int n);
void StatisticAnalysis(int score[], int n);
void ListRecord(int num[], char name[][MAX], int score[], int n, int sum, int aver);
void Swap(int *x, int *y);
int main()
{
    int num[N], n, op, score[N], sum;
    char name[N][MAX];
    float aver;
    printf("How many students:\n");
    scanf("%d", &n);
    printf("1.Input record\n2.Caculate total and average score of course\n3.Sort in descending order by score\n4.Sort in ascending order by score\n5.Sort in ascending order by number\n6.Sort in dictionary order by name\n7.Search by number\n8.Search by name\n9.Statistic analysis\n10.List record\n0.Exit\nPlease enter your choice\n");
    do
    {
        printf("Input option:\n");
        scanf("%d", &op);
        switch (op)
        {
        case 1:
            InputRecord(num, name, score, n);
            break;
        case 2:
            aver = CaculateAverage(n, CaculateTotal(score, n));
            break;
        case 3:
            DescendingSort(num, name, score, n);
            break;
        case 4:
            AscendingSort(num, name, score, n);
            break;
        case 5:
            AscendingNumSort(num, name, score, n);
            break;
        case 6:
            AscendingNameSort(num, name, score, n);
            break;
        case 7:
            LinNumSearch(num, name, score, n);
            break;
        case 8:
            LinNameSearch(num, name, score, n);
            break;
        case 9:
            StatisticAnalysis(score, n);
            break;
        case 10:
            sum = CaculateTotal(score, n);
            aver = CaculateAverage(n, sum);
            ListRecord(num, name, score, n, sum, aver);
            break;
        case 0:
            exit(0);
        }
    } while (op >= 0);
    return 0;
}
void InputRecord(int num[], char name[][MAX], int score[], int n)
{
    int i;
    for (i = 0; i < n; i++)
    {
        scanf("%d%s%d", &num[i], &name[i], &score[i]);
    }
}
int CaculateTotal(int score[], int n)
{
    int i;
    int total = 0;
    for (i = 0; i < n; i++)
    {
        total += score[i];
    }
    return total;
}
float CaculateAverage(int n, int sum)
{
    return (float)sum / n;
}
void DescendingSort(int num[], char name[][MAX], int score[], int n)
{
    int i, j;
    char temp[MAX];
    for (i = 0; i < n - 1; i++)
    {
        for (j = 1; j < n; j++)
        {
            if (score[j] > score[i])
            {
                Swap(&score[j], &score[i]);
                Swap(&num[j], &num[i]);
                strcpy(temp, name[i]);
                strcpy(name[i], name[j]);
                strcpy(name[j], temp);
            }
        }
    }
    for (i = 0; i < n; i++)
    {
        printf("num:%d name:%s score:%d\n", num[i], name[i], score[i]);
    }
}
void Swap(int *x, int *y)
{
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}
void AscendingSort(int num[], char name[][MAX], int score[], int n)
{
    int i, j;
    char temp[MAX];
    for (i = 0; i < n - 1; i++)
    {
        for (j = 1; j < n; j++)
        {
            if (score[j] < score[i])
            {
                Swap(&score[j], &score[i]);
                Swap(&num[j], &num[i]);
                strcpy(temp, name[i]);
                strcpy(name[i], name[j]);
                strcpy(name[j], temp);
            }
        }
    }
    for (i = 0; i < n; i++)
    {
        printf("num:%d name:%s score:%d\n", num[i], name[i], score[i]);
    }
}
void AscendingNumSort(int num[], char name[][MAX], int score[], int n)
{
    int i, j;
    char temp[MAX];
    for (i = 0; i < n - 1; i++)
    {
        for (j = 1; j < n; j++)
        {
            if (num[j] < num[i])
            {
                Swap(&score[j], &score[i]);
                Swap(&num[j], &num[i]);
                strcpy(temp, name[i]);
                strcpy(name[i], name[j]);
                strcpy(name[j], temp);
            }
        }
    }
    for (i = 0; i < n; i++)
    {
        printf("num:%d name:%s score:%d\n", num[i], name[i], score[i]);
    }
}
void AscendingNameSort(int num[], char name[][MAX], int score[], int n)
{
    int i, j;
    char temp[MAX];
    for (i = 0; i < n - 1; i++)
    {
        for (j = 1; j < n; j++)
        {
            if ((strcmp(name[j], name[i])) < 0)
            {
                Swap(&score[j], &score[i]);
                Swap(&num[j], &num[i]);
                strcpy(temp, name[i]);
                strcpy(name[i], name[j]);
                strcpy(name[j], temp);
            }
        }
    }
    for (i = 0; i < n; i++)
    {
        printf("num:%d name:%s score:%d\n", num[i], name[i], score[i]);
    }
}
void LinNameSearch(int num[], char name[][MAX], int score[], int n)
{
    int i;
    char na[MAX];
    printf("Input the searching name:");
    scanf("%s", na);
    for (i = 0; i < n; i++)
    {
        if ((strcmp(name[i], na)) == 0)
            printf("no=%d\tscore=%d\n", i + 1, score[i]);
    }
}
void LinNumSearch(int num[], char name[][MAX], int score[], int n)
{
    int x, i;
    printf("Input the searching ID:");
    scanf("%d", &x);
    for (i = 0; i < n; i++)
    {
        if (num[i] == x)
        {
            printf("no:%d\tscore=%d\n", i + 1, score[i]);
        }
    }
}
void StatisticAnalysis(int score[], int n)
{
    int i, A = 0, B = 0, C = 0, D = 0, E = 0;
    for (i = 0; i < n; i++)
    {
        if (score[i] >= 0 && score[i] <= 59)
        {
            A++;
        }
        else if (score[i] >= 60 && score[i] <= 69)
        {
            B++;
        }
        else if (score[i] >= 70 && score[i] <= 79)
        {
            C++;
        }
        else if (score[i] >= 80 && score[i] <= 89)
        {
            D++;
        }
        else if (score[i] >= 90 && score[i] <= 100)
        {
            E++;
        }
    }
    printf("90~100:%d\trate:%f %\n", E, (float)E / n * 100.0);
    printf("80~89:%d\trate:%f %\n", D, (float)D / n * 100.0);
    printf("70~79:%d\trate:%f %\n", C, (float)C / n * 100.0);
    printf("60~69:%d\trate:%f %\n", B, (float)B / n * 100.0);
    printf("0~59:%d\trate:%f %\n", A, (float)A / n * 100.0);
}
void ListRecord(int num[], char name[][MAX], int score[], int n, int sum, int aver)
{
    int i;
    for (i = 0; i < n; i++)
    {
        printf("num=%d\tname=%s\tscore=%d\n", num[i], name[i], score[i]);
    }
    printf("sum=%d\taverage=%d\n", sum, aver);
}
相关文章
|
7月前
|
Java 关系型数据库 MySQL
毕业设计|课程设计|SSM开发实现图书管理系统(一)
毕业设计|课程设计|SSM开发实现图书管理系统
|
7月前
|
JavaScript 小程序 Java
基于SSM大学生宿舍管理系统的设计与实现
基于SSM大学生宿舍管理系统的设计与实现
75 1
|
SQL 数据管理 Java
C#宿舍管理系统(C#课程设计含源码)
C#宿舍管理系统(C#课程设计含源码)
161 0
C#宿舍管理系统(C#课程设计含源码)
|
存储 Java 关系型数据库
JavaWeb期末项目 图书馆管理系统
JavaWeb期末项目 图书馆管理系统
174 1
|
7月前
|
前端开发 JavaScript Java
毕业设计|课程设计|SSM开发实现图书管理系统
毕业设计|课程设计|SSM开发实现图书管理系统
106 1
|
7月前
|
人工智能 前端开发 JavaScript
毕业设计|课程设计|SSM开发实现图书管理系统(二)
毕业设计|课程设计|SSM开发实现图书管理系统
|
Java 程序员 PHP
C#简单学生信息管理系统(C#课程设计)
C#简单学生信息管理系统(C#课程设计)
82 0
|
SQL 网络协议 Java
学校信息管理系统说明文档
建好一个数据库 命名为mysims
|
编译器 C++
【期末课程设计】学生成绩管理系统
【期末课程设计】学生成绩管理系统