十字星编程c语言,·c语言编程.5个学生的数据

满意答案

02ae427d08e371d7e90d5b995e828d6d.png

zxq1981n

2014.05.02

02ae427d08e371d7e90d5b995e828d6d.png

采纳率:45%    等级:12

已帮助:7619人

#include

#include

#include

#define N 3

typedef struct stu{

unsigned int num;

char name[20];

int math;

int english;

int computer;

float average;

}STUDENT;

int menu()

{

int choice;

clrscr();

gotoxy(10,20);

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

printf("\n* Class score process Program *");

printf("\n* *");

printf("\n* 1. Input everyone's score *");

printf("\n* 2. Calculate average of everyone *");

printf("\n* 3. Sort by average *");

printf("\n* 4. Output to file *");

printf("\n* 5. Exit *");

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

printf("\nPlease input your choice:");

scanf("%d",&choice);

return(choice);

}

void Input(STUDENT *p,int n)

{ int i;

printf("\nPlease input info of students:No Name Math English Computer\n");

for (i=0; i

printf("\n%d:",i+1);

scanf("%u%s%d%d%d",&((p+i)->num),(p+i)->name,&((p+i)->math),&((p+i)->english),&((p+i)->computer));

}

}

void Count(STUDENT *p,int n)

{ int i;

printf("\nAverage score of students:\n");

for (i=0; i

printf("\n%d:",i+1);

(p+i)->average=((p+i)->math+(p+i)->english+(p+i)->computer)/3.0;

printf("%.3f",(p+i)->average);

}

getch();

}

void Sort(STUDENT *p,int n)

{

int i,j;

STUDENT *temp;

for (i=0; i

for(j=i+1; j

if ((p+i)->average < (p+j)->average) {

*temp=*(p+i); *(p+i)=*(p+j);*(p+j)=*temp;

}

}

printf("\nResult of sort.");

for (i=0; i

printf("\n%-3d %s %-3d %-7d %-8d %-.2f",(p+i)->num,(p+i)->name,

(p+i)->math,(p+i)->english,(p+i)->computer,(p+i)->average);

getch();

}

int Output(STUDENT *p,int n)

{ int i;

FILE *fp;

printf("\nOut put to file...");

fp=fopen("d:\\cxh_tc\\sy5.dat","w");

if (fp==NULL) { printf("\nOpen file error.Exit!"); return(0); }

fprintf(fp,"%s"," Class Score Table \n\n");

fprintf(fp,"%s","Num Name Math English Computer Average 名次 \n");

for (i=0; i

fprintf(fp, "%-3d %s %-d %-d %-d %-.2f %d\n",(p+i)->num,(p+i)->name,

(p+i)->math,(p+i)->english,(p+i)->computer,(p+i)->average,i+1);

}

fclose(fp);

getch();

return 1;

}

void main()

{

STUDENT myclass[N],*p;

int flag=1,choice;

p=myclass;

while (flag) {

choice=menu();

clrscr();

switch(choice) {

case 1: Input(p,N); break;

case 2: Count(p,N); break;

case 3: Sort(p,N); break;

case 4: Output(p,N); break;

case 5:

default: flag=0; break;

}

}

}

00分享举报

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值