面向对象程序设计上机练习六(类和对象)
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
用类成员函数完成5个整型数组元素的输入、从小到大排序、排序后数组元素的输出。
Input
输入5个数组元素。
Output
输出5个数组元素从小到大排序后的结果。(最后一个数后面既没有空格也没有换行)
Example Input
8 9 1 5 4
Example Output
1 4 5 8 9
Hint
Author
zlh
#include<bits/stdc++.h>
using namespace std;
class bijiao
{
public:
void mmax(int a[]);
};
void bijiao::mmax(int a[])//注意类成员函数的写法
{
for(int i = 0; i < 4; i++)
{
for(int j = i + 1; j < 5; j++)
{
if(a[i] > a[j])
{
int t = a[i]; a[i] = a[j]; a[j] = t;
}
}
}
}
int main()
{
int a[5];
for(int i = 0; i < 5; i++)
{
cin>>a[i];
}
bijiao B;
B.mmax(a);
for(int i = 0; i < 5; i++)
{
if(i == 4)
cout<<a[i]<<endl;
else
cout<<a[i]<<" ";
}
return 0;
}