指向学生类的指针
2016-04-20 15:25
190 查看
问题及代码:
结果及总结:
/* *copyright(c) 2016烟台大学计算机学院 *All rights reserved *文件名称:test.cpp *作者:杨昊 *版本:v6.0 * *问题描述: 只想学生类的指针 *输入描述:无 *程序输出: */ #include<iostream> using namespace std; class Student { public: Student(int n=0,double s=0):num(n),score(s){} int getnum() { return num; } double getscore() { return score; } void shuchu() { cout<<num<<" "<<score<<endl; } private: int num; //学号 double score; //成绩 }; int max(Student *arr) { double max1=arr[0].getscore(); int k=0; for(int i=1; i<5; i++) if(arr[i].getscore()>max1) { max1=arr[i].getscore(); k=i; } return arr[k].getnum(); } int main() { int i; Student stud[5]= { Student(101,78.5),Student(102,85.5),Student(103,100), Student(104,98.5),Student(105,95.5) }; for(i=0;i<5;) { stud[i].shuchu(); i=i+2; } cout<<"5个学生中成绩最高者的学号为: "<<max(stud)<<endl; return 0; }
结果及总结:
相关文章推荐
- 自己写一个Web服务器(3)
- 2015软件男篮失利总结
- js 函数定义三种方式
- WordPress 3D旋转彩色标签云
- iOS UIButton传递多个参数的方法——使用关联函数
- VS 2013 编译 Lua 5.3
- Nike如何利用邮件营销助力科比退役赛事?
- iOS开发--Mac下服务器搭建
- 请求php返回json生成自定义对象
- Pandas——ix vs loc vs iloc
- ndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter的解决方案
- 【超清晰】同步和异步的区别
- Maven Android Plugin
- linux与windows文件共享的实现
- Smart210学习记录-------内存初始化
- iOS中,当我们要去掉webView上的长按手势时
- mysql (master/slave)复制原理及配置
- 详解C语言编程中的函数指针以及函数回调
- LCS最长子串问题
- windows azure创建并发布网站