您的位置:首页 > 其它

面向对象程序设计上机练习八(对象数组)

2017-09-28 11:39 302 查看

面向对象程序设计上机练习八(对象数组)

Time Limit: 1000MS
Memory Limit: 65536KB
[align=center][/align]

Problem Description

利用类对象数组完成N个学生数据(学号是字符串类型、成绩是整型)的输入、输出。

Input

输入有N+1行:

第一行的整数N表示学生数目;

以下N行是N个学生的数据,每行中第一个是表示学号的字符串,第二个是表示学生成绩的整数。

Output

输出N个学生数据。每个学生的数据占一行。

Example Input

5
01 89
02 78
03 56
04 92
05 76


Example Output

01 89
02 78
03 56
04 92
05 76


#include <iostream>

using namespace std;

class Student

{

public:

    void GetStudent(string id,int result)

    {

        ID=id;

        Result=result;

    }

    void PrintStudent()

    {

        cout<<ID<<" "<<Result<<endl;

    }

private:

    int Result;

    string ID;

};

int main()

{

    Student stu[64];

    int t,result;

    string ID;

    cin>>t;

    for(int i=0;i<t;i++)

    {

        cin>>ID>>result;

        stu[i].GetStudent(ID,result);

    }

    for(int i=0;i<t;i++)

    {

        stu[i].PrintStudent();

    }

    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: