学生成绩管理系统

设计一个学生成绩管理系统,实现对学生成绩的动态管理,实现对学生成绩的输入,显示,删除,查找,插入,最佳,保存,计算,排序等主要功能。
(2)功能要求
1、每一条记录包括一个学生的学号、姓名、3门课成绩、平均成绩。
2、输入功能:可以一次完成若干条记录的输入。
3、显示功能:完成全部学生记录的显示。
4、查找功能:完成按姓名查找学生记录,并显示。
5、排序功能:按学生平均成绩进行排序。
6、插入功能:按平均成绩高低插入一条学生记录
7、删除功能:如果输入错误,可以删除学生记录;
8、退出。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE_NAME 10
#define SIZE_ID 20

typedef struct //信息结构体
{
    char name[SIZE_NAME];/*姓名*/
    char id[SIZE_ID];/*学号*/
     int ava;/*平均成绩*/
    int m, n, c;
}Info;

typedef struct node
{
    Info people;
    struct node *next;
}linkList;//结合列表

int Record = 0;
int menu();/*界面*/
int create(linkList *head);/*创造*/
int display(linkList *head);/*显示*/
int search(linkList *head, char *info);/*查询*/
int add2(linkList *head, char *pid);/*添加*/
int delt(linkList *head, char *info);/*删除*/
int compare(int ava1, int ava2);/*比较*/
int sort(linkList *head, int boolean);/*排序*/ //1升序 0降序

int main()
{
    linkList head, *p;
    char info[SIZE_ID];
    int temp, chus, i;
    head.next = NULL;

    while (1)
    {
        switch (menu())
        {
        case 1:
            create(&head);
            break;
        case 2:
            display(&head);
            break;
        case 3:
            printf("请输入需要查询的学号或姓名: ");
            scanf("%s", info);
            p = &head;
            p = p->next;
            for (i = 0; i < search(&head, info); i++) {
                p = p->next;
            }
            printf("搜索到:\n");
            printf("\t\t\t\t学生信息\n");
            printf("--------------------------------------------------------------------------------\n");
            printf("\t\t学号\t\t姓名\t\t\t平均成绩\n");
            printf("--------------------------------------------------------------------------------\n");
            printf("%20s\t", p->people.id);
            printf("%10s\t", p->people.name);
            printf("%20d\n", p->people.ava);
            break;
        case 4:
            printf("请输入需要添加的学号: ");
            scanf("%s", info);
            add2(&head, info);
            break;
        case 5:
            printf("请输入需要删除的学号或姓名: ");
            scanf("%s", info);
            delt(&head, info);
            break;
        case 6:
            printf("请输入1或0:\n\t1:升序\n\t0:降序\n");
            scanf("%d", &temp);
            sort(&head, temp);
            break;
        case 7:
            exit(0);
            break;
        default:
            printf("输错了,再来一次\n");
        }
        system("pause");
        system("cls");
    }
    system("pause");
    return 0;
}

int menu()
{
    int chus;/*选择*/
    printf("\t学生信息\n\n");
    printf("请输入(1 -- 8):\n");
    printf("\t1.创建学生信息\n");
    printf("\t2.显示学生信息\n");
    printf("\t3.查询学生信息\n");
    printf("\t4.添加学生信息\n");
    printf("\t5.删除学生信息\n");
    printf("\t6.排序学生成绩\n");
    printf("\t7.退出\n");
    scanf("%d", &chus);
    return chus;
}

int create(linkList *head)
{
    linkList *s, *p;
    p = head;
    printf("请输入学号 姓名 三科成绩,输入end结束\n");
    while (1)
    {
        s = (linkList*)malloc(sizeof(linkList));
        scanf("%s", s->people.id);
        if (!strcmp(s->people.id, "end"))
        {
            return 0;
        }
        scanf("%s", s->people.name);
        scanf("%d", &s->people.m);
        scanf("%d", &s->people.n);
        scanf("%d", &s->people.c);
        s->people.ava = (s->people.m + s->people.n + s->people.c) / 3;

        s->next = p->next;
        p->next = s;
        p = s;
        Record++;
    }
    return 0;
}

int display(linkList *head)
{
    int i;
    linkList *p;
    p = head;
    p = p->next;
    printf("\t\t\t\t学生信息\n");
    printf("--------------------------------------------------------------------------------\n");
    printf("\t\t学号\t\t姓名\t\t\t平均成绩\n");
    printf("--------------------------------------------------------------------------------\n");
    for (i = 0; i < Record; i++, p = p->next)
    {
        printf("%20s\t", p->people.id);
        printf("%10s\t", p->people.name);
        printf("%20d\n", p->people.ava);
    }

    return 0;
}

int search(linkList *head, char *info)
{
    int i;
    linkList *p;
    p = head;
    p = p->next;
    for (i = 0; i < Record; i++, p = p->next)
    {
        if ((!strcmp(p->people.id, info)) || (!strcmp(info, p->people.name)))
        {
            return i;
        }
    }
    return -1;
}

int add2(linkList *head, char *pid)
{
    int i;
    linkList *p, *s;
    p = head;
    p = p->next;
    s = (linkList*)malloc(sizeof(linkList));
    while (p->next != NULL)
    {
        p = p->next;
    }
    printf("请输入需要添加的姓名和成绩:\n");
    strcpy(s->people.id, pid);
    scanf("%s", s->people.name);
    scanf("%d", &s->people.m);
    scanf("%d", &s->people.n);
    scanf("%d", &s->people.c);
    s->people.ava = (s->people.m + s->people.n + s->people.c) / 3;
    if (search(head, s->people.id) == -1)
    {
        s->next = p->next;
        p->next = s;
        Record++;
    }
    else
    {
        printf("学号重复了\n");
    }
    sort(head, 0);
    return 0;
}

int delt(linkList *head, char *info)
{
    int i, n;
    linkList *p, *s;
    p = head;
    n = search(head, info);
    if (-1 == n)
    {
        printf("没有找到\n");
        return 0;
    }
    for (i = 0; i < n; i++) {
        p = p->next;
    }
    p->next = p->next->next;
    Record--;
    return 0;
}
int compare(int ava1, int ava2)
{
    if (ava1 < ava2)
    {
        return 1;
    }
    return 0;
}

int sort(linkList *head, int boolean)
{
    linkList *p, *pre;
    Info temp;
    if (boolean)
    {
        for (p = head->next; p != NULL; p = p->next)
        {
            for (pre = p->next; pre != NULL; pre = pre->next)
            {
                if (0 == compare(p->people.ava, pre->people.ava))
                {
                    temp = p->people;
                    p->people = pre->people;
                    pre->people = temp;
                }
            }
        }
    }
    else
    {
        for (p = head->next; p != NULL; p = p->next)
        {
            for (pre = p->next; pre != NULL; pre = pre->next)
            {
                if (1 == compare(p->people.ava, pre->people.ava))
                {
                    temp = p->people;
                    p->people = pre->people;
                    pre->people = temp;
                }
            }
        }
    }
    return 0;
}

运行结果如下:
这里写图片描述

#include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define M 3 struct student {long num; char name[20]; char sex; int score[5]; int ave; }stu[M]; void init() { printf("\t\t********************************\n\n"); printf("\t\tStudent score management systerm \n"); printf("\n"); printf("\t\t Make by Maggiehe \n"); printf("\n"); printf("\t\t Student number is 3206***** \n\n"); printf("\t\t********************************\n\n"); } void input() { int i,j; printf("\nInput the student number name sex math English PE maolun majing:\n"); for(i=0;i<M;i++) {scanf("%ld,%s,%c",&stu[i].num,stu[i].name,&stu[i].sex); for(j=0;j<5;j++) scanf("%d",&stu[i].score[j]); scanf("%d",&stu[i].ave); save(); } } void list() { int i,j; clrscr(); printf("\t**********************student****************************\n"); printf("num name sex math English PE maolun majing:\n"); for(i=0;i<M;i++) { printf("%ld %s %c",stu[i].num,stu[i].name,stu[i].sex); for(j=0;j<5;j++) printf("%d",stu[i].score[j]); printf("%d",stu[i].ave); } if((i+1)%10==0) { printf("\npress any key continue.......\n"); getch(); } printf("\t*************************end*********************************\n"); } void average() { int i,j; float sum[M]; for(i=0;i<M;i++) for(j=0;j<5;j++) sum[i]+=stu[i].score[j]; stu[i].ave=sum[i]/5.0; } void search_num() { long num; int i,j; printf("\nplease enter number which you want to search:"); scanf("%ld",&num); printf("\n"); for(i=0;i<M;i++) if(stu[i].num!=num) printf("The number is not exist\n"); else { printf("number name sex math English PE maolun majing average\n"); printf("%ld %s %c",stu[i].num,stu[i].name,stu[i].sex); for(j=0;j<5;j++) printf("%d",stu[i].score[j]); printf("%d",stu[i].ave); } } void search_nam() { int i,j; char name[20]; printf("\nplease enter name which you want to search:"); scanf("%s",&name); printf("\n"); for(i=0;i<M;i++) if(strcmp(stu[i].name,name)==0) { printf("number name sex math English PE maolun majing average:\n"); printf("%ld%s%c",stu[i].num,stu[i].name,stu[i].sex); for(j=0;j<5;j++) printf("%d",stu[i].score[j]); printf("%d",stu[i].ave); } else printf("\nThe name is not exist!!!\n"); } void search_ave() { int i,j,a=0; float k; printf("please enter average score which you want to search:"); scanf("%f",&k); printf("\n"); for(i=0;i<M;i++) if(stu[i].ave!=k) printf("The average score is not exist!!!\n"); else for(i=0;i<M;i++) { if(stu[i].ave<=k) printf("number name sex math English PE maolun majing average\n"); printf("%ld %s %c",stu[i].num,stu[i].name,stu[i].sex); for(j=0;j<5;j++) printf("%d",stu[i].score[j]); printf("%d",stu[i].ave); a++; } } void sort() { int i,j; struct student temp; for(i=0;i<M;i++) for(j=i+i;j<M;j++) if(stu[i].ave<stu[j].ave) {temp=stu[i]; stu[i]=stu[j]; stu[j]=temp; } } void save() { int i; FILE *fp; if((fp=fopen("student.dat","wb"))==NULL) {printf("cannot open file\n"); return; } for(i=0;i<M;i++) if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1) printf("file write error\n"); fclose(fp); } void delect() { int i,t; long num; printf("please enter number which you want to delect:"); scanf("%ld",&num); printf("\n"); for(i=0;i<M;i++) { if(stu[i].num!=num) printf("The number is not exist!!!\n"); if(stu[i].num==num) t=i; } for(i=t;i<M;i++) stu[i]=stu[i+1]; save(); } void insert() {FILE *fp; int i,n,t; struct student s; printf("please input record\n"); printf("number name sex math English PE maolun majing average\n"); scanf("%ld,%s,%c,%d%d%d%d%d%d",&s.num,s.name,&s.sex,&s.score[0],&s.score[1],&s.score[2],&s.score[3],&s.score[4],&s.ave); s.ave=(s.score[0]+s.score[1]+s.score[2]+s.score[3]+s.score[4])/3.0; if((fp=fopen("student.dat","wb"))==NULL) {printf("cannot open file\n"); return; } i=M; for(t=0;stu[i].ave>s.ave&&t<M;t++) if(fwrite(&s,sizeof(struct student),1,fp)!=1) printf("file write error\n"); fclose(fp); } void MainMenu() {clrscr(); printf("\t********************************************************************\n \n); Printf(“\n”); printf("\t choose one of following:\n"); printf("\t 1. search record\n"); printf("\t 2. sort record\n"); printf("\t 3. insert record\n"); printf("\t 4. delect record\n"); printf("\t please enter your choice:"); printf(“\n”); printf("\t********************************************************************\n"); } void menu_select() {clrscr(); printf("\t******************************************************************\n\n"); printf(“\n”); printf("\t choose one of following:\n"); printf("\t 1.1 search by number\n"); printf("\t 1.2 search by name\n"); printf("\t 1.3 search by average score\n"); printf("\t please enter your choice:"); printf(“\n”); printf("\t******************************************************************\n"); } void search() { char ch; clrscr(); menu_select(); ch=getch(); switch(ch) { case '1':search_num();break; case '2':search_nam();break; case '3':search_ave();break; } } main() { char ch; clrscr(); init(); input(); list(); average(); save(); MainMenu(); ch=getch(); switch(ch) { case '1':search();break; case '2':sort();break; case '3':insert();break; case '4':delect();break; } search_num(); search_nam(); search_ave(); sort(); delect(); insert; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值