帮我看下这段代码如何写

yuewei1231 2008-06-15 03:40:37
运行环境:TC
问题描述: 如何求各科平均分级总分的平均分
下面的代码 有问题的地方我都描述出来了 希望大家帮我参考下 看看该如何写完
代码如下
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define LEN sizeof(struct student)
#define HEADER "\nnumber\tname\tsex\tage\tmath computer english score\n"
#define FORMAT "%ld\t%s\t%s\t%d\t%-3g\t %-3g\t %-3g\t%2.0f\n"
#define DATE p->num,p->name,p->sex,p->age,p->math,p->computer,p->english,p->score=p->math+p->computer+p->english
struct student *insert(struct student *head,struct student *stud);
struct student
{
long num;
char name[15];
char sex[7];
int age;
float math;
float computer;
float english;
float score;
struct student *next;
};
int n;
void mainmenu(void);
struct student *creat(void);
void input(struct student *stu);
void print(struct student *head) ;
struct student *sort_avgen(struct student *head,int n);
struct student *sort_avgma(struct student *head,int n);
struct student *sort_avgco(struct student *head,int n);
struct student *sort_avgso(struct student *head,int n);
main()
{
struct student *head,*stu;
long del_num,search_num;
int i;
int have=0;
int flag;
char c,t1,t2,t3,k;
char search_name[15];
system("cls");
enter();
do {
flag=0;
window(1,1,80,25);
system("cls");
mainmenu();
do {
t1=getch();
}while(t1<'1'||t1>'7');
window(1,1,80,25);
clrscr();
switch(t1)
{
case'1':
printf("Please input records(It will be end if the number is 0):\n");
head=creat();
print(head);
have=1;
getch();
break;

case'2':
for(;;) {
system("cls");
window(34,8,48,10);
textcolor(14);
cprintf("1)By math.");
window(34,10,48,12);
cprintf("2)By Computer.");
window(34,12,48,14);
cprintf("3)By English.");
window(34,14,48,16);
cprintf("4)total Score.");
window(34,16,48,18);
cprintf("5)Back.");
do {
t2=getch();
}while(t2<'1'||t2>'6');
system("cls");
window(1,1,80,25);
textcolor(2);
switch(t2)
{
case '1': /*底下这样调用对不对???*/ /*求平均分*/
sort_avgma(head,n);
print(head);
getch();
break;
case'2':
sort_avgco(head,n);
print(head);
getch();
break;
case'3':
sort_avgen(head,n);
print(head);
getch();
break;
case'4':
sort_avgso(head,n);
print(head);
getch();
break;

case'5':
flag=1;break;
}
if(flag) break;
}
break;
}while(t1!='0');
}




void mainmenu(void) /*创建主菜单*/
{ window(15,7,67,9);
textcolor(12);
cprintf("1)");
textcolor(2);
cprintf("Creat a new manage system of student's grade.");
window(15,15,67,17);
textcolor(12);
cprintf("2)");
textcolor(2);
cprintf("Score."); /*求平均分*/

}

struct student *creat(void) /*建立一个数据输入的链表*/
{
struct student *head;
struct student *p1,*p2;
int i;
n=0; /*n是结点个数*/
p1=p2=(struct student*)malloc(LEN);
input(p1);
head=NULL;
while(p1->num!=0) { /*当输入的学号为0时数据输入完毕*/
n+=1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
input(p1);
}
p2->next=NULL;
return head;
}

void input(struct student *stu) /*一个被反复调用的数据输入函数*/
{
float s1,s2,s3;
printf("No:");
scanf("%ld",&stu->num);
if(stu->num!=0) {
getchar();
printf("Name:");
gets(stu->name);
printf("Sex(male or female):");
gets(stu->sex);
printf("Age:");
scanf("%d",&stu->age);
printf("math:");
scanf("%f",&s1);
stu->math=s1;
printf("Computer:");
scanf("%f",&s2);
stu->computer=s2;
printf("English:");
scanf("%f",&s3);
stu->english=s3;
getchar();

}
}
void print(struct student *head) /*打印成绩*/
{
struct student *p;
clrscr();
printf(HEADER);
p=head;
if(head!=NULL)
do {
printf(FORMAT,DATE);
p=p->next;

}while(p!=NULL);
}





/*如何写底下的求平均分函数???*/
...全文
147 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuewei1231 2008-06-15
  • 打赏
  • 举报
回复
没人解决??

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧