Problem 1414. -- 整型数组类

1414: 整型数组类

Time Limit: 1 Sec  Memory Limit: 65535 MB   64bit IO Format: %lld
Submitted: 2165  Accepted: 805
[Submit][Status][Web Board]

Description

ARRAY();//构造函数，数组的长度默认为10，动态申请内存，并输出信息"Default Construct is called"
ARRAY(int i); //构造函数，数组的长度为i，动态申请内存，并输出信息"Construct is called"
ARRAY(const ARRAY &a); //复制构造函数（深复制），并输出信息"Copy Default Construct is called"
int& operator [](int i); //重载运算符[]，返回数组的第i个整数，并输出信息"operator [] Function is called"
~ARRAY();//析构函数，需要释放动态申请的内存，并输出信息"DeConstruct is called"
ARRAY& operator =(const ARRAY &a); //重载运算符=，并输出信息"operator = Function is called"
operator int *() const;  //重载指针运算，返回数组的首地址，并输出信息"operator * Function is called"
void Resize(int sz);  //修改数组大小，并输出信息"Resize function is called"
friend ARRAY operator+(ARRAY &a,ARRAY &b); //重载运算符+为友元函数,将b中的所有元素存放到a的后面，生成新数组，然后返回新数组，并输出信息"friend operator + Function is called"
friend ostream& operator<<(ostream &o,ARRAY &a); //重载运算符<<为友元函数，输出a的所有元素（格式见Sample Output），并输出信息"friend operation << Function is called"

main函数如下：（大家提交时只需要提交除main函数外的代码部分）
int main()
{
int i,n,t;
ARRAY a1;
for(i=0;i<10;i++)
{
a1[i]=i+1;
}
fun(a1);
ARRAY a2(5);
for(i=0;i<5;i++)
{
a2[i]=(i+1)*100;
}
fun(a2);
ARRAY a3(a2);
fun(a3);
a3.Resize(8);
a3=666;
a3=777;
a3=888;
fun(a3);
a3=a1+a2;
fun(a3);
return 0;
}

Sample Output

```Default Construct is called
operator [] Function is called
operator [] Function is called
operator [] Function is called
operator [] Function is called
operator [] Function is called
operator [] Function is called
operator [] Function is called
operator [] Function is called
operator [] Function is called
operator [] Function is called
Copy Default Construct is called
fun Function is called
[1,2,3,4,5,6,7,8,9,10]
friend operation << Function is called

DeConstruct is called
Construct is called
operator [] Function is called
operator [] Function is called
operator [] Function is called
operator [] Function is called
operator [] Function is called
Copy Default Construct is called
fun Function is called
[100,200,300,400,500]
friend operation << Function is called

DeConstruct is called
Copy Default Construct is called
Copy Default Construct is called
fun Function is called
[100,200,300,400,500]
friend operation << Function is called

DeConstruct is called
Resize function is called
operator [] Function is called
operator [] Function is called
operator [] Function is called
Copy Default Construct is called
fun Function is called
[100,200,300,400,500,666,777,888]
friend operation << Function is called

DeConstruct is called
Construct is called
friend operator + Function is called
operator = Function is called
DeConstruct is called
Copy Default Construct is called
fun Function is called
[1,2,3,4,5,6,7,8,9,10,100,200,300,400,500]
friend operation << Function is called

DeConstruct is called
DeConstruct is called
DeConstruct is called
DeConstruct is called```

[Submit][Status][Web Board]