/*
*copyright(c) 2016,烟台大学计算机学院
*All rights reserved
*文件名称:test.cpp
*作者:谭泽纯
*版本:v6.0
*
*问题描述:
设计数组类Array,为了实现测试函数中要求的功能,请补足相关的函数(构造、析构函数)和运算符重载的函数。请注意引用的用法。
实现策略提示:可以将测试函数中的语句加上注释,取消一句的注释,增加相应的函数,以渐增地实现所有的功能,避免全盘考虑带来的困难。
<code class="hljs cpp has-numbering"><span class="hljs-keyword">class</span> Array { <span class="hljs-keyword">private</span>: <span class="hljs-keyword">int</span>* <span class="hljs-built_in">list</span>; <span class="hljs-comment">//用于存放动态分配的数组内存首地址</span> <span class="hljs-keyword">int</span> size; <span class="hljs-comment">//数组大小(元素个数)</span> <span class="hljs-keyword">public</span>: <span class="hljs-comment">//成员函数声明</span> }; <span class="hljs-comment">//要求测试函数能够运行出正确、合理的结果:</span> <span class="hljs-keyword">int</span> main() { <span class="hljs-keyword">int</span> a[<span class="hljs-number">8</span>]= {<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>}; <span class="hljs-keyword">int</span> b[<span class="hljs-number">8</span>]= {<span class="hljs-number">10</span>,<span class="hljs-number">20</span>,<span class="hljs-number">30</span>,<span class="hljs-number">40</span>,<span class="hljs-number">50</span>,<span class="hljs-number">60</span>,<span class="hljs-number">70</span>,<span class="hljs-number">80</span>}; Array array1(a,<span class="hljs-number">8</span>),array3,array4; <span class="hljs-keyword">const</span> Array array2(b,<span class="hljs-number">8</span>); array4=array3=array1+array2; array3.show(); array4.resize(<span class="hljs-number">20</span>); array4[<span class="hljs-number">8</span>]=<span class="hljs-number">99</span>; <span class="hljs-built_in">cout</span><<array4[<span class="hljs-number">8</span>]<<endl; <span class="hljs-built_in">cout</span><<array2[<span class="hljs-number">3</span>]<<endl; <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>; }</code>
#include <iostream>
#include <iomanip>