现在的位置: 首页 > 综合 > 正文

第五周上机任务4

2013年10月21日 ⁄ 综合 ⁄ 共 785字 ⁄ 字号 评论关闭
/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生 
* All rights reserved.
* 文件名称:练习.cpp                              
* 作    者:宋本一                              
* 完成日期:2012 年 3 月 24 日
* 版 本 号:v5.4          
* 对任务及求解方法的描述部分
* 输入描述: 
* 问题描述: 
* 程序输出: 
* 程序头部的注释结束
*/
#include <iostream>  
using namespace std;

class Student  
{  
public:  
    Student (int n, int s);  
    void max_score (Student *p);  
    void output ();
	
private:  
    long num;  
    int score;  
};  

Student :: Student(int n, int s)  
{  
    num = n;  
    score = s;  
}  

void Student :: output()  
{  
    cout << num << '\t' << score << endl;  
}  

void Student :: max_score (Student *p)  
{  
    int max_score=p[0].score;  
    int i,k;  
    
	for(i = 1; i < 5; i++)  
    {  
        if(p[i].score > max_score)  
        {  
            max_score = p[i].score;  
            k = i;  
        }  
    }  
    cout << "最高成绩为:" << max_score << " " << "学号为:" << p[k].num << endl;  
}  

int main()  
{   
    Student a[5] = 
	{  
        Student (001, 10),  
			Student (002, 30),  
			Student (003, 50),  
			Student (004, 70),  
			Student (005, 90)  
    };  
    
	Student * stud = a;  
    int i;  
    
	for(i = 0; i <= 2; stud += 2, ++i)  
    {  
        stud -> output();  
    } 
    stud -> max_score(a);
	
	return 0;
}

 运行结果:

抱歉!评论已关闭.