33,311
社区成员
发帖
与我相关
我的任务
分享
void menu()
{
printf("1. 输入学生信息\n");
prinf("2 .
...
printf("0. 退出
...
}
int main()
{
int n;
int over = 0;
while(!over)
{
scanf("%d",n);
switch(n)
{
case 1: input();
break;
case 2:
...
case 0: over = 1; break;
#include<iostream>
#include<iomanip>
using namespace std;
const int consureN=5;//每人的信息量
const int LINE=3;//学生的人数
int score[LINE][consureN];
char zifu[][5]={"学号",
"班级",
"语文",
"数学",
"英语"};
int allscore[LINE];
int pingjun[3];
void main()
{
//Input();
// all();
//paiming();
// pingjunfen();
for(int i=0;i<LINE;i++)
{
for(int j=0;j<consureN;j++)
{
cout<<zifu[j]<<":"<<"\t";
cin>>score[i][j];//输入3个人每个人的信息,没人5条信息,全部为INT型,
//输入第一个学生的存入score[0][0],.....
}
cout<<endl;
}
for (int g=0;g<LINE;g++)
allscore[g] = 0;//全部初始化为0
for(int x=0;x<LINE;x++)
{
for(int j=2;j<consureN;j++)
{
allscore[x]=score[x][j]+allscore[x];//除了学号信息全部相加
}
}
for(int k=0;k<LINE;k++)
pingjun[k]=allscore[k]/(consureN-2);//得到三个人的平均分,赋值给PJ123
for(int s=0;s<LINE;s++)
{
for(int j=s+1;j<LINE;j++)
{
if(allscore[s]<allscore[j])
{
int t;
t=allscore[s];
allscore[s]=allscore[j];
allscore[j]=t;//交换数组,按从大到小排序
}
}
}
cout<<"排名"<<"\t"<<"学号"<<"\t\t"<<"班级"<<"\t"<<"语文"<<"\t"<<"数学"<<"\t"<<"英语"<<"\t"<<"平均分"<<"\t\t"<<"总分"<<endl;
cout<<"********************************************************************************"<<endl;
for(int w=0;w<LINE;w++)
{
int s=0;
cout<<w+1<<"\t"<<score[w][s]<<"\t\t"<<score[w][s+1]<<"\t"<<score[w][s+2]<<"\t"<<score[w][s+3]<<"\t"<<score[w][s+4]<<"\t"<<pingjun[w]<<"\t\t"<<allscore[w]<<endl;
}
}
//建议定义个结构体:
typedef score{
int number;
char name[MAX_NAME_LENTH];
float score1;
float score2;
float score3;
float score4;
}t_score;
//同时还有宏定义:
#define MAX_NAME_LENTH 50
#define MAX_STUDENT 100
//定义一个数组
t_score Student[MAX_STUDENT];
//初始化
memset(Student, 0, MAX_STUDENT*sizeof(t_score));
//输入信息,只是参考
scanf("%d", &(Student[i].number));
scanf("%s", &(Student[i].name));
scanf("%f", &(Student[i].score1));
scanf("%f", &(Student[i].score2));
scanf("%f", &(Student[i].score3));
scanf("%f", &(Student[i].score4));
//求某门成绩的平均分和总分就用循环对某门分数进行累加
//排序的方法一般C语言的书里都有介绍,按照某一门成绩排就行了
//第四个也简单,就循环判断某门成绩是否>=90就行了