这段代码怎么用C++构造函数来写?

#include <iostream>
#include <iomanip>
#define N 10
using namespace std;
int main(){
    double a[N],temp;
    int i,j;
    cout<<"Input number:";
    for(i=0;i<N;i++)
        cin>>a[i];
    for(i=0;i<N-1;i++)
        for(j=0;j<N-i-1;j++)
            if(a[j]>a[j+1]){
                temp=a[j];a[j]=a[j+1];a[j+1]=temp;}
            for(i=0;i<N;i++)
                cout<<setw(7)<<a[i];
            cout<<endl;
            return 0;
}

定义一个类,在类的构造函数中,把你需要的代码粘贴进行就可以了。

然后类在new对象时,会自动调用构造函数,然后就会执行的你的代码了。