第五周实验报告(任务4)
来源:互联网 发布:手机版服装批发软件 编辑:程序博客网 时间:2024/05/17 07:26
【任务4】设计一个学生类,包括学号(num)和成绩(score)。建立一个对象数组,内放5个学生的数据,要求:
(1) 用指针指向数组首元素,输出第1、3、5个学生的信息;
(2) 设计一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号。
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称: 长方柱类
* 作 者:郭广建
* 完成日期: 2012年 3月 20日
* 版 本 号: 1.0
源程序:
#include <iostream>using namespace std;class Student{public:Student(int n, float s):num(n),score(s){};int get_num(){return num;} //这个方法很好借鉴老师的 float get_score(){return score;} void output();private:int num ;float score;};int max(Student *Stu){ float max_score = Stu[0].get_score();int i, j;for(i = 1; i < 5; ++i){if(Stu[i].get_score() > max_score){max_score = Stu[i].get_score();j = i;}}return Stu[j].get_num();}void Student::output(){cout << "学号是:" << num << "成绩是:" << score <<endl;}int main(){Student Stu[5] = {Student(1001,87),Student(1002,91),Student(1003,90.5),Student(1004,88.5),Student(1005,97.5)};for(int i = 0; i < 5; i+=2){cout << "第" <<i + 1 << "个学生的信息是:";Stu[i].output();}cout << "学生中成绩最高的同学的学号是:" << max(Stu) <<endl;return 0;}
运行结果:
- 第五周实验报告(任务4)
- 《第五周实验报告任务4》
- 第五周实验报告任务4
- 第五周实验报告 任务4
- 第五周实验报告任务4
- 第五周实验报告(任务1)
- 第五周实验报告(任务1)
- 第五周实验报告(任务3)
- 第五周实验报告(任务2)
- C++程序设计实验报告(三十九)---第五周任务一
- C++程序设计实验报告(四十)---第五周任务二
- C++程序设计实验报告(四十一)---第五周任务三
- C++程序设计实验报告(四十二)---第五周任务四
- 第五周实验报告(任务三)《处理分数》
- 第五周实验报告任务(1-1)
- 第五周实验报告(任务四)《学生类》
- 第五周实验报告任务1-1
- 第五周实验报告 任务一
- 选择器
- 《Java Concurrency in Practice》ch6 Task Execution
- [Linux驱动开发] jffs2 文件系统制作及移植
- 第五周实验报告2
- SQL Server 2000中的列级约束与表级约束
- 第五周实验报告(任务4)
- java之LinkList、ListIterator、ArrayList学习
- 从 Java 支持压缩/解压缩开始,无法缺省支持中文文件名。
- 问题2
- Java 随机数
- weblogic.transaction.TimedOutException
- dfs最简单的应用——输出全排列
- [初学者的困惑] 堆和栈的区别 (转)
- MyISAM存储引擎的表级锁定优化