c语言,帮我编个学生管理系统
学生管理系统,要求能法律添加、修改、删除学生信息(学号、姓名、性别、班级等) #include <stdio.h>#include <string.h>
#include <conio.h>
#include <dos.h>
static intb=0;
struct Score
{
float shu;
float li;
float hua;
float average;
voidvi(void);
};
void Score::vi(void)
{
average=(shu+li+hua)/3;
}
struct student
{
char number;
char name;
char sex;
float flag;
struct Score sco;
};
int x=0;
struct student sut;
//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,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,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 chariis input \t*\n");
printf("\t\t*\t2:the charois output\t*\n");
printf("\t\t*\t3:the chargis xiugai\t*\n");
printf("\t\t*\t4:the charq is tui chu\t*\n");
printf("\t\t*\t5:the chars is savelis\t*\n");
printf("\t\t*\t6:the chard 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.flag==1) {printf("\t\there is a people!\n");return;}
printf("put the number:\t");
scanf("%s",sut.number);
printf("\nput the name:\t");
scanf("%s",sut.name);
printf("\nput the sex:\t");
scanf("%s",sut.sex);
printf("\n");
printf("\nput the score:\n");
printf("put the shu:\t");
scanf("%f",&sut.sco.shu);
printf("\nput the li:\t");
scanf("%f",&sut.sco.li);
printf("\nput the hua:\t");
scanf("%f",&sut.sco.hua);
sut.sco.vi();
sut.flag=1;
if(b>1)
paixu();//输入完后自动排序
}
//输出数据
void putout(int i)
{
printf("\t\tthe number:\t%s",sut.number);
printf("\n\t\tthe name:\t%s",sut.name);
printf("\n\t\tthe sex:\t%s",sut.sex);
printf("\n");
printf("\n\t\tput the score:\n");
printf("\t\tthe shu:\t%f",sut.sco.shu);
printf("\n\t\tthe li: \t%f",sut.sco.li);
printf("\n\t\tthe hua:\t%f\n",sut.sco.hua);
printf("\n\t\the average is:\t%f\n",sut.sco.average);
}
//修改数据
void xiugai(void)
{
int i;
printf("put number student :\t");
scanf("%d",&i);
if(sut.flag!=1) {putin(i);return;}
printf("put the number:\t%s",sut.number);
printf("\nput the xiugai:\t");
scanf("%s",sut.number);
printf("\nput the name:\t%s",sut.name);
printf("\nput the name:\t");
scanf("%s",sut.name);
printf("\nput the sex:\t%s",sut.sex);
printf("\nput the sex:\t");
scanf("%s",sut.sex);
printf("put the shu:\t%d",sut.sco.shu);
printf("\nput the shu:\t");
scanf("%f",&sut.sco.shu);
printf("\nput the li:\t%d",sut.sco.li);
printf("\nput the li:\t");
scanf("%f",&sut.sco.li);
printf("\nput the hua:\t%d\n",sut.sco.hua);
printf("\nput the hua:\t");
scanf("%f",&sut.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;
char flag;
printf("put the name:\t");
scanf("%s",name);
for(;i<b;i++)
{
if(!strcmp(name,sut.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;
char flag;
printf("put the number:\t");
scanf("%s",number);
for(;i<b;i++)
{
if(!strcmp(number,sut.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.name,sut.name);
strcpy(sut.number,sut.number);
strcpy(sut.sex,sut.sex);
sut.sco.shu=sut.sco.shu;
sut.sco.li=sut.sco.li;
sut.sco.hua=sut.sco.hua;
sut.sco.average=sut.sco.average;
sut.flag=sut.flag;
}
}
void paixu(void)
{
char number;
int i=b-2;
strcpy(sut.name,sut.name);
strcpy(sut.number,sut.number);
strcpy(sut.sex,sut.sex);
sut.sco.shu=sut.sco.shu;
sut.sco.li=sut.sco.li;
sut.sco.hua=sut.sco.hua;
sut.sco.average=sut.sco.average;
strcpy(number,sut.number);
while(((strcmp1(number,sut.number))==1)&&i>=0)
{
strcpy(sut.name,sut.name);
strcpy(sut.number,sut.number);
strcpy(sut.sex,sut.sex);
sut.sco.shu=sut.sco.shu;
sut.sco.li=sut.sco.li;
sut.sco.hua=sut.sco.hua;
sut.sco.average=sut.sco.average;
sut.flag=sut.flag;
i=i-1;
}
strcpy(sut.name,sut.name);
strcpy(sut.number,sut.number);
strcpy(sut.sex,sut.sex);
sut.sco.shu=sut.sco.shu;
sut.sco.li=sut.sco.li;
sut.sco.hua=sut.sco.hua;
sut.sco.average=sut.sco.average;
sut.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;
} #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;
char name;
char sex;
/* float shu;
floatli;
floathua;*/
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)
{
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)
{
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;
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;
} 两个都可以, 太长了,我们只要小小的一个程序代码就可以,我是大一的 这么强悍
佩服 你好,可以用一个MIS软件试试,很有模块化! 好长时间 没看C 了, 差点没看懂…… 就是,那个写程序的高手哦,主函数里可以用个SWICH,把要带用的函数放到里面,让主函数尽量简单化好些 呜呜··我们当时也让做了··我什么都没有做啊··
页:
[1]
2