#include <iostream>
#define N 8
using namespace std;
class A
{
public:
void shuru(); //类内申明
void shuchu();
void qiuhe();
void paixu();
private:
int arr[N];
};
void A:: shuru() //类外定义
{
cout<<"请输入"<<N<<"个整数:";
int i = 0;
for(i=0; i<N; i++)
{
cin>>arr[i];
}
}
void A::shuchu()
{
cout<<"这"<<N<<"个整数为:";
int i = 0;
for(i=0; i<N; i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
}
void A::qiuhe()
{
cout<<"这"<<N<<"个整数的和为:";
int sum = 0, i = 0;
for(i=0; i<N; i++)
{
sum+=arr[i];
}
cout<<sum<<endl;
}
void A::paixu()
{
NEXT:
cout<<"请输入升序排列还是降序排列(0:升序,1:降序)";
int i = 0, j = 0, temp = 0, flag1 = 0, flag2 = 0;
cin>>flag1;
if(flag1 != 1 && flag1 != 0)
{
cout<<"你输入的有误,请你重新输入"<<endl;
goto NEXT;
}
if(0 == flag1)
{
for(i=1; i<N; i++)
{
flag2 = 0;
for(j=0; j<N-i; j++)
{
if(arr[j] > arr[j+1])
{
temp = arr[j];
arr[j]= arr[j+1];
arr[j+1] = temp;
flag2 = 1;
}
}
if(0 == flag2)
break;
}
}else if(1 == flag1)
{
for(i=1; i<N; i++)
{
flag2 = 0;
for(j=0; j<N-i; j++)
{
if(arr[j] < arr[j+1])
{
temp = arr[j];
arr[j]= arr[j+1];
arr[j+1] = temp;
flag2 = 1;
}
}
if(0 == flag2)
break;
}
}
}
int main()
{
A s1;
s1.shuru();
s1.shuchu();
s1.qiuhe();
s1.paixu();
s1.shuchu();
return 0;
}