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

来源:互联网 发布:大数据明细实时查询 编辑:程序博客网 时间:2024/05/29 18:02

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

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic

Problem Description

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

Input

输入有N+1行:
第一行的整数N表示学生数目;
以下N行是N个学生的数据,每行中第一个是表示学号的字符串,第二个是表示学生成绩的整数。

Output

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

Example Input

501 8902 7803 5604 9205 76

Example Output

01 8902 7803 5604 9205 76
#include <iostream>#include <string>using namespace std;#define MAX 10000class student{private:string name;int grade;public:void set_info(string p, int n){name = p;grade = n;}void show(){cout<<name<<" "<<grade<<endl;}~student() {}};int main(){int n, m;string p;student s[MAX];cin>>n;for(int i = 0; i < n; i++){cin>>p>>m;s[i].set_info(p, m);}for(int i = 0; i < n; i++)s[i].show();return}


阅读全文
0 0
原创粉丝点击