拜求C++高手,有好心编程高手帮帮忙,谢谢了!!

用C++语言编写程序
定义一个方阵类Array,实现对方阵进行顺时针90度旋转。如图所示。
|1 2 3 4 | |13 9 5 1 |
|5 6 7 8 | → |14 10 6 2 |
|9 10 11 12 | |15 11 7 3 |
|13 14 15 16 | |16 12 8 4 |
具体要求如下:
(1)私有数据成员
int a[4][4]:用于存放方阵。
(2)公有数据成员
Array(int a1[][4],int n):构造函数,用给定的参数a1初始化数据成员a。
void xuanzhaun():实现对方阵a进行顺时针90度的旋转。
void show():在屏幕上显示数组元素。
(3)在主程序中定义数组int b[][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}对作为原始数组。定义一个类Array类对象test,用b初始化test,完成对该类的测试
编好后程序 一定请发[email protected]~谢了

第1个回答  2011-03-10
#include "iostream.h"

class Array
{

private:
int a[4][4];

public:
Array(int a1[][4],int n)
{
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
a[i][j]=a1[i][j];
}
}
}
void xuanzhaun()//:实现对方阵a进行顺时针90度的旋转。
{
int temp[4][4];
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
temp[i][j]=a[3-j][i];
}
}
for( i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
a[i][j]=temp[i][j];
}
}

}
void show()//在屏幕上显示数组元素
{
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
cout<<a[i][j]<<'\t';
}
cout<<endl;
}
}
};

void main()
{
int b[4][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
Array test(b,4);
// b初始化test,完成对该类的测试
cout<<"没有旋转之前的"<<endl;
test.show();

test.xuanzhaun();
cout<<endl;
cout<<"旋转之后的"<<endl;
test.show();

}
第2个回答  2011-03-10
已发送到邮箱,请查收本回答被提问者采纳
相似回答