结构做得不错,条理清晰,我喜欢,不过算法不好,系统运行不都快,要是用C++的类编就比较好点。这就是C与C++的区别吧
[此贴子已经被作者于2007-6-18 20:49:03编辑过]
我做了一些,希望大家多多指教!
这用的是数组方法:
#include<stdio.h>
struct node
{
int id;
char name[10];
float math,english,computer;
};
struct biao
{
struct node chen[50];
int biaochang;
}biao1;
void chengjiluru()
{
int a,i,s;
float z;
char x;
loop:for(;;)
{
if (biao1.biaochang>=50)
printf("%s\n","gaibiaoyiman!");
else
{
for(;;)
{
printf("qingshuruxuehao:");
scanf("%d",&a);
if(a<0||a>50)
{
printf("shuruxuehaoyouwu!\n");
continue;
}
else
break;
}
for(i=0;i<biao1.biaochang;i++)
{
if(a==biao1.chen[i].id)
{
printf("gaishengyicunzai!\n");
break;
}
}
if(i==biao1.biaochang)
{ s=biao1.biaochang;
biao1.chen[s].id=a;
printf("qingshuruxingming:");
scanf("%s",&biao1.chen[s].name);
for(;;)
{
printf("qingshurushuxue:");
scanf("%f",&z);
if(z<0||z>100)
{
printf("shurushuxueyouwu!\n");
continue;
}
else break;
}
biao1.chen[s].math=z;
for(;;)
{
printf("qingshuruyingyu:");
scanf("%f",&z);
if(z<0||z>100)
{
printf("shuruyingyuyouwu!\n");
continue;
}
else break;
}
biao1.chen[s].english=z;
for(;;)
{
printf("qingshurujisuanji:");
scanf("%f",&z);
if(z<0||z>100)
{
printf("shurujisuanjiyouwu!\n");
continue;
}
else break;
}
biao1.chen[s].computer=z;
biao1.biaochang=biao1.biaochang+1;
}
}
for(;;)
{
printf("shifoujixuluru(Y/N):");
getchar();
x=getchar();
if(x=='n'||x=='N')
goto lp;
else
{if(x=='y'||x=='Y')
goto loop;
else
{printf("shurubuhefa!\n");
continue;}
}
}
}lp:;
}
char fuzhi(char a[10],char b[10])
{
int i=0;
while(b[i]=='\0')
a[i]=b[i];
return a[10];
}
void chengjishanchu()
{
int d,i,x;
char q;
loop:for(;;)
{
if(biao1.biaochang==0)
{printf("gaibiaowujilu!\n");
break;
}
else
{
for(;;)
{
printf("qingshuruyaoshanchudexuehao:");
scanf("%d",&d);
if(d<0||d>50)
{printf("xuhaoyouwu!\n");
continue;}
else
break;
}
if(biao1.biaochang==1)
biao1.biaochang=biao1.biaochang-1;
else
{
for(i=0;i<biao1.biaochang;i++)
{
if(biao1.chen[i].id==d)
break;
}
if(i==biao1.biaochang)
printf("xuehaobucunzai!\n");
else
if(i==biao1.biaochang-1)
biao1.biaochang=biao1.biaochang-1;
else
{
{for(x=i+1;x<=biao1.biaochang-1;x++)
{
biao1.chen[x-1].id=biao1.chen[x].id;
fuzhi(biao1.chen[x-1].name,biao1.chen[x].name);
biao1.chen[x-1].math=biao1.chen[x].math;
biao1.chen[x-1].english=biao1.chen[x].english;
biao1.chen[x-1].computer=biao1.chen[x].computer;
biao1.biaochang=biao1.biaochang-1;
}}}}}
for(;;)
{
printf("shifoujixushanchu(Y/N):");
getchar();
q=getchar();
if(q=='n'||q=='N')
goto lp;
else
{
if(q=='y'||q=='Y')
goto loop;
else
{printf("shurubuhefa!\n");
break;}
}
}
}lp:;
}
void chengjixiugai()
{
int x,i;
char q;
float a;
loop:for(;;)
{
if(biao1.biaochang==0)
{
printf("gaibiaowujilu!\n");
break;
}
else
{
for(;;)
{
printf("qingshuruyaoxiugaidexuehao:");
scanf("%d",&x);
if(x<0||x>50)
{printf("xuehaoyouwu!\n");
continue;}
else
break;
}
for(i=0;i<biao1.biaochang;i++)
{ if(biao1.chen[i].id==x)
{printf("xuehao:%d\n",biao1.chen[i].id);
printf("xingming:%s\n",biao1.chen[i].name);
printf("shuxue:%f\n",biao1.chen[i].math);
printf("yingyu:%f\n",biao1.chen[i].english);
printf("jisuanji:%f\n",biao1.chen[i].computer);
printf("qingchongxinshurushuxue:");
scanf("%f",&a);
biao1.chen[i].math=a;
printf("qingchongxinshuruyingyu:");
scanf("%f",&a);
biao1.chen[i].english=a;
printf("qingchongxinshurujisuanji:");
scanf("%f",&a);
biao1.chen[i].computer=a;
}}
if(i==biao1.biaochang)
printf("xuehaobucunzai!\n");
for(;;)
{
printf("shifoujixuxiugai(Y/N):");
getchar();
q=getchar();
if(q=='n'||q=='N')
goto lp;
else
{
if(q=='y'||q=='Y')
goto loop;
else
{printf("shufubuhefa!\n");
break;}
}
}
}
}lp:;
}
void chengjixianshi()
{
int i;
if(biao1.biaochang==0)
printf("gaibiaowujilu!\n");
else
{
printf(" xuehao xingming shuxue yingyu jisuanji\n");
for(i=0;i<biao1.biaochang;i++)
printf("%9d%10s %-8.2f %-8.2f %-8.2f\n",biao1.chen[i].id,biao1.chen[i].name,biao1.chen[i].math,biao1.chen[i].english,biao1.chen[i].computer);
}
}
void jisuanzongfenhepingjunfen()
{ int i;
float x,y;
if(biao1.biaochang==0)
printf("gaibiaowujilu!\n");
else
{
printf(" xuehao xingming zongfen pingjunfen\n");
for(i=0;i<biao1.biaochang;i++)
{x=biao1.chen[i].math+biao1.chen[i].english+biao1.chen[i].computer;
y=x/3;
printf("%9d%10s %-8.2f %-8.2f\n",biao1.chen[i].id,biao1.chen[i].name,x,y);
}}}
void main()
{
int x;
biao1.biaochang=0;
for(;;)
{
printf(" chengjiguanli[shuzu] \n");
printf(" ----------------------------------------------\n");
printf(" | 1.chengjiluru |\n");
printf(" | 2.chengjishanchu |\n");
printf(" | 3.chengjixiugai |\n");
printf(" | 4.chengjixianshi |\n");
printf(" | 5.jisuanzongfenhepingjunfen |\n");
printf(" | 6.tuichu! |\n");
printf(" ----------------------------------------------\n");
printf(" qingshurugongnenghao:");
scanf("%d",&x);
if(x==1) chengjiluru();
if(x==2) chengjishanchu();
if(x==3) chengjixiugai();
if(x==4) chengjixianshi();
if(x==5) jisuanzongfenhepingjunfen();
if(x==6) break;
}
}
这是用的链表:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int id;
char name[10];
float english,math,computer,zongfen,pingjunfen;
struct node *next;
}*head;
void luru();
void shanchu();
void xiugai();
void xianshi();
void zongfenhepingjunfen();
void luru()
{
float a;
struct node *p,*q;
if(head==NULL)
{
head=(struct node *) malloc(sizeof(struct node));
head->next=NULL;
}
p=(struct node *) malloc(sizeof(struct node));
printf(" qingshuruxuehao:");
scanf("%d",&p->id);
printf(" qingshuruxingming:");
scanf("%s",&p->name);
for(;;)
{
printf(" qingshuruyingyu(0~100):");
scanf("%f",&a);
if(a<0||a>100)
{
printf(" shuruyingyuyouwu!\n");
continue;
}
else break;
}
p->english=a;
for(;;)
{
printf(" qingshurushuxue(0~100):");
scanf("%f",&a);
if(a<0||a>100)
{
printf(" shurushuxueyouwu!\n");
continue;
}
else break;
}
p->math=a;
for(;;)
{
printf(" qingshurujisuanji(0~100):");
scanf("%f",&a);
if(a<0||a>100)
{
printf(" shurujisuanjiyouwu!\n");
continue;
}
else break;
}
p->computer=a;
p->next=NULL;
q=head;
if(head->next==NULL)
{
head->next=p;
}
else
{
while(q->next!=NULL)
q=q->next;q->next=p;
}
}
void shanchu(n)
{
struct node *q1,*q2,*q3;
q1=head;
q3=q1;
if(head->next==NULL)
{
printf(" chengjibiaowujilu!\n");
}
else
{
while(q1->id!=n && q1->next!=NULL)
{
q3=q1;q1=q1->next;
}
if(q1->id==n)
{
q2=q3->next;
q3->next=q2->next;
free(q2);
}
else return;
}
}
void xiugai()
{
int n;
struct node *p;
float a;
p=(struct node *) malloc(sizeof(struct node));
p->next=NULL;
printf(" qingshuruyaoxiugaidexuehao:");
scanf("%d",&n);
p->id=n;
p=head;
if(p!=NULL)
{
while(p->id!=n && p->next!=NULL)
{
p=p->next;
}
if(p->id==n)
{
printf(" qingshuruxingming:");
scanf("%s",&p->name);
for(;;)
{
printf(" qingshuruyingyu(0~100):");
scanf("%f",&a);
if(a<0||a>100)
{
printf(" shuruyingyuyouwu!\n");
continue;
}
else break;
}
p->english=a;
for(;;)
{
printf(" qingshurushuxue(0~100):");
scanf("%f",&a);
if(a<0||a>100)
{
printf(" shuruyingyuyouwu!\n");
continue;
}
else break;
}
p->math=a;
for(;;)
{
printf(" qingshurujisuanji(0~100):");
scanf("%f",&a);
if(a<0||a>100)
{
printf(" shuruyingyuyouwu!\n");
continue;
}
else break;
}
p->computer=a;
}
else
printf(" xuehaobucunzai!\n");
}
else
printf(" xuhaobucunzai!\n");
}
void xianshi()
{
struct node *p;
p=head;
if(p->next==NULL)
{
printf(" chengjibiaowujilu!\n");
}
else
{
printf(" xuehao xingming yingyu shuxue jisuanji\n");
while(p->next!=NULL)
{
printf(" %d %s %3.2f %3.2f %3.2f\n",p->next->id,p->next->name,p->next->english,p->next->math,p->next->computer);
p=p->next;
}
}
}
void zongfenhepingjunfen()
{
struct node *p;
p=head;
p->next->zongfen=p->next->english+p->next->math+p->next->computer;
p->next->pingjunfen=p->next->zongfen/3;
if(p->next==NULL)
{
printf(" chengjibiaowujilu!\n");
}
else
{
printf(" xuehao xingming zongfen pingjunfen\n");
while(p->next!=NULL)
{
printf(" %d %s %3.2f %3.2f\n",p->next->id,p->next->name,p->next->zongfen,p->next->pingjunfen);
p=p->next;
}
}
}
void main()
{
int x,n;
for(;;)
{
printf(" chengjiguanli[lianbiao] \n");
printf(" ----------------------------------------\n");
printf(" | 1.chengjiluru |\n");
printf(" | 2.chengjishanchu |\n");
printf(" | 3.chengjixiugai |\n");
printf(" | 4.chengjixianshi |\n");
printf(" | 5.jisuanzongfenhepingjunfen |\n");
printf(" | 0.tuichu! |\n");
printf(" ----------------------------------------\n");
printf(" qingshurugongnenghao:");
scanf("%d",&x);
if(x==1) luru();
if(x==2)
{
printf(" qingshuruyaoshanchudexuehao:");
scanf("%d",&n);
shanchu(n);
}
if(x==3) xiugai();
if(x==4) xianshi();
if(x==5) zongfenhepingjunfen();
if(x==6) break;
}
}