/* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. * 文件名称: Lshu * 作 者: 刘向一 * 完成日期: 2012 年 3 月 19 日 * 版 本 号: V1.0 * 对任务及求解方法的描述部分 * 输入描述: * 问题描述: * 程序输出: * 程序头部的注释结束 */ #include<iostream> using namespace std; class Student { public: Student(int n,float s):num(n),score(s){} void display(); int num; float score; }; int main() {Student stud[5]={ Student(186,98.5),Student(187,95.5),Student(188,99.5), Student(189,100.0),Student(190,93.5)}; Student *p=stud; cout<<"第1、3、5个学生的信息为:"<<endl; for(int i=0;i<=2;p=p+2,i++) p->display(); void max(Student *); Student *m=&stud[0]; max(m); return 0; } void Student::display() { cout<<"学号:"<<num<<" "<<"分数:"<<score<<endl; } void max(Student *arr) { float max_score=arr[0].score; int k=0; for(int i=1;i<5;i++) if(arr[i].score>max_score) { max_score=arr[i].score;k=i; } cout<<"5个学生中成绩最高分为:"<<max_score<<" "<<"其学号为"<<arr[k].num<<endl; system("pause"); }