您的位置:首页 > 其它

面向对象程序设计上机练习六(类和对象)

2016-09-28 15:35 211 查看


面向对象程序设计上机练习六(类和对象)

Time Limit: 1000MS Memory Limit: 65536KB

Submit Statistic


Problem Description

用类成员函数完成5个整型数组元素的输入、从小到大排序、排序后数组元素的输出。


Input

输入5个数组元素。


Output

输出5个数组元素从小到大排序后的结果。(最后一个数后面既没有空格也没有换行)


Example Input

8 9 1 5 4



Example Output

1 4 5 8 9



#include <iostream>
#include <algorithm>
using namespace std;
class Array
{
private:
int a[5];
public:
void getnum()
{
for(int i=0;i<5;i++)
cin>>a[i];
}
void asort()
{
sort(a,a+5);
}
void pri()
{
for(int i=0;i<5;i++)
{
if(i==0)
cout<<a[i];
else
cout<<" "<<a[i];
}
cout<<endl;
}
};
int main()
{
Array t;
t.getnum();
t.asort();
t.pri();
return 0;
}


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