您的位置:首页 > 其它

第五周上机指导--任务4--设计一个学生类,建立一个对象数组,内放5个学生的数据

2012-03-19 22:39 549 查看
/* (程序头部注释开始)

* 程序的版权和版本声明部分

* Copyright (c) 2011, 烟台大学计算机学院学生

* All rights reserved.

* 文件名称: 设计一个学生类,包括学号(num)和成绩(score)。建立一个对象数组,内放5个学生的数据。

* 作 者: 雷恒鑫

* 完成日期: 2012 年 03 月 20 日

* 版 本 号: V1.0

* 对任务及求解方法的描述部分

* 输入描述:

* 问题描述:

* 程序输出:

* 程序头部的注释结束

*/

#include <iostream>
#include<Cmath>
#include <iomanip>
using namespace std;
class student
{
public: 
	student(int,float);
	void output_score(student *a);
	void get_max_score(student *a);
private: 
	int num;
	int score;
	
};
int main(void)
{
	student a[5]={student(1001,98),student(1002,99),student(1003,89),student(1004,100),student(1005,98)};
	student *p;
	p=a;
	(*p).output_score(a);

	(*p).get_max_score(a);
	system("PAUSE");
	return 0;
}
student::student(int a,float b)
{
	num=a;
	score=b;
}
void student::output_score(student *a)
{
	student *p;
	p=a;
    for (int i = 0;i < 5;i += 2)
	{
		
		cout<<(*(p+i)).num<<'\t'<<(*(p+i)).score<<endl;
	}
}
// get_max_score()函数的功能是求出num名同学的最高成绩
void student::get_max_score(student *a)
{
	int max,i,*p=&score;
	max = *p;
	for (i = 1;i < 5;i++)
	{

		if ( a[i].score > max )
		{
			max = a[i].score;
			
		}
	}
	for(i=0;i<5;++i)
	{
		if(max==a[i].score)
		{

			cout<<"该同学的最高成绩和分数为:"<<a[i].num<<'\t'<<a[i].score<<endl;
		}
	}
}


运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐