面向对象程序设计上机练习九(对象指针)
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
#include<iostream> using namespace std; class numble { private: int i,num[1010],n,k; char name[1000][20]; public: void setint() { for(i = 0; i < 5; i++) cin>>name[i]>>num[i]; } void setput() { n = num[0]; k = 0; for(i = 1; i < 5; i++) if(num[i] > n) { n = num[i]; k = i; } cout<<name[k]<<" "<<num[k]<<endl; } }; int main() { numble t,*p; p = &t; (*p).setint(); (*p).setput(); return 0; }
本文介绍了一个使用C++实现的学生信息管理程序案例。通过面向对象的方法,利用对象指针作为函数参数,实现了从学生数组中查找并输出成绩最高者的信息。此程序包括输入学生数据及输出最高成绩学生的具体实现。
1990

被折叠的 条评论
为什么被折叠?



