6.15 喜刷刷 1 oj 1 对象数组中的最大值
来源:互联网 发布:c语言 十进制转换bcd 编辑:程序博客网 时间:2024/09/21 09:04
问题 E: C++习题 对象数组求最大值
时间限制: 1 Sec 内存限制: 128 MB提交: 1047 解决: 755
[提交][状态][讨论版]
题目描述
建立一个对象数组,内放n(<10)个学生的数据(学号、成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出n个学生中成绩最高者,并输出其学号。
输入
n和n个学生的学号、成绩
输出
成绩最高者的学号和成绩
样例输入
5101 78.5102 85.5103 98.5104 100.0105 95.5
样例输出
104 100.00
解题代码:
#include <iostream>#include <iomanip>using namespace std;class Student{public: Student(int n=0,double s=0):num(n),score(s) {} int get_num(); void input(); double get_score(); void display();
private: int num; //学号 double score; //成绩};
int Student::get_num(){ return num;}double Student::get_score(){ return score;}void max(Student *arr,int n){ double max=arr[0].get_score(); int i,no; for(i=0; i<n; ++i) { if(arr[i].get_score()>max) no=i; } no--; arr[no].display();}void Student::input(){ double n,s; cin>>n>>s; num=n; score=s;}void Student::display(){ cout<<num<<" "<<score<<endl;}
int main()
{ void max(Student* ,int); const int NUM=10; Student stud[NUM]; int n,i; cin>>n; for(i=0; i<n; i++) stud[i].input(); cout<<setiosflags(ios::fixed); cout<<setprecision(2); Student *p=&stud[0]; max(p,n); return 0;}
- 6.15 喜刷刷 1 oj 1 对象数组中的最大值
- 6.15 喜刷刷1 oj 数组输出
- 6.15 喜刷刷 oj 1 b 矩形类定义
- OJ对象数组求最大值
- 6.15 喜刷刷 1 oj c 矩形的运算符重载
- 16 oj 对象数组求最大值
- 【OJ】---M---对象数组求最大值
- YTU-OJ- 对象数组求最大值
- OJ积累—对象数组求最大值
- OJ——对象数组求最大值
- 6,15 喜刷刷oj 1 j 复数类 重载运算符+
- 1、寻找数组中的最大值和最小值
- oj刷题第一批E 对象数组求最大值
- oj刷(1)4对象数组
- 刷刷笔试题~(1)
- 刷刷编程基础题~(1)
- 对象数组最大值
- 对象数组求最大值
- String StringBuffer StringBuilder区别
- SAT数学难题解题方法
- IOS开发之利用通知(NSNotification)进行数据传递
- TCP/IP TIME_WAIT状态原理
- iOS通过iTunes search检测版本更新,并提示用户更新!
- 6.15 喜刷刷 1 oj 1 对象数组中的最大值
- iOS文字 转 语音
- 正则表达式判断电话号码
- 向对象的的基本特征:抽象,封装,继承,多态
- LeetCode Contains Duplicate III
- [leetcode] Implement Trie (Prefix Tree)
- oracle学习之路(六)两个实际使用的例子
- postgres row_number()分析
- iphone学习路线