C语言程序 统计成绩并拍名次 怎么写程序 用C不用C++ 30
70个学生分别统计3门功课的优秀良中及格不及格人数低于30不能补考统计补考人数不能补考人数求出每个同学平均成绩精确小数点后一位对70名同学的成绩排序注意并列名次学生的名字...
70个学生分别统计3门功课的 优秀 良 中 及格 不及格 人数
低于30不能补考 统计补考人数 不能补考人数
求出每个同学 平均成绩 精确小数点后一位
对70名同学的成绩排序 注意并列名次
学生的名字用如下方法随即产生
char f_name[4][3]={“赵”,“钱”,“孙”,“李”}
char s_name[][]={}
char cname[20]
for(int j=0;j<4;j++)
for(int k=0;k<5;k++)
cname[j*k+k]=strcat(f_name[j],s_name[k])
好的可以另加分 展开
低于30不能补考 统计补考人数 不能补考人数
求出每个同学 平均成绩 精确小数点后一位
对70名同学的成绩排序 注意并列名次
学生的名字用如下方法随即产生
char f_name[4][3]={“赵”,“钱”,“孙”,“李”}
char s_name[][]={}
char cname[20]
for(int j=0;j<4;j++)
for(int k=0;k<5;k++)
cname[j*k+k]=strcat(f_name[j],s_name[k])
好的可以另加分 展开
1个回答
展开全部
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
//
int const N=70;
struct Boy{
char name[20];
int c1;
int c2;
int c3;
};
typedef struct Boy boy;
boy classmate[N];
char *names[]={"Charles","Mark","Bill","Vincent","William","Joseph"
,"James","Henry","Gary","Martin","Fred","Gary","William",
"Charles","Michael","Karl","Bob","John","Thomas","Dean",
"Paul","Jack","Brooke","Kevin","Louis","John","George",
"Henry","Benjamin","Robert","Carl","Scott","Tom","Eddy",
"Kris","Peter","Johnson","Bruce","Robert","Peter","Bill",
"Joseph","John","Burt","Charlie","Elliot","George","Johnson",
"Richard","James","Charles","Bruce","David","Nick","Walt",
"John","Mark","Sam","Davis","Neil","Carl","Lewis","Billy",
"Richard","Howard","Allen","Johnny","Robert","Martin","Jeff",
"Paul","Sam","Francis","Lewis","Stephen","Andy","Scott","Albert",
"Kevin","Michael","Taylor","Jackson","Jack","Jimmy","Allen",
"Martin","Vincent"};
void s(int s,int c);
void initname(boy * mem,int num);
void initscore(boy * mem,int num);
void count (boy * mem,int n);
static struct {
int good;
int med;
int ok;
int bad;
int out;
} stat[3];
int main(int argc, char *argv[]){
initname(classmate,N);
initscore(classmate,N);
count (classmate,N);
printf("%5s%5s%5s%5s%5s%5s\n","","good","med","ok","bad","out");
printf("%-5s%5d%5d%5d%5d%5d\n","c1:",
stat[0].good, stat[0].med,
stat[0].ok,stat[0].bad,
stat[0].out );
printf("%-5s%5d%5d%5d%5d%5d\n","c2:",
stat[1].good, stat[1].med,
stat[1].ok,stat[1].bad,
stat[1].out );
printf("%-5s%5d%5d%5d%5d%5d\n","c3:",
stat[2].good, stat[2].med,
stat[2].ok,stat[2].bad,
stat[2].out );
system("PAUSE");
return EXIT_SUCCESS;
}
void initname(boy * mem,int num){
int i=0;
char **np=names;
for (;i<num;i++){
strcpy ( (mem++)->name,*(np++));
}
}
void initscore(boy * mem,int num){
//初始化成绩,完全随机。
int i=0;
int n=100;
srand( time(NULL) );
for ( i=0; i<num; i++ ){
mem->c1=(int)(n*rand()/(RAND_MAX+1.0));
mem->c2=(int)(n*rand()/(RAND_MAX+1.0));
mem->c3=(int)(n*rand()/(RAND_MAX+1.0));
mem++;
}
}
void count (boy * mem,int n){
// >=85 good
// >=70 med
// >=60 ok
// >=30 bad
// <30 out
int i;
for ( i=0; i<n; i++ ){
printf("%d %d %d\n",mem->c1,mem->c2,mem->c3);
s(mem->c1,0);
s(mem->c2,1);
s(mem->c3,2);
mem++;
}
}
void s(int s,int c){
// >=85 good
// >=70 med
// >=60 ok
// >=30 bad
// <30 out
if (s>=85){
stat[c].good++;
}
else if(s>=70){
stat[c].med++;
}
else if(s>=60){
stat[c].ok++;
}
else if(s>=30){
stat[c].bad++;
}
else {
stat[c].out++;
}//endif
}
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
//
int const N=70;
struct Boy{
char name[20];
int c1;
int c2;
int c3;
};
typedef struct Boy boy;
boy classmate[N];
char *names[]={"Charles","Mark","Bill","Vincent","William","Joseph"
,"James","Henry","Gary","Martin","Fred","Gary","William",
"Charles","Michael","Karl","Bob","John","Thomas","Dean",
"Paul","Jack","Brooke","Kevin","Louis","John","George",
"Henry","Benjamin","Robert","Carl","Scott","Tom","Eddy",
"Kris","Peter","Johnson","Bruce","Robert","Peter","Bill",
"Joseph","John","Burt","Charlie","Elliot","George","Johnson",
"Richard","James","Charles","Bruce","David","Nick","Walt",
"John","Mark","Sam","Davis","Neil","Carl","Lewis","Billy",
"Richard","Howard","Allen","Johnny","Robert","Martin","Jeff",
"Paul","Sam","Francis","Lewis","Stephen","Andy","Scott","Albert",
"Kevin","Michael","Taylor","Jackson","Jack","Jimmy","Allen",
"Martin","Vincent"};
void s(int s,int c);
void initname(boy * mem,int num);
void initscore(boy * mem,int num);
void count (boy * mem,int n);
static struct {
int good;
int med;
int ok;
int bad;
int out;
} stat[3];
int main(int argc, char *argv[]){
initname(classmate,N);
initscore(classmate,N);
count (classmate,N);
printf("%5s%5s%5s%5s%5s%5s\n","","good","med","ok","bad","out");
printf("%-5s%5d%5d%5d%5d%5d\n","c1:",
stat[0].good, stat[0].med,
stat[0].ok,stat[0].bad,
stat[0].out );
printf("%-5s%5d%5d%5d%5d%5d\n","c2:",
stat[1].good, stat[1].med,
stat[1].ok,stat[1].bad,
stat[1].out );
printf("%-5s%5d%5d%5d%5d%5d\n","c3:",
stat[2].good, stat[2].med,
stat[2].ok,stat[2].bad,
stat[2].out );
system("PAUSE");
return EXIT_SUCCESS;
}
void initname(boy * mem,int num){
int i=0;
char **np=names;
for (;i<num;i++){
strcpy ( (mem++)->name,*(np++));
}
}
void initscore(boy * mem,int num){
//初始化成绩,完全随机。
int i=0;
int n=100;
srand( time(NULL) );
for ( i=0; i<num; i++ ){
mem->c1=(int)(n*rand()/(RAND_MAX+1.0));
mem->c2=(int)(n*rand()/(RAND_MAX+1.0));
mem->c3=(int)(n*rand()/(RAND_MAX+1.0));
mem++;
}
}
void count (boy * mem,int n){
// >=85 good
// >=70 med
// >=60 ok
// >=30 bad
// <30 out
int i;
for ( i=0; i<n; i++ ){
printf("%d %d %d\n",mem->c1,mem->c2,mem->c3);
s(mem->c1,0);
s(mem->c2,1);
s(mem->c3,2);
mem++;
}
}
void s(int s,int c){
// >=85 good
// >=70 med
// >=60 ok
// >=30 bad
// <30 out
if (s>=85){
stat[c].good++;
}
else if(s>=70){
stat[c].med++;
}
else if(s>=60){
stat[c].ok++;
}
else if(s>=30){
stat[c].bad++;
}
else {
stat[c].out++;
}//endif
}
追问
没有那个 名次的排序啊
追答
给你的代码我编译过了,xp sp3 32 bit ,dev c++ 4.9.9.2.
void sort_print(boy* mem,int num){
qsort(classmate,N,sizeof(boy),cmp);
int i=0;
printf("\n\n%10s%5s%5s%5s%5s\n","name","c1","c2","c3","sum");
for (;isum > a2->sum)
return 1;
if (a1->sum sum)
return -1;
return 0;
}
你加上这两个函数。调用sort_print(classmate,N);就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询