面向对象程序设计上机练习九(对象指针

来源:互联网 发布:成都行知小学小升初 编辑:程序博客网 时间:2024/05/19 00:09

面向对象程序设计上机练习九(对象指针)

Time Limit: 1000MS Memory Limit: 65536KB
SubmitStatistic

Problem Description

建立对象数组,内放5个学生数据(学号是字符串类型、成绩是整型),设立max函数,用指向对象的指针作函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号和成绩。

Input

输入5个学生数据。

Output

输出5个学生中成绩最高者的学号和成绩。

Example Input

01 8902 7803 5604 9205 76

Example Output

04 92
 
 
#include<iostream>#include<string.h>using namespace std;class student{   private:   int s;   char name[1000][20];   int num[1000];   public:   void set()   {        for(int i=0;i<5;i++)        {            cin>>name[i]>>num[i];        }   }   void input()   {       int i,k;       int max=num[0];       for(i=0;i<5;i++)       {           if(max<num[i])           {               max=num[i];               k=i;           }       }       cout<<name[k]<<" "<<num[k]<<endl;   }};int main(){    student t,*p;    t.set();    p=&t;    p->input();    return 0;}

0 0