- /*
- *Copyright (c) 2016,烟台大学计算机与控制工程学院
- *All rights reserved.
- *文件名称:lemon.cpp
- *作 者:郑志金
- *完成日期:2016年4月21日
- *版 本 号:v1.0
- *
- *问题描述:* 设计一个学生类,完成以下问题
- *输入描述:无
- *输出描述:输出第1,3,5个学生的信息,输出最高成绩学生的学号*/
#include<iostream>
using namespace std;
class Student
{
public:
friend int max(Student *);
Student(int a,double b);
void cout1(Student *arr1);
private:
int num;
double score;
};
Student::Student(int a,double b)
{
num=a;
score=b;
}
void Student::cout1(Student *arr1)
{
int i;
for(i=0;i<5;i+=2)
{
cout<<arr1[i].num<<' '<<arr1[i].score<<endl;
}
}
int max(Student *arr)
{
int max1;
max1=0;
int k;
for(int i=0;i<5;i++)
{
if(arr[i].score>max1)
{
max1=arr[i].score;
k=i;
}
}
return arr[k].num;
}
int main()
{
Student stud[5]=
{
Student(101,78.5),Student(102,85.5),Student(103,100),
Student(104,98.5),Student(105,95.5),
};
stud[0].cout1(stud);
cout<<"5个学生中成绩最高者的学号为:"<<max(stud);
return 0;
}
运行结果: