您的位置:首页 > 其它

面向对象部分_210

2014-06-25 14:00 155 查看
#include <iostream>

using namespace std;

class Array
{
private:
int n;
int s;
int a[10], b[10];
public:
Array(int, int*, int);
void change();
void output();
};

Array::Array(int m, int c[], int s)
{
n = m;
this->s = s;
for (int i = 0; i < s; i++)
{
a[i] = c[i];
}
}

void Array::change()
{
int j = 0;
for (int i = s - n; i < s; i++)  //从需要调换的地方开始赋值
{
b[j++] = a[i];
}
for (int i = 0; i < s - n; i++)
{
b[j++] = a[i];
}
}

void Array::output()
{
cout << "原数组为:" << endl;
for (int i = 0; i < s; i++)
{
if ((i + i) % 5 == 0)
{
cout << endl;
}
cout << a[i] << " ";
}
cout << endl << "调换后的数组为:" << endl;
for (int i = 0; i < s; i++)
{
if ((i + i) % 5 == 0)
{
cout << endl;
}
cout << b[i] << " ";
}
cout << endl;
}

int main()
{
int t[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Array test(3, t, 10);
test.change();
test.output();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: