C++之类和对象课后习题简单实例
建立一个对象数组,内放5个学生的(学号,成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生的最高成绩者,并输出其学号。
#include<iostream>
usingnamespacestd;
classStudent
{public:
Student(int=10,int=0);
intnumber;
intscore;
voiddisplay();
};
Student::Student(intnum,intsco):number(num),score(sco){
}
voidStudent::display()
{
cout<<number<<""<<score<<endl;
}
voidmax(Student*p)
{
intmaxi=p[0].score;
inttemp=0;
for(inti=1;i<5;i++)
if(p[i].score>maxi)
{
maxi=p[i].score;
temp=i;
}
cout<<p[temp].number<<""<<maxi<<endl;
}
intmain()
{
Studentstu[5]={
Student{1001,90},
Student{1002,80},
Student{1003,99},
Student{1004,84},
Student{1005,85}
};
Student*p=&stu[0];
max(p);
return0;
}
以上这篇C++之类和对象课后习题简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下