作者热门文章
- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章C++之类和对象课后习题简单实例由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
建立一个对象数组,内放5个学生的(学号,成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生的最高成绩者,并输出其学号.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include<iostream>
using
namespace
std;
class
Student
{
public
:
Student(
int
=10,
int
=0);
int
number;
int
score;
void
display();
};
Student::Student(
int
num,
int
sco):number(num),score(sco){
}
void
Student::display()
{
cout<<number<<
" "
<<score<<endl;
}
void
max(Student *p)
{
int
maxi=p[0].score;
int
temp=0;
for
(
int
i=1;i<5;i++)
if
(p[i].score>maxi)
{
maxi=p[i].score;
temp=i;
}
cout<<p[temp].number<<
" "
<<maxi<<endl;
}
int
main()
{
Student stu[5]={
Student{1001,90},
Student{1002,80},
Student{1003,99},
Student{1004,84},
Student{1005,85}
};
Student *p=&stu[0];
max(p);
return
0;
}
|
以上这篇C++之类和对象课后习题简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我.
最后此篇关于C++之类和对象课后习题简单实例的文章就讲到这里了,如果你想了解更多关于C++之类和对象课后习题简单实例的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我是一名优秀的程序员,十分优秀!