面向对象程序设计上机练习八(对象数组)
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
利用类对象数组完成N个学生数据(学号是字符串类型、成绩是整型)的输入、输出。
Input
输入有N+1行:
第一行的整数N表示学生数目;
以下N行是N个学生的数据,每行中第一个是表示学号的字符串,第二个是表示学生成绩的整数。
第一行的整数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>
#include<string>
using namespace std ;
class stu
{
private:
string xuehao ;
int chengji ;
public:
stu (string x = "00" ,int y = 0 )
{
xuehao = x ;
chengji = y ;
}
void show()
{
cout << xuehao << " "<< chengji << endl ;
}
};
int main()
{
int n ;
int i ;
stu a[1000] ;
cin >> n ;
for(i=0;i<n;i++)
{
string stl ;
int num ;
cin >> stl >> num ;
a[i]={stl,num} ;
}
for(i=0;i<n;i++)
{
a[i].show();
}
return 0 ;
}