第八周上机实践项目——项目3-指向学生类的指针
2016-04-18 22:48
316 查看
/* *Copyright (c)2016,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:main.cpp *作 者:郭永恒 *完成日期:2016年4月18日 *版 本 号:v1.0 * *问题描述:设计一个学生类,数据成员包括学号和成绩,成员函数根据需要自行设计 */ #include <iostream> using namespace std; class Student { public: Student(int x = 0,double y = 0.0):num(x),score(y) {} void input(); void output(); int get_num() {return num;} double get_score() {return score;} private: int num; double score; }; void Student::input() { cin >> num >> score; } void Student::output() { cout << num << "--" << score << endl; } int max(Student *arr) { int temp; double tscore = arr[0].get_score(); for(int i = 0; i < 5; ++i) if(tscore < arr[i].get_score()) { tscore = arr[i].get_score(); temp = arr[i].get_num(); } return temp; } int main() { Student stud[5] = { Student(101,78.5),Student(102,85.5),Student(103,100), Student(104,98.5),Student(105,95.5) }; for(int i = 0; i < 5; i+=2)//输出1、3、5的成绩 stud[i].output(); cout << "5个学生中成绩最高者的学号为: " << max(stud); return 0; }
运行结果:
相关文章推荐
- 9.1.3 模块接口
- Myeclipse工具栏快捷图标丢失后找回
- Android Mvp实践
- web实战(二)— — 商城分类导航
- 【项目管理】项目经理的关键职责
- Socket通信几个概念
- #1015 : KMP
- Android之Dialog详解
- UVA_10336_Divisibility
- Struts2框架中OGNL表达式的学习
- 思科防火墙ASA端口映射
- iOS _BSMachError: (os/kern) invalid capability (20)
- css的repaint和reflow
- 4.Java中获取当前目录的方法
- 敏捷风暴2016(广州站)
- 关于java中bean拷贝的思考
- Markdown 常用技巧
- Selinux SeAndroid理解
- C++ 中Traits技术 (4) —— 类型推导
- 2 ARM7的三级流水线过程