面向对象部分_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; }
相关文章推荐
- 第二部分 Windows编程、面向对象程序设计
- 面向对象系统设计部分的数据管理和构建部分的设计
- PHP面向对象试题(基础部分)
- php部分---面向对象静态、抽象类、oop接口、加载类、魔术方法、关键字。
- [零基础学JAVA]Java SE面向对象部分-15.面向对象高级(03) 推荐
- 面向对象基础部分笔记
- [零基础学JAVA]Java SE面向对象部分-21.包及访问权限 推荐
- 高级特性-面向对象部分
- C与C++部分不同(非面向对象部分)
- 面向对象部分_201
- java面向对象下第一部分学习日志
- 9.Python笔记之面向对象高级部分
- 面向对象学习1部分
- ----------------以下总结的5-10课是程序的面向对象和异常处理部分--------------
- C#基础系列(8)-- 第三部分 面向对象相关 -- 类与结构(1)
- 面向对象部分_202
- [零基础学JAVA]Java SE面向对象部分.面向对象基础(01)
- 面向对象部分_203
- C++面向对象程序设计 笔记3 (面向对象部分)
- [零基础学JAVA]Java SE面向对象部分.面向对象基础(02)