第五周实验报告4

 * (程序头部注释开始)

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

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

* All rights reserved.* 文件名称:

 * 作 者: 于宸

* 完成日期:2012 年 3月21日

* 版 本 号:

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

* 输入描述: 设计一个学生类,包括学号(num)和成绩(score)。建立一个对象数组,内放5个学生的数据,要求:(1) 用指针指向数组首元素,输出第1、3、5个学生的信息;(2) 设计一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号。

* 问题描述:

* 程序输出:

* 程序头部的注释结束*/

#include<iostream>  
using namespace std;  
class Student  
{  
public:  
    Student(int n,float s):num(n),score(s){}  
    void display();  
    int num;  
    float score;  
};  
void Student::display()  
{  
    cout<<num<<" "<<score<<endl;  
}  
void max(Student *a);  
  
int main()  
{  
    Student s[5]={  
        Student(001,90),  
            Student(002,98.5),  
            Student(003,98),  
            Student(004,92),  
            Student(005,100)  
    };  
    Student *p=s;  
    for(int i=0;i<5;i=i+2)  
    {  
        cout<<"第"<<i+1<<"个学生的学号和成绩";  
        s[i].display();  
    }  
        cout<<"最高成绩的学号成绩为:";  
        Student *q=&s[0];  
        max(q);  
        cout<<endl;  
        return 0;  
}     
      
    void max(Student *a)  
    {  
        float max_score=a[0].score;  
        int k;  
        for(int i=0;i<5;i++)  
        {  
            if(a[i].score>max_score)  
                  
                max_score=a[i].score;  
            k=i;  
        }  
        cout<<a[k].num<<" "<<max_score;  
        return;  
          
    }  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值