谁帮忙编分数给谁。。。简单一个编程题

duliang135 2012-10-06 12:45:43
输出如下面的效果一样。问用户输出几个学生的学号和成绩。回答是3个。就输出3个。第二个方阵是按照学生的学号大小排列的。第三个方阵是按照学生的平均成绩排列的。用到函数和类和数组就好。不要编的那么难我看不懂。。

输出时的例子是:

请问要查看几个学生的成绩: 3
2011123458 45 32 64
2010345782 34 98 100
2009425342 74 64 21

2009425342 74 64 21 53 //最后一个是平均成绩。这个方阵是按照学号的大小排列的
2010345782 34 98 100 73
2011123458 45 32 64 47

2010345782 34 98 100 73 //按照平均成绩的大小排列的。
2009425342 74 64 21 53
2011123458 45 32 64 47

一定要符合我的要求。一共就有10个学生。要求输入1-10的数字。这里我先给出10个学生的学号吧。
2009425342 2010345782 2011123458 2009190190 2009182198 2009190111 2010132938 2010291832 2011293817 2012928173
成绩随意编。从0到100.。
...全文
157 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangxy10 2012-10-07
  • 打赏
  • 举报
回复
好心人还是很多的。
hlphyx 2012-10-07
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
const int y=4; //列数
const int x=10; //行数
class Student
{
public:
void Display(int n);
void StuNum_Sort(int n);
void StuAve_Sort(int n);
void Normal_Sort(int n);
private:
static unsigned int StuNum[x][y] ;
};
void Student::Display(int n)
{
Normal_Sort(n);
cout<<"按学号排列如下:"<<endl;
StuNum_Sort(n);
cout<<"按平均成绩排列如下:"<<endl;
StuAve_Sort(n);
return;
}
void Student::Normal_Sort(int n) //第一方阵
{
for(int i=0;i<n;++i)
{
for(int j=0;j<y;++j)
{
cout<<StuNum[n-i-1][j]<<' ';
}
cout<<endl;
}
return;
}
void Student::StuNum_Sort(int n) //第二方阵,按学号从小到大排列,附加平均成绩
{
unsigned int temp;
unsigned int T[x][y+1],tx=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<4;++j)
{
T[i][j]=StuNum[i][j]; //复制原来数组并扩增一列
if(j>0)
{
tx=T[i][j]+tx;
}
}
T[i][j]=tx/3; //平均成绩在最后一列
tx=0;
}

for(i=0;i<n-1;++i) //根据学号升序排序
{
for(int k=i+1;k<n;++k)
{
int L=0;
if(T[i][L]>T[k][L])
{
for(;L<y+1;++L)
{
temp=T[k][L];
T[k][L]=T[i][L];
T[i][L]=temp;
}

}
}
}
for(i=0;i<n;++i) //显示第二方阵结果
{
for(int j=0;j<y+1;++j)
{
cout<<T[i][j]<<' ';
}
cout<<endl;
}
return;
}
void Student::StuAve_Sort(int n) //第三方阵,按平均成绩从小到大排列
{
unsigned int temp;
unsigned int T[x][y+1],tx=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<4;++j)
{
T[i][j]=StuNum[i][j]; //复制原来数组并扩增一列
if(j>0)
{
tx=T[i][j]+tx;
}
}
T[i][j]=tx/3; //平均成绩在最后一列
tx=0;
}

for(i=0;i<n-1;++i) //根据平均成绩升序排序
{
for(int k=i+1;k<n;++k)
{
int L=y;
if(T[i][L]>T[k][L])
{
for(;L>0;--L)
{
temp=T[k][L];
T[k][L]=T[i][L];
T[i][L]=temp;
}
}
}
}
for(i=0;i<n;++i) //显示第三方阵结果
{
for(int j=0;j<y+1;++j)
{
cout<<T[i][j]<<' ';
}
cout<<endl;
}
return;
}

//静态对象初始化
unsigned int Student::StuNum[x][y]={
{2009425342,33,71,100},
{2010345782,50,20,80},
{2011123458,80,77,90},
{2009190190,64,39,65},
{2009182198,50,78,82},
{2009190111,90,100,99},
{2010132938,49,59,69},
{2010291832,99,89,79},
{2011293817,88,46,81},
{2012928173,78,85,94},
};
void main()
{
Student c;
int n;
cout<<"请问要查看几个学生的成绩:"<<endl;
cin>>n;
c.Display(n);
return;
}
hlphyx 2012-10-07
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
输出如下面的效果一样。问用户输出几个学生的学号和成绩。回答是3个。就输出3个。第二个方阵是按照学生的学号大小排列的。第三个方阵是按照学生的平均成绩排列的。用到函数和类和数组就好。不要编的那么难我看不懂。。

输出时的例子是:

请问要查看几个学生的成绩: 3
2011123458 45 32 64
2010345782 34 98 100
2009425342 74 64 21
……
[/Quote]

<code=C/C++>
#include <iostream>
using namespace std;
const int y=4; //列数
const int x=10; //行数
class Student
{
public:
void Display(int n);
void StuNum_Sort(int n);
void StuAve_Sort(int n);
void Normal_Sort(int n);
private:
static unsigned int StuNum[x][y] ;
};
void Student::Display(int n)
{
Normal_Sort(n);
cout<<"按学号排列如下:"<<endl;
StuNum_Sort(n);
cout<<"按平均成绩排列如下:"<<endl;
StuAve_Sort(n);
return;
}
void Student::Normal_Sort(int n) //第一方阵
{
for(int i=0;i<n;++i)
{
for(int j=0;j<y;++j)
{
cout<<StuNum[n-i-1][j]<<' ';
}
cout<<endl;
}
return;
}
void Student::StuNum_Sort(int n) //第二方阵,按学号从小到大排列,附加平均成绩
{
unsigned int temp;
unsigned int T[x][y+1],tx=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<4;++j)
{
T[i][j]=StuNum[i][j]; //复制原来数组并扩增一列
if(j>0)
{
tx=T[i][j]+tx;
}
}
T[i][j]=tx/3; //平均成绩在最后一列
tx=0;
}

for(i=0;i<n-1;++i) //根据学号升序排序
{
for(int k=i+1;k<n;++k)
{
int L=0;
if(T[i][L]>T[k][L])
{
for(;L<y+1;++L)
{
temp=T[k][L];
T[k][L]=T[i][L];
T[i][L]=temp;
}

}
}
}
for(i=0;i<n;++i) //显示第二方阵结果
{
for(int j=0;j<y+1;++j)
{
cout<<T[i][j]<<' ';
}
cout<<endl;
}
return;
}
void Student::StuAve_Sort(int n) //第三方阵,按平均成绩从小到大排列
{
unsigned int temp;
unsigned int T[x][y+1],tx=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<4;++j)
{
T[i][j]=StuNum[i][j]; //复制原来数组并扩增一列
if(j>0)
{
tx=T[i][j]+tx;
}
}
T[i][j]=tx/3; //平均成绩在最后一列
tx=0;
}

for(i=0;i<n-1;++i) //根据平均成绩升序排序
{
for(int k=i+1;k<n;++k)
{
int L=y;
if(T[i][L]>T[k][L])
{
for(;L>0;--L)
{
temp=T[k][L];
T[k][L]=T[i][L];
T[i][L]=temp;
}
}
}
}
for(i=0;i<n;++i) //显示第三方阵结果
{
for(int j=0;j<y+1;++j)
{
cout<<T[i][j]<<' ';
}
cout<<endl;
}
return;
}

//静态对象初始化
unsigned int Student::StuNum[x][y]={
{2009425342,33,71,100},
{2010345782,50,20,80},
{2011123458,80,77,90},
{2009190190,64,39,65},
{2009182198,50,78,82},
{2009190111,90,100,99},
{2010132938,49,59,69},
{2010291832,99,89,79},
{2011293817,88,46,81},
{2012928173,78,85,94},
};
void main()
{
Student c;
int n;
cout<<"请问要查看几个学生的成绩:"<<endl;
cin>>n;
c.Display(n);
return;
}
</code>
duliang135 2012-10-06
  • 打赏
  • 举报
回复
谁帮忙编。分给谁吧。
newtee 2012-10-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

引用楼主 的回复:
输出如下面的效果一样。问用户输出几个学生的学号和成绩。回答是3个。就输出3个。第二个方阵是按照学生的学号大小排列的。第三个方阵是按照学生的平均成绩排列的。用到函数和类和数组就好。不要编的那么难我看不懂。。

输出时的例子是:

请问要查看几个学生的成绩: 3
2011123458 45 32 64
2010345782 34 98 100
200942534……
[/Quote]如果刚学就多看书
duliang135 2012-10-06
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
输出如下面的效果一样。问用户输出几个学生的学号和成绩。回答是3个。就输出3个。第二个方阵是按照学生的学号大小排列的。第三个方阵是按照学生的平均成绩排列的。用到函数和类和数组就好。不要编的那么难我看不懂。。

输出时的例子是:

请问要查看几个学生的成绩: 3
2011123458 45 32 64
2010345782 34 98 100
2009425342 74 64 21
……
[/Quote]
不是作业。刚学。不懂
JiMoKuangXiangQu 2012-10-06
  • 打赏
  • 举报
回复
作业还是自己做的好啊,别人可以提供帮助,但不能代劳.
Finalcheat 2012-10-06
  • 打赏
  • 举报
回复
作业题?
longburulin 2012-10-06
  • 打赏
  • 举报
回复
先学结构体 再自己写吧
JiMoKuangXiangQu 2012-10-06
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>


#define STUDENT_MAX 10

#define ID_LEN_MAX 10
#define SUBJECT_MAX 10

struct student {
char id[ID_LEN_MAX + 1];
int scores[SUBJECT_MAX];
int score_n;
int total;
int average;
} students[STUDENT_MAX];



static int arr_sum(int arr[], int n);
static int arr_average(int arr[], int n);

static void student_sort_by_id(struct student stus[], int n);
static void student_sort_by_score(struct student stus[], int n);
static void student_print(const struct student *s);



int main(void)
{
int n, sbjn;
int i, j;

printf("请问要查看几个学生的成绩(最多%d个): ", STUDENT_MAX);
scanf("%d", &n); getchar();

printf("请输入科目数(最多%d科): ", STUDENT_MAX);
scanf("%d", &sbjn); getchar();

printf("\n请输入学生的学号和各科成绩(最多%d科,每个学生的数据占一行):\n", SUBJECT_MAX);
for (i = 0; i < n; i++)
{
scanf("%s ", students[i].id);
for (j = 0; j < sbjn; j++)
scanf("%d", &students[i].scores[j]);
getchar();

students[i].score_n = sbjn;
students[i].total = arr_sum(students[i].scores, sbjn);
students[i].average = arr_average(students[i].scores, sbjn);
}

student_sort_by_id(students, n);
printf("\n按学号排序的学生信息:\n");
for (i = 0; i < n; i++)
student_print((const struct student *)&students[i]);

student_sort_by_score(students, n);
printf("\n按成绩排序的学生信息:\n");
for (i = 0; i < n; i++)
student_print((const struct student *)&students[i]);

return 0;
}



static int id_cmp_func(const void *a, const void *b);
static int score_cmp_func(const void *a, const void *b);

static void student_sort_by_id(struct student stus[], int n)
{
qsort((void *)stus, n, sizeof(struct student), id_cmp_func);
}

static int id_cmp_func(const void *a, const void *b)
{
const struct student *sa, *sb;

assert(a && b);

sa = (const struct student *)a;
sb = (const struct student *)b;
return strcmp(sa->id, sb->id);
}

static void student_sort_by_score(struct student stus[], int n)
{
qsort((void *)stus, n, sizeof(struct student), score_cmp_func);
}

static int score_cmp_func(const void *a, const void *b)
{
const struct student *sa, *sb;

assert(a && b);

sa = (const struct student *)a;
sb = (const struct student *)b;

if (sa->total > sb->total)
return -1;
else if (sa->total == sb->total)
return 0;
else
return 1;
}

static void student_print(const struct student *s)
{
int i;

assert(s);

printf("%s ", s->id);
for (i = 0; i < s->score_n; i++)
printf("%d ", s->scores[i]);
printf("%d\n", s->average);
}

static int arr_sum(int arr[], int n)
{
int sum;
int i;

sum = 0;
for (i = 0; i < n; i++)
sum += arr[i];
return sum;
}

static int arr_average(int arr[], int n)
{
int sum;
int i;

sum = 0;
for (i = 0; i < n; i++)
sum += arr[i];
return (sum / n);
}


写得不严谨,基本能满足你的要求了.

64,281

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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