欢迎来到入门教程网!

C语言

当前位置:主页 > 软件编程 > C语言 >

C++之类和对象课后习题简单实例

来源:本站原创|时间:2020-01-10|栏目:C语言|点击:126 次

建立一个对象数组,内放5个学生的(学号,成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生的最高成绩者,并输出其学号。

#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=p0.score;
  int temp=0;
  for(int i=1;i<5;i++)
  if(p.score>maxi)
  
  maxi=p.score;
  temp=i;
  
  cout<<p.number<<" "<<maxi<<endl;


int main()

  Student stu5=
Student1001,90,
Student1002,80,
Student1003,99,
Student1004,84,
Student1005,85
;
  Student *p=&stu0;
   max(p);
  return 0;

以上这篇C++之类和对象课后习题简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

上一篇:C/C++: Inline function, calloc 对比 malloc

栏    目:C语言

下一篇:C语言获取Shell返回结果的实现方法

本文标题:C++之类和对象课后习题简单实例

本文地址:https://www.xiuzhanwang.com/a1/Cyuyan/2192.html

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 脚本教程网 版权所有