第1个回答 2007-12-26
#include <stdio.h>
struct
{
int xuehao;
float yuwen,shuxue,waiyu,zongfen;
}
xuesheng[100];
static num2;
main()
{
int num1;
num1=0;
num2=1;
while(1)
{
printf("please choose:\n");
printf("1.yici shuru chengji\n");
printf("2.xiugai xuesheng chengji\n");
printf("3.chaxun xuesheng chengji\n");
printf("4.tuichu\n");
scanf("%d",&num1);
switch(num1)
{
case 1:input_information(num2);
num2++;break;
case 2:xiugai_chengji();break;
case 3:chaxun_chengji();break;
case 4:exit();
}
}
}
int input_information(int num)
{
float total;
printf("please input xuehao yuwen shuxue waiyu\n");
scanf("%d %f %f %f",&xuesheng[num].xuehao,&xuesheng[num].yuwen,&xuesheng[num].shuxue,&xuesheng[num].waiyu);
total=xuesheng[num].yuwen+xuesheng[num].shuxue+xuesheng[num].waiyu;
xuesheng[num].zongfen=total;
}
int xiugai_chengji()
{
int i,num3;
float total;
i=0;
num3=0;
printf("shuru xuehao:\n");
scanf("%d",&num3);
for (i=1;i<num2;i++)
if(num3==xuesheng[i].xuehao)
{
printf("please input xuehao yuwen shuxue waiyu\n");
scanf("%d %f %f %f",&xuesheng[num3].xuehao,&xuesheng[num3].yuwen,&xuesheng[num3].shuxue,&xuesheng[num3].waiyu);
total=xuesheng[num3].yuwen+xuesheng[num3].shuxue+xuesheng[num3].waiyu;
xuesheng[num3].zongfen=total;
return;
}
printf("zhaobudao cixuehao!\n");
return;
}
int chaxun_chengji()
{
int i;
int num3;
printf("shuru xuehao:\n");
scanf("%d",&num3);
for (i=1;i<num2;i++)
if(num3==xuesheng[i].xuehao)
{
printf("xuehao yuwen shuxue waiyu zongfen\n");
printf("%d %6f %6f %6f %6f\n",xuesheng[num3].xuehao,xuesheng[num3].yuwen,xuesheng[num3].shuxue,xuesheng[num3].waiyu,xuesheng[num3].zongfen);
return;
}
printf("zhaobudao cixuehao!\n");
return;
}
总算写完了测试也通过了.给分吧!
qq 64924930本回答被提问者采纳
第2个回答 2007-12-27
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define N 50
#define NULL 0
struct student
{
char num[50];
float Chinese;
float Math;
float English;
float Total;
struct student *next;
}stu[N];
void main()
{
struct student *input();
void alter(struct student *);
void search(struct student *);
struct student *head=NULL;
for(;;)
{
switch(menu_select())
{
case 1:head=input();break;
case 2:alter(head);break;
case 3:search(head);break;
case 4:printf("Goodbye!\n");exit(0);
}
}
clrscr();
}
int menu_select()
{
int ch;
printf("1.Enter the static of the students.\n");
printf("2.Alter the static of the student.\n");
printf("3.Search the static of the student.\n");
printf("4.Quit.\n");
do
{
printf("Make a chioce.");
scanf("%d",&ch);
}while(ch>4 || ch<1);
return(ch);
}
struct student *input()
{
struct student *p1,*p2,*p3,*head;
int i=1,j,k,n=0;
printf("input the static:\n");
p1=p2=(struct student *) malloc (sizeof(struct student));
head=NULL;
printf("num:");
scanf("%s",p1->num);
if(strcmp(p1->num,"0")==0)/*输入0时可以结束*/
goto end;
printf("Chinese score:");
scanf("%f",&p1->Chinese);
printf("English score:");
scanf("%f",&p1->English);
printf("Math score:");
scanf("%f",&p1->Math);
p1->Total=p1->Chinese+p1->English+p1->Math;
p2=p1;
while(strcmp(p1->num,"0")!=0 && i<50)
{
i++;
n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *) malloc (sizeof(struct student));
printf("num:");
scanf("%s",p1->num);
if(strcmp(p1->num,"0")==0)
goto end;
printf("Chinese score:");
scanf("%f",&p1->Chinese);
printf("English score:");
scanf("%f",&p1->English);
printf("Math:");
scanf("%f",&p1->Math);
p1->Total=p1->Chinese+p1->English+p1->Math;
}
end:
p2->next=NULL;
p1=head;
printf("\tNUM\tChinese\tEnglish\tMath\tTotal\n");
while(p1!=NULL)
{
printf("\t%-5s\t%-5.2f\t%-5.2f\t%-5.2f\t%-5.2f\n",p1->num,p1->Chinese,p1->English,
p1->Math,p1->Total);
p1=p1->next;
}
return(head);
}
void alter(struct student *head)
{
struct student *p1,*p2;
char ser[50];
int i,j,k;
if(head==NULL)
printf("zhaobudao xuehao!\n");
else
{
printf("input the number to alter:");
scanf("%s",ser);
p1=p2=head;
while(p1->next!=NULL && (strcmp(ser,p1->num)!=0))
{
p2=p1;
p1=p1->next;
}
if(strcmp(ser,p1->num)==0)
{
printf("Enter the new static:\n");
printf("Chinese:");
scanf("%f",&p1->Chinese);
printf("English:");
scanf("%f",&p1->English);
printf("Math:");
scanf("%f",&p1->Math);
p1->Total=p1->Chinese+p1->English+p1->Math;
}
else
printf("zhaobudao xuehao!");
}
p1=head;
printf("\tNUM\tChinese\tEnglish\tMath\tTotal\n");
while(p1!=NULL)
{
printf("\t%s\t%5.2f\t%5.2f\t%5.2f\t%5.2f\n",p1->num,
p1->Chinese,p1->English,p1->Math,p1->Total);
p1=p1->next;
}
}
void search(struct student *head)
{
struct student *p1;
int i,j;
char ser[50];
printf("input the num to search:");
scanf("%s",ser);
if(head==NULL)
printf("\nzhaobudao xuehao!\n");
p1=head;
while((strcmp(ser,p1->num)!=0) && p1->next!=NULL)
{
p1=p1->next;
}
if(strcmp(ser,p1->num)==0)
{
printf("\tNUM\tChinese\tEnglish\tMath\tTotal\n");
printf("\t%s\t%-5.2f\t%-5.2f\t%-5.2f\t%5.2f\n",p1->num,p1->Chinese,p1->English,p1->Math,p1->Total);
}
else
printf("zhaobudao xuehao!\n");
}
总算做完了,不过看见已经有人给你答案了,择优录用,任君选择吧
第3个回答 2007-12-26
这个程序好像不太难,80分也不低了,不过,最近感冒的挺厉害,头脑不太清楚.不过,记得谭浩强C语言的书,后面结构体那块的例子,你改改应该就可以了的了.