我是接触C语言没多久的大一学生,请多加一些中文注释
300è¡è¿ç®ååï¼åµåµï¼ä½ èªå·±å»Cè¯è¨ä»£ç åºæ¾æ¾åï¼åºè¯¥æä½ æ³è¦ç#include <stdio.h>
#include <stdlib.h>
#include <string.h>struct STU
{
long Num;
int mathScore;
int englishScore;
int computerScore;
int allScore;
int averageScore;
};void sort();
void cal();
void stuPrint();
void stuInput();
#define STUNUM 60/*å®ä¹å¦çæ°*/STU stu[STUNUM];int main(int argc, char* argv[])
{
stuInput();
cal();
sort();
stuPrint(); return 0;
}void stuInput()
{
int i = 0;
for (;i<STUNUM;i++)
{
system("cls");
printf("请ä¸ä¸ªå¦çè¾å ¥å¦å·\n");
scanf("%d",&(stu[i].Num));
printf("请è¾å ¥è¯¥å¦çæ°å¦æ绩\n");
scanf("%d",&(stu[i].mathScore));
printf("请è¾å ¥è¯¥å¦çè±è¯æ绩\n");
scanf("%d",&(stu[i].englishScore));
printf("请è¾å ¥è¯¥å¦ç计ç®æºæ绩\n");
scanf("%d",&(stu[i].computerScore));
}
}void cal()
{
int i = 0;
for (;i<STUNUM;i++)
{
stu[i].allScore = stu[i].mathScore + stu[i].computerScore + stu[i].englishScore;
stu[i].averageScore = stu[i].allScore / 3;
}
}void sort()
{
STU temp;
int i = 0 , j =0;
for (;i<STUNUM-1;i++)
{
for ( j = i+1;j< STUNUM ;j++)
{
if (stu[i].allScore<stu[j].allScore)
{
memcpy(&temp,&stu[i],sizeof(STU));
memcpy(&stu[i],&stu[j],sizeof(STU));
memcpy(&stu[j],&temp,sizeof(STU));
}
}
}
}void stuPrint()
{
int i = 0;
printf("å次 å¦å· æ°å¦æ绩 è±è¯æ绩 计ç®æºæ绩 æ»æ绩 å¹³åæ绩\n");
for (;i<STUNUM;i++)
{
printf("\n---------------------------------------------------------\n");
printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\n",i+1,stu[i].Num,stu[i].mathScore,
stu[i].englishScore,stu[i].computerScore,
stu[i].allScore,stu[i].averageScore);
}}
#include <stdlib.h>
#include <string.h>struct STU
{
long Num;
int mathScore;
int englishScore;
int computerScore;
int allScore;
int averageScore;
};void sort();
void cal();
void stuPrint();
void stuInput();
#define STUNUM 60/*å®ä¹å¦çæ°*/STU stu[STUNUM];int main(int argc, char* argv[])
{
stuInput();
cal();
sort();
stuPrint(); return 0;
}void stuInput()
{
int i = 0;
for (;i<STUNUM;i++)
{
system("cls");
printf("请ä¸ä¸ªå¦çè¾å ¥å¦å·\n");
scanf("%d",&(stu[i].Num));
printf("请è¾å ¥è¯¥å¦çæ°å¦æ绩\n");
scanf("%d",&(stu[i].mathScore));
printf("请è¾å ¥è¯¥å¦çè±è¯æ绩\n");
scanf("%d",&(stu[i].englishScore));
printf("请è¾å ¥è¯¥å¦ç计ç®æºæ绩\n");
scanf("%d",&(stu[i].computerScore));
}
}void cal()
{
int i = 0;
for (;i<STUNUM;i++)
{
stu[i].allScore = stu[i].mathScore + stu[i].computerScore + stu[i].englishScore;
stu[i].averageScore = stu[i].allScore / 3;
}
}void sort()
{
STU temp;
int i = 0 , j =0;
for (;i<STUNUM-1;i++)
{
for ( j = i+1;j< STUNUM ;j++)
{
if (stu[i].allScore<stu[j].allScore)
{
memcpy(&temp,&stu[i],sizeof(STU));
memcpy(&stu[i],&stu[j],sizeof(STU));
memcpy(&stu[j],&temp,sizeof(STU));
}
}
}
}void stuPrint()
{
int i = 0;
printf("å次 å¦å· æ°å¦æ绩 è±è¯æ绩 计ç®æºæ绩 æ»æ绩 å¹³åæ绩\n");
for (;i<STUNUM;i++)
{
printf("\n---------------------------------------------------------\n");
printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\n",i+1,stu[i].Num,stu[i].mathScore,
stu[i].englishScore,stu[i].computerScore,
stu[i].allScore,stu[i].averageScore);
}}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2013-07-27
#include <stdio.h> #define N 50 #include<string.h>#define USER "admin"#define PASSWORD "12345678"#include<stdio.h>#define MAX 10
int NUM; int x; //全局变量 struct student { int number; char name[20]; float score[3]; float ave; float sum;
}stu[N]; void suan(int ); void insert(int );void display(struct student *p,int n ); void paixu(struct student stu[],int n); void add( int n); void del(struct student *p,int n ); void tui(int ); void password(); void pingjunfenpaixu(struct student stu[],int n);void zongfenpaixu(struct student stu[],int n);
void main() { int i=0;
printf("\n\n 欢迎使用学生成绩管理系统 \n");password();suan(x);
} void suan(int i) { char x; printf(" \n\n 1、输入学员信息 \n"); printf(" \n\n 2、增加学员信息 \n"); printf(" \n\n 3、删除学员信息 \n"); printf(" \n\n 4、显示学员信息 \n"); printf(" \n\n 5、排序学员信息 \n"); printf(" \n\n 6、 退出 \n"); printf("\n 请输入选项:"); scanf("%d",&x); switch (x) { case 1: { insert(i); //调用函数
break; } case 2: { add(NUM);
break; } case 3: { del(stu,NUM); break; } case 4: { display(stu,NUM); break; } case 5: { paixu(stu,NUM);
break; } case 6: { tui(NUM);break; }default: printf("\n输入有误\n\n"); }
} void insert(int i) { int j; float sum; char ch; do { sum=0; printf("\n请输入学员信息:\n"); printf("\n学号:"); scanf("%d",&stu[i].number); printf("\n姓名:"); scanf("%s",&stu[i].name); printf("\n三门成绩:\n");
for (j=0;j<3;j++) { printf("\n成绩%d:",j+1); scanf("%f",&stu[i].score[j]); sum+=stu[i].score[j]; stu[i].sum = stu[i].score[0]+stu[i].score[1]+stu[i].score[2]; } stu[i].ave=sum/3; i++; printf("\n是否继续输入学员信息?(y/n)"); fflush(stdin); ch=getchar(); }while(ch=='y' || ch=='Y'); NUM=i; suan(x); } void display(struct student *p,int n) { int i; printf("\n学号\t姓名\t成绩1\t成绩2\t成绩3\t平均分:总分:\n"); for (i=0;i<n;i++,p++) { printf("%d\t%s\t%5.1f\t%5.1f\t%5.1f\t%5.1f\t%5.1f\n",p->number,p->name,p->score[0],p->score[1],p->score[2],p->ave,p->sum); }
suan(x);} void paixu(struct student stu[],int n){char x;printf(" \n\n 1、平均成绩排序 \n"); printf(" \n\n 2、总分成绩排序 \n"); printf("\n 请输入选项:"); scanf("%d",&x);switch(x){case 1:{pingjunfenpaixu(stu,NUM);break;}case 2:{zongfenpaixu(stu,NUM);break;}default:{printf("请重新输入");<br>} }}
void pingjunfenpaixu(struct student stu[],int n){float temp; int i,j; for (i=0;i<n;i++) { for (j=0;j<n-i-1;j++) { if (stu[j].ave<stu[j+1].ave) { temp=stu[j+1].ave; stu[j+1].ave=stu[j].ave; stu[j].ave=temp; display(stu,NUM); <br>}}}}void zongfenpaixu(struct student stu[],int n){float temp; int i,j; for (i=0;i<n;i++) { for (j=0;j<n-i-1;j++) { if (stu[j].ave<stu[j+1].sum) { temp=stu[j+1].sum; stu[j+1].sum=stu[j].sum; stu[j].sum=temp; <br>display(stu,NUM); }}}}
void add(int n) { char ch; printf("\n是否需要插入新学员信息?(y/n)"); fflush(stdin); ch=getchar(); if (ch=='y' || ch=='Y') { insert(n); } suan(x); }
void del(struct student stu[],int n) { int num,i=0,j=0; char ch; printf("\n是否需要删除学员信息?(y/n)"); fflush(stdin); ch=getchar(); while (ch=='y' ||ch=='Y') { printf("\n请输入删除学员的学号:"); scanf("%d",&num); for (i=0;i<n;i++) { if (num==stu[i].number) break; } if (i<n) { for (j=i;j<n;j++) { stu[j]=stu[j+1]; } n--; printf("\n删除后的学员信息如下:\n"); display(stu,n); } else printf("\n对不起,没有这个学号!\n"); if (n==0) break; printf("\n是否要继续删除学员信息?(y/n)"); fflush(stdin); ch=getchar(); } suan(x);
}
void tui(int i) { char ch; printf("\n退出?(y/n):"); fflush(stdin); ch=getchar(); if (ch=='y' || ch=='Y') { printf("\t----------------------------------------------------------------------\n");printf("\t***************************@@*********@@******************************\n");printf("\t************************@@****@@***@@****@@***************************\n");printf("\t*********************@@**********@**********@@************************\n");printf("\t********************@*************************@***********************\n");printf("\t* @@ @@ *\n");printf("\t* @@ 谢谢使用本程序 @@ *\n");printf("\t***************************@@**********@@*****************************\n");printf("\t******************************@@****@@********************************\n");printf("\t*********************************@@***********************************\n");printf("\t----------------------------------------------------------------------\n");} else { suan(x);
} }
void password() {
char name[21];char pw[11];int i;for(i=0;i<3;i++){printf("\nEnter User name: ");gets(name);printf("\nEnter password :");gets(pw);if((strcmp(name,USER)==0)&&(strcmp(pw,PASSWORD)==0))break;}if(i>2){printf("您已连续3次将用户名或密码输错,系统将退出!");<br>}
else{
}}
int NUM; int x; //全局变量 struct student { int number; char name[20]; float score[3]; float ave; float sum;
}stu[N]; void suan(int ); void insert(int );void display(struct student *p,int n ); void paixu(struct student stu[],int n); void add( int n); void del(struct student *p,int n ); void tui(int ); void password(); void pingjunfenpaixu(struct student stu[],int n);void zongfenpaixu(struct student stu[],int n);
void main() { int i=0;
printf("\n\n 欢迎使用学生成绩管理系统 \n");password();suan(x);
} void suan(int i) { char x; printf(" \n\n 1、输入学员信息 \n"); printf(" \n\n 2、增加学员信息 \n"); printf(" \n\n 3、删除学员信息 \n"); printf(" \n\n 4、显示学员信息 \n"); printf(" \n\n 5、排序学员信息 \n"); printf(" \n\n 6、 退出 \n"); printf("\n 请输入选项:"); scanf("%d",&x); switch (x) { case 1: { insert(i); //调用函数
break; } case 2: { add(NUM);
break; } case 3: { del(stu,NUM); break; } case 4: { display(stu,NUM); break; } case 5: { paixu(stu,NUM);
break; } case 6: { tui(NUM);break; }default: printf("\n输入有误\n\n"); }
} void insert(int i) { int j; float sum; char ch; do { sum=0; printf("\n请输入学员信息:\n"); printf("\n学号:"); scanf("%d",&stu[i].number); printf("\n姓名:"); scanf("%s",&stu[i].name); printf("\n三门成绩:\n");
for (j=0;j<3;j++) { printf("\n成绩%d:",j+1); scanf("%f",&stu[i].score[j]); sum+=stu[i].score[j]; stu[i].sum = stu[i].score[0]+stu[i].score[1]+stu[i].score[2]; } stu[i].ave=sum/3; i++; printf("\n是否继续输入学员信息?(y/n)"); fflush(stdin); ch=getchar(); }while(ch=='y' || ch=='Y'); NUM=i; suan(x); } void display(struct student *p,int n) { int i; printf("\n学号\t姓名\t成绩1\t成绩2\t成绩3\t平均分:总分:\n"); for (i=0;i<n;i++,p++) { printf("%d\t%s\t%5.1f\t%5.1f\t%5.1f\t%5.1f\t%5.1f\n",p->number,p->name,p->score[0],p->score[1],p->score[2],p->ave,p->sum); }
suan(x);} void paixu(struct student stu[],int n){char x;printf(" \n\n 1、平均成绩排序 \n"); printf(" \n\n 2、总分成绩排序 \n"); printf("\n 请输入选项:"); scanf("%d",&x);switch(x){case 1:{pingjunfenpaixu(stu,NUM);break;}case 2:{zongfenpaixu(stu,NUM);break;}default:{printf("请重新输入");<br>} }}
void pingjunfenpaixu(struct student stu[],int n){float temp; int i,j; for (i=0;i<n;i++) { for (j=0;j<n-i-1;j++) { if (stu[j].ave<stu[j+1].ave) { temp=stu[j+1].ave; stu[j+1].ave=stu[j].ave; stu[j].ave=temp; display(stu,NUM); <br>}}}}void zongfenpaixu(struct student stu[],int n){float temp; int i,j; for (i=0;i<n;i++) { for (j=0;j<n-i-1;j++) { if (stu[j].ave<stu[j+1].sum) { temp=stu[j+1].sum; stu[j+1].sum=stu[j].sum; stu[j].sum=temp; <br>display(stu,NUM); }}}}
void add(int n) { char ch; printf("\n是否需要插入新学员信息?(y/n)"); fflush(stdin); ch=getchar(); if (ch=='y' || ch=='Y') { insert(n); } suan(x); }
void del(struct student stu[],int n) { int num,i=0,j=0; char ch; printf("\n是否需要删除学员信息?(y/n)"); fflush(stdin); ch=getchar(); while (ch=='y' ||ch=='Y') { printf("\n请输入删除学员的学号:"); scanf("%d",&num); for (i=0;i<n;i++) { if (num==stu[i].number) break; } if (i<n) { for (j=i;j<n;j++) { stu[j]=stu[j+1]; } n--; printf("\n删除后的学员信息如下:\n"); display(stu,n); } else printf("\n对不起,没有这个学号!\n"); if (n==0) break; printf("\n是否要继续删除学员信息?(y/n)"); fflush(stdin); ch=getchar(); } suan(x);
}
void tui(int i) { char ch; printf("\n退出?(y/n):"); fflush(stdin); ch=getchar(); if (ch=='y' || ch=='Y') { printf("\t----------------------------------------------------------------------\n");printf("\t***************************@@*********@@******************************\n");printf("\t************************@@****@@***@@****@@***************************\n");printf("\t*********************@@**********@**********@@************************\n");printf("\t********************@*************************@***********************\n");printf("\t* @@ @@ *\n");printf("\t* @@ 谢谢使用本程序 @@ *\n");printf("\t***************************@@**********@@*****************************\n");printf("\t******************************@@****@@********************************\n");printf("\t*********************************@@***********************************\n");printf("\t----------------------------------------------------------------------\n");} else { suan(x);
} }
void password() {
char name[21];char pw[11];int i;for(i=0;i<3;i++){printf("\nEnter User name: ");gets(name);printf("\nEnter password :");gets(pw);if((strcmp(name,USER)==0)&&(strcmp(pw,PASSWORD)==0))break;}if(i>2){printf("您已连续3次将用户名或密码输错,系统将退出!");<br>}
else{
}}
第2个回答 2013-07-27
给你个300字的程序,你估计也看不太懂,实际效用不大,还是找本C语言的书看看吧,再多加练习就好,有什么不懂的可以问我,本人QQ314156403
第3个回答 2013-07-27
请问你要这程序时做什么的?学习?还是应付作业?