计算机技术论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

  • 欢迎访问 计算机技术论坛-电脑迷与初学者的家园!由于论坛管理严格,新注册会员可能遇到各种问题,无法解决的请发邮件 admin@jsjbbs.cn
查看: 8718|回复: 15

c语言,帮我编个学生管理系统

  [复制链接]
发表于 2010-1-4 16:49:51 | 显示全部楼层 |阅读模式
学生管理系统,要求能法律添加、修改、删除学生信息(学号、姓名、性别、班级等)
发表于 2010-1-5 13:07:47 | 显示全部楼层
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <dos.h>


static int  b=0;

struct Score
{
        float shu;
        float li;
        float hua;
        float average;
        void  vi(void);
};

void Score::vi(void)
{
        average=(shu+li+hua)/3;
}

struct student
{
        char number[8];
        char name[8];
        char sex[8];
        float flag;
        struct Score sco;
       
};

int x=0;

struct student sut[50];

//FILE *fp;
/*void data_load()
{
        int j;
        long k;
        fp=fopen("friend.txt","r+");
        if(fp!=NULL)
        {
                for(i=1;i<50;i++)
                {
                        if((j=fgetc(fp))==EOF)
                                return;
                        k=i-1;
                        fseek(fp,k*sizeof(struct student),SEEK_SET);
                        fread(&sut[i],sizeof(struct student),1,fp);
                }
        }
        else
        {
                fp=fopen("friend.txt","w");
                i=1;
        }
}
*/

/*
void data_save()
{
        int j;
        printf("%d",x);
        fp=fopen("friend.txt","w");
        for(j=1;j<=x;j++)
        {
                fwrite(&sut[j],sizeof(struct student),1,fp);
        }
        fclose(fp);
}
*/
void putin(int i);
void putout(int i);
void xiugai(void);
void dellist(void);
void delname(void);
void delnumber(void);
void move(int i);
int strcmp1(char *buf1,char *buf2);
void paixu(void);

int main(void)
{


        char flag;
       

    printf("\t\t*****************************************\n");
        printf("\t\t*\t1:the char  i  is input \t*\n");
        printf("\t\t*\t2:the char  o  is output\t*\n");
        printf("\t\t*\t3:the char  g  is xiugai\t*\n");
        printf("\t\t*\t4:the char  q is tui chu\t*\n");
        printf("\t\t*\t5:the char  s is savelis\t*\n");
        printf("\t\t*\t6:the char  d is dellist\t*\n");
        printf("\t\t*****************************************\n");
        while(1)
        {
       
                printf("\nput your donzhu:");
                //flag=getch();
                scanf("%c",&flag);
                switch(flag)
                {
                case  'i' :  {int i;   
                                          printf("put number student :\t");
                                          scanf("%d",&i);
                                          putin(i);
                                         } break;

                case  'o' : {int i;
                                        printf("put number student :\t");
                                        scanf("%d",&i);
                                        putout(i);
                                        }break;

                case 'd' : dellist(); break;

                case 'g' : xiugai(); break;
//                case 's' :  data_save(); break;
                case 'q' : goto tuichu; break;
                }

        }//end while
tuichu:          // goto结束语
        return 0;
}


//输入数据
void putin(int i)
{
        b=b+1;      
    x++;
        if(sut[i].flag==1) {printf("\t\there is a people!\n");return;}

        printf("put the number:\t");
        scanf("%s",sut[i].number);

        printf("\nput the name:\t");
        scanf("%s",sut[i].name);

        printf("\nput the sex:\t");
        scanf("%s",sut[i].sex);

        printf("\n");
        printf("\nput the score:\n");
        printf("put the shu:\t");
        scanf("%f",&sut[i].sco.shu);

        printf("\nput the li:\t");
        scanf("%f",&sut[i].sco.li);

        printf("\nput the hua:\t");
        scanf("%f",&sut[i].sco.hua);
        sut[i].sco.vi();
        sut[i].flag=1;
        if(b>1)
        paixu();//输入完后自动排序
}

//输出数据
void putout(int i)
{       
        printf("\t\tthe number:\t%s",sut[i].number);
       
        printf("\n\t\tthe name:\t%s",sut[i].name);
       
        printf("\n\t\tthe sex:\t%s",sut[i].sex);
       
        printf("\n");
        printf("\n\t\tput the score:\n");
        printf("\t\tthe shu:\t%f",sut[i].sco.shu);
       
        printf("\n\t\tthe li: \t%f",sut[i].sco.li);

        printf("\n\t\tthe hua:\t%f\n",sut[i].sco.hua);
        printf("\n\t\the average is:\t%f\n",sut[i].sco.average);
       
}

//修改数据
void xiugai(void)
{
        int i;
        printf("put number student :\t");
        scanf("%d",&i);

        if(sut[i].flag!=1) {putin(i);return;}

        printf("put the number:\t%s",sut[i].number);
        printf("\nput the xiugai:\t");
        scanf("%s",sut[i].number);

        printf("\nput the name:\t%s",sut[i].name);
        printf("\nput the name:\t");
        scanf("%s",sut[i].name);

        printf("\nput the sex:\t%s",sut[i].sex);
        printf("\nput the sex:\t");
        scanf("%s",sut[i].sex);
       
        printf("put the shu:\t%d",sut[i].sco.shu);
        printf("\nput the shu:\t");
        scanf("%f",&sut[i].sco.shu);

        printf("\nput the li:\t%d",sut[i].sco.li);
        printf("\nput the li:\t");
        scanf("%f",&sut[i].sco.li);

        printf("\nput the hua:\t%d\n",sut[i].sco.hua);
        printf("\nput the hua:\t");
        scanf("%f",&sut[i].sco.hua);

}


void dellist(void)
{
        char fla=0;
        printf("\t\tpress n use name");
        printf("\n\t\tpress l use number");
        printf("\nyou char is :\t");
        getchar();
        while(1)
        {

                scanf("%c",&fla);
                printf("%c\n",fla);
                if(fla=='n'||fla=='l') break;
                printf("\nput again:\t");

        }
            //不能执行。我加了getchar()后能执行,上面的getchar()接收回车键
        switch(fla)
        {
        case 'n' : delname();break;
        case 'l' : delnumber();break;
        default  : printf("you are wrong\n");
        }
}

void delname(void)
{
        int i=0;
        char name[8];
        char flag;
        printf("put the name:\t");
        scanf("%s",name);
        for(;i<b;i++)
        {
                if(!strcmp(name,sut[i].name))
                {
                        putout(i);
                        printf("press Y OR N");
                        getchar();
                        scanf("%c",&flag);
                        if(flag=='y') {move(i);return;}
                }
        }
        if(i>=b) printf("sorry search is no\n");       

}



void delnumber(void)
{
        int i=0;
        char number[8];
        char flag;
        printf("put the number:\t");
        scanf("%s",number);
        for(;i<b;i++)
        {
                if(!strcmp(number,sut[i].number))
                {
                        putout(i);
                        printf("press Y OR N");
                        getchar();
                        scanf("%c",&flag);
                        if(flag=='y') {move(i);return;}
                }
        }
        if(i>=b) printf("sorry search is no\n");       

}



void move(int i)
{
        for(;i<b-1;i++)
        {
                strcpy(sut[i].name,sut[i+1].name);
                strcpy(sut[i].number,sut[i+1].number);
                strcpy(sut[i].sex,sut[i+1].sex);
                sut[i].sco.shu=sut[i+1].sco.shu;
                sut[i].sco.li=sut[i+1].sco.li;
                sut[i].sco.hua=sut[i+1].sco.hua;
                sut[i].sco.average=sut[i+1].sco.average;
                sut[i].flag=sut[i+1].flag;
        }
}

void paixu(void)
{
        char number[8];
        int i=b-2;
                strcpy(sut[b].name,sut[b-1].name);
                strcpy(sut[b].number,sut[b-1].number);
                strcpy(sut[b].sex,sut[b-1].sex);
                sut[b].sco.shu=sut[b-1].sco.shu;
                sut[b].sco.li=sut[b-1].sco.li;
                sut[b].sco.hua=sut[b-1].sco.hua;
                sut[b].sco.average=sut[b-1].sco.average;
        strcpy(number,sut[b-1].number);
        while(((strcmp1(number,sut[i].number))==1)&&i>=0)
        {
                strcpy(sut[i+1].name,sut[i].name);
                strcpy(sut[i+1].number,sut[i].number);
                strcpy(sut[i+1].sex,sut[i].sex);
                sut[i+1].sco.shu=sut[i].sco.shu;
                sut[i+1].sco.li=sut[i].sco.li;
                sut[i+1].sco.hua=sut[i].sco.hua;
                sut[i+1].sco.average=sut[i].sco.average;
                sut[i+1].flag=sut[i].flag;
                i=i-1;
        }
                strcpy(sut[i+1].name,sut[b].name);
                strcpy(sut[i+1].number,sut[b].number);
                strcpy(sut[i+1].sex,sut[b].sex);
                sut[i+1].sco.shu=sut[b].sco.shu;
                sut[i+1].sco.li=sut[b].sco.li;
                sut[i+1].sco.hua=sut[b].sco.hua;
                sut[i+1].sco.average=sut[b].sco.average;
                sut[i+1].flag=1;
}

int strcmp1(char *buf1,char *buf2)
{
        while(*buf1!='\0'||*buf2!='\0')
        {
                if(*buf1>*buf2) return 1;
                if(*buf1<*buf2) return -1;
                buf1++;
                buf2++;
        }
        return 0;
}
发表于 2010-1-5 13:08:17 | 显示全部楼层
#include <stdio.h>
#include <string.h>
#include <malloc.h>

#define LEN sizeof(struct student)

//int n=0;

struct score
{
        //成绩
        float shu;
        float li;
        float hua;
        float average;
//        void aver(void);
};
/*
void struct score::aver(void)
{
        average=(shu+li+hua)/3;
}*/
struct student
{
        //姓名,姓别,成绩
        char number[8];
        char name[8];
        char sex[8];
/*        float shu;
        float  li;
        float  hua;*/
        struct score sco;
        struct student *next;
};

struct student *creat(void)//建立结点   //会自动按平均分由低到高排序
{
        struct student *head;
        struct student *p1,*p3,*p4;
        int n=0;
        p1=(struct student *)malloc(LEN);
        if(p1==NULL)
        {
                printf("no enough memory!\n");
                return (NULL);
        }

        printf("put the number:\t");
        scanf("%s",p1->number);

        printf("\nput the name:\t");
        scanf("%s",p1->name);

        printf("\nput the sex:\t");
        scanf("%s",p1->sex);

        printf("\n");
        printf("\nput the score:\n");
        printf("put the shu:\t");
        scanf("%f",&p1->sco.shu);

       
        printf("\nput the li:\t");
        scanf("%f",&p1->sco.li);

        printf("\nput the hua:\t");
        scanf("%f",&p1->sco.hua);
       
        p1->sco.average=(p1->sco.shu+p1->sco.li+p1->sco.hua)/3;

        head=NULL;

        while(p1->sco.average!=0)
        {
                n=n+1;
                if(n==1) {head=p1;p3=p1;p1->next=NULL;}
                else
                {
                        while(p1->sco.average>p3->sco.average&&p3->next!=NULL)
                        {
                                p4=p3;
                                p3=p3->next;
                        }
                        if(p3->sco.average>=p1->sco.average)
                        {
                                if(p3==head){head=p1;p1->next=p3;}
                                else
                                {
                                        p4->next=p1;//改过
                                        p1->next=p3;
                                }
                        }
                        else
                        {
                                p3->next=p1;
                                p1->next=NULL;
                        }
                        p3=head;
                }
       
                        p1=(struct student *)malloc(LEN);
                        if(p1==NULL)
                        {
                        printf("no enough memory!\n");
                        return (NULL);
                        }

                        printf("put the number:\t");
                        scanf("%s",p1->number);

                        printf("\nput the name:\t");
                        scanf("%s",p1->name);

                        printf("\nput the sex:\t");
                        scanf("%s",p1->sex);

                        printf("\n");
                        printf("\nput the score:\n");
                        printf("put the shu:\t");
                        scanf("%f",&p1->sco.shu);


                        printf("\nput the li:\t");
                        scanf("%f",&p1->sco.li);
       
                        printf("\nput the hua:\t");
                        scanf("%f",&p1->sco.hua);

                        p1->sco.average=(p1->sco.shu+p1->sco.li+p1->sco.hua)/3;
               
               
        }
        return(head);
}

void prin(struct student *head)  //输出结点
{
        struct student *p;
        if(head==NULL) //   ==与=重要重要啊!
        {
                printf("no people!");
                return ;
        }
        p=head;
        do
        {
                printf("\n**************************************\n");
                printf("***the number:\t");
                printf("%s",p->number);

                printf("\n***the name:\t");
                printf("%s",p->name);

                printf("\n***the sex:\t");
                printf("%s",p->sex);

                printf("\n");
                printf("\n***the score:\n");
                printf("***the shu:\t");
                printf("%f",p->sco.shu);


                printf("\n***the li:\t");
                printf("%f",p->sco.li);

                printf("\n***the hua:\t");
                printf("%f",p->sco.hua);
               
                printf("\n***the average:\t");
                printf("%f",p->sco.average);

                printf("\n**************************************\n");

                p=p->next;
        }while(p!=NULL);
       
}


struct student *del(struct student *head,char name[8])
{
        struct student *p1,*p2;
        char flag;
        char cflag=0;
        if(head==NULL) {printf("\nlist null!\n");return head;}
        p1=head;
        while(p1!=NULL)  //p1->next!=NULL改为p1!=NULL
        {       
                     //改过 移下面去了  不能删除最后一个数据
                if(!strcmp(name,p1->name))
                {
                        cflag++;
                        printf("\nname:%s",p1->name);
                        printf("\nnumber:%s",p1->number);
                        printf("\nsex:%s",p1->sex);
                        printf("\nshu:%f",p1->sco.shu);
                        printf("\nli:%f",p1->sco.li);
                        printf("\nhua:%f",p1->sco.hua);
                        printf("\naverage:%f",p1->sco.average);

                        printf("\npress YorN:\t");
                        fflush(stdin);
                        scanf("%c",&flag);
                        if(flag=='y'||flag=='Y')
                        {
                                if(p1==head) head=p1->next;//我没有考虑这个
                                else
                                        p2->next=p1->next;   //p2是第二次才能出现的
                        }
                }//endif
                p2=p1;
                p1=p1->next;               
        }
        if(cflag==0) printf("\nNo your want!\n");
        return(head);
}

struct student *insert(struct student *head,struct student *stud)
{
        struct student *p,*p1;
        p=head;
        if(head==NULL)
        {head=stud;stud->next=NULL;}
        else
        {
                while(stud->sco.average>p->sco.average&&p->next!=NULL)
                {
                        p1=p;
                        p=p->next;
                }
                if(stud->sco.average<=p->sco.average)
                {
                        if(p==head) {head=stud;stud->next=p;}
                        else
                        {
                                p1->next=stud;
                                stud->next=p;
                        }
                }
                else
                {
                        p->next=stud;
                        stud->next=NULL;
                }
        }

        return head;

}
//怎么做一个以名字或者是学号来修改的函数
struct student *amend(struct student *head,char name[8])
{
        struct student *p;
        if(head==NULL) printf("\nno people!");   //又是这样,=与==重要啊
        p=head;
        while(p!=NULL)
        {
                if(!strcmp(name,p->name))
                {
                        printf("\n**************************************\n");
                        printf("***the number:\t");
                        printf("%s\n",p->number);
                        scanf("%s",p->number);

                        printf("\n***the name:\t");
                        printf("%s\n",p->name);
                        scanf("%s",p->name);

                        printf("\n***the sex:\t");
                        printf("%s\n",p->sex);
                        scanf("%s",p->sex);

                        printf("\n***the score:\n");
                        printf("***the shu:\t");
                        printf("%f\n",p->sco.shu);
                        scanf("%f",&p->sco.shu);


                        printf("\n***the li:\t");
                        printf("%f\n",p->sco.li);
                        scanf("%f",&p->sco.li);

                        printf("\n***the hua:\t");
                        printf("%f\n",p->sco.hua);
                        scanf("%f",&p->sco.hua);

                        p->sco.average=(p->sco.shu+p->sco.li+p->sco.hua)/3;

                        printf("\n**************************************\n");
                }
                p=p->next;
        }
        return head;
}

struct student *frees(struct student *head)
{
        struct student *p;
        p=head;
        while(p!=NULL)
        {
                p=head->next;
                free(head);
                head=p;
        }
        return head;
}

int main(void)
{
        struct student *head;
        head=NULL;
        struct student *p1;
        char name[8];
        char flag;
        char flagc=0;
        unsigned char stu=0;
        printf("\n*****************************************\n");
        printf("*\t the action:\t\t\t*\n");
        printf("*\t 1:char i is a input!\t\t*");
        printf("\n*\t 2:char o is a output!\t\t*");
        printf("\n*\t 3:char d is a delname!\t\t*");
        printf("\n*\t 4:char a is a insert!\t\t*");
        printf("\n*\t 6:char m is amend!\t\t*");
        printf("\n*\t 7:char n is count student!\t*");
        printf("\n*\t 5:char q is quit!\t\t*");
        printf("\n*****************************************\n");
        while(1)
        {
                fflush(stdin);
                printf("\nput your action:\t");
                scanf("%c",&flag);
                fflush(stdin);
                switch(flag)
                {
                case 'i' : {if(flagc==0)
                                        {flagc=1;head=creat();}
                                        else
                                        {flagc=0;frees(head);head=creat();}
                                   }break;
               
                case 'o' : prin(head);break;
                case 'd' :
                        {
                        printf("the name:\t");
                        scanf("%s",name);
                        head=del(head,name);
                        } break;
                case 'a' :
                        {
                                p1=(struct student *)malloc(sizeof(struct student));
                                printf("put the number:\t");
                                scanf("%s",p1->number);

                                printf("\nput the name:\t");
                                scanf("%s",p1->name);

                                printf("\nput the sex:\t");
                                scanf("%s",p1->sex);

                                printf("\n");
                                printf("\nput the score:\n");
                                printf("put the shu:\t");
                                scanf("%f",&p1->sco.shu);

       
                                printf("\nput the li:\t");
                                scanf("%f",&p1->sco.li);

                                printf("\nput the hua:\t");
                                scanf("%f",&p1->sco.hua);
       
                                p1->sco.average=(p1->sco.shu+p1->sco.li+p1->sco.hua)/3;

                                head=insert(head,p1);

                        } break;
                case 'm' :
                        {
                                printf("\nput the name:\t");
                                scanf("%s",name);
                                head=amend(head,name);
                        } break;
                case 'n' :
                        {
                                stu=0;
                                p1=head;
                                while(p1!=NULL)
                                {
                                        stu++;
                                        p1=p1->next;
                                }
                                printf("The student have %u\n",stu);
                        }break;
        //        case '0' :head=frees(head);break;
                case 'q' : goto end;break;
                }
        }
end:
        return 0;
}
发表于 2010-1-5 13:08:47 | 显示全部楼层
两个都可以,
 楼主| 发表于 2010-1-5 17:15:18 | 显示全部楼层
太长了,我们只要小小的一个程序代码就可以,我是大一的
发表于 2010-1-6 12:15:41 | 显示全部楼层
这么强悍
佩服
发表于 2010-1-6 16:57:05 | 显示全部楼层
你好,可以用一个MIS软件试试,很有模块化!
发表于 2010-11-5 14:09:09 | 显示全部楼层
好长时间 没看C 了,   差点没看懂……
发表于 2011-2-14 20:15:18 | 显示全部楼层
就是,那个写程序的高手哦,主函数里可以用个SWICH,把要带用的函数放到里面,让主函数尽量简单化好些
发表于 2011-3-5 23:41:17 | 显示全部楼层
呜呜··我们当时也让做了··我什么都没有做啊··
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

无图版|手机版|计算机技术论坛 JSJBBS.CN @ 2008-2024 ( 鲁ICP备17021708号 )

技术支持 : 北京康盛新创科技有限责任公司

快速回复 返回顶部 返回列表