学生管理系统基本操作的实现(因为太长了所以上传到这里并以超链接的形式放在附件2里)

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

typedef struct student

{

    int no;

    char name[20];

    char gender;

    double score[3];

    double sum;

    double ave;

    struct student *next;

}stu;

void input(stu *t)

{

    int i;

    t->sum=0;

    scanf("%d ",t->no);

    gets(t->name);

    t->gender=getchar();

    for(i=0;i<3;i++)

    {

        scanf("%lf",&t->score[i]);

        t->sum+=t->score[i];

    }

    t->ave=t->sum*1.0/3;

}

int seek(stu *head,int no)

{

    int i,j=0;

    stu *p;

    p=head->next;

    while(p)

    {

        if(p->no==no)

        {

            printf("%d  %s  ",p->no,p->name);

            for(i=0;i<3;i++)

            printf("%.2lf  ",p->score[i]);

            printf("%.2lf %.2lf\n",p->ave,p->sum);

            return 1;

        }

        p=p->next;

    }

    return 0;

}

 

stu *creatlist(int n)

{

    stu *head,*p,*q;

    int i;

    head=(stu*)malloc(sizeof(stu));

    head->next=NULL;

    q=head;

    for(i=0;i<n;i++)

    {

        p=(stu*)malloc(sizeof(stu));

        input(p);

        q->next=p;

        q=p;

    }

    q->next=NULL;

    return head;

}

void output(stu *head)

{

    int i;

    stu *p;

    p=head->next;

    while(p)

    {

        printf("%d  %s  ",p->no,p->name);

        for(i=0;i<3;i++)

        printf("%.2lf  ",p->score[i]);

        printf("%.2lf  %.2lf\n",p->ave,p->sum);

        p=p->next;

    }

}

stu *delete(stu *head,int no)

{

    stu *p,*pre;

    pre=head;

    p=head->next;

    while(p)

    {

        if(p->no==no)

        {

            pre->next=p->next;

            return 1;

        }

        pre=p;

        p=p->next;

    }

    return head;

}

void store(FILE *fp,stu *t,int n)

{

    fp=fopen("student.dat.txt","w+");

    if(fp==NULL)

    {

        printf("error open file\n");

        exit(1);

    }

    fwrite(t,sizeof(stu),n,fp);

    fclose(fp);

}

 

stu *insert(stu *head,stu *x)

{

    stu *p,*pre;

    pre=head;

    p=head->next;

    while(p)

    {

        if(x->no<p->no)

        {

            pre->next=x;

            x->next=p;

            return 1;

        }

        pre=p;

        p=p->next;

    }

    pre->next=x;

    x->next=NULL;

return head;

}

void menu()

{

    printf("please enter your section on the keyboard\n");

    printf("1---create   2---seek\n");

    printf("3---delete   3---add\n");

    printf("5---print    6---quit\n");

}

int main()

{

    FILE *fp;

    stu *head=NULL,new;

    int ncom,n,no;

    while(1)

    {

        menu();

        scanf("%d",&ncom);

        {

           switch(ncom)

            {case 1:

            {

                scanf("%d",&n);

                head=creatlist(n);

                break;

            }

            case 2:

            {

                scanf("%d",&no);

                if(!seek(head,no))

                    printf("no person\n");

                break;

            }

            case 3:

            {

               scanf("%d",&no);

               head=delete(head,no);

               break;

            }

            case 4:

            {

                //store(head,fp,n);

                printf("please enter information of new student\n");

                input(&new);

                head=insert(head,&new);

                break;

            }

            case 5:

            {

                output(head);

                break;

            }

            case 6:exit(0);

        }

    }

}

    return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值