实验题目:
输入一个班N个学生(N为符号常量,自定人数)的学号和每个学生考试三门功课(数学、英语、计算机基础)的成绩。编程计算出每个学生的总分和平均分,并按学生成绩优劣排序,最后打印一张按高分到低分名次排序的成绩单。要求:
1)排序用一个函数实现。
2)打印的成绩单表项包括:序号,学号、数学、英语、计算机、总分、平均分。
3)按实验报告电子模板格式填写实验内容。
可用多个函数或多个源文件实现
可以用数组法、指针法、结构体法编写程序。
源程序清单:
主要标识符说明:(说明变量、函数、指针、结构体等)
实验结果贴图:
实验环境:
intel Pentium 4 计算机,windowsXP操作系统,Microsoft Visual C++ 6编译环境。
你太牛了,如果光是程序我可以帮你写,但是还有其他的一大堆,哎! 程序我写好了,给我个邮箱 ,直接给你贴出来吧,已经通过调试。
#include "stdio.h"
#include "stdlib.h"
class Student
{
public:
int id;
int eng;
int math;
int computer;
double avg;
double total;
Student(){id=-1;eng=-1;;math=-1;computer=-1;avg=-1;total=-1;};
double Aveage()
{
return avg=(double)(eng+math+computer)/(double)3;
};
double Sum()
{
return total=(double)(eng+math+computer);
};
};
void EX(Student*A,Student*B)
{
Student temp;
temp=*A;
*A=*B;
*B=temp;
}
void PX(Student* A,int s)
{
Student* R=new Student[s];
for(int i=0;i<s;i++)
{
for(int j=i+1;j<s;j++)
{
if((A+i)->avg<(A+j)->avg)
EX(A+i,A+j);
}
}
};
void main()
{
int s=-1;
printf("请输入学生个数\n");
scanf("%d",&s);
Student *all=new Student[s];
printf("eng,math,computer\n");
for(int i=0;i<s;i++)
{
scanf("%d %d %d",&(all+i)->eng,&(all+i)->math,&(all+i)->computer);//输入以空格为间隔以回车为确定
(all+i)->Aveage();(all+i)->Sum();(all+i)->id=i+1;
}
PX(all,s);
printf("ID,eng,math,computer,avg,total\n");
for(int j=0;j<s;j++)
{
printf("%d,%d,%d,%d,%2.2f,%d\n",(all+j)->id,(all+j)->eng,(all+j)->math,(all+j)->computer,(all+j)->avg,(all+j)->total);
}
}