面向对象程序设计上机练习九(对象指针)
来源:互联网 发布:贝思外贸软件数据导出 编辑:程序博客网 时间:2024/05/18 01:38
面向对象程序设计上机练习九(对象指针)
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
建立对象数组,内放5个学生数据(学号是字符串类型、成绩是整型),设立max函数,用指向对象的指针作函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号和成绩。
Input
输入5个学生数据。
Output
输出5个学生中成绩最高者的学号和成绩。
Example Input
01 89
02 78
03 56
04 92
05 76
Example Output
04 92
Hint
Author
zlh
#include<math.h>#include<bits/stdc++.h>#include<string.h>using namespace std;class Point{public: char c[20]; int data; void f(char *a,int n) { strcpy(c,a); data = n; }};void Mymax(Point *p){ int m = 0,j = 0,i; for(i = 0; i < 5; i++) { if(p[i].data > m) { m = p[i].data; j = i; } } cout<<p[j].c<<" "<<p[j].data<<endl;}int main(){ int i; Point s[5]; for(i = 0; i < 5; i++) { char a[20]; int n; cin>>a>>n; s[i].f(a,n); } Mymax(s); return 0;}
阅读全文