#include<iostream>
#include<string>
#include<new>
#include <algorithm>
#include <vector>
using namespace std;
class myarray{
public:
myarray();
myarray(const myarray&m);
myarray(int len);
// myarray add(const myarray& a,const myarray& b);
~myarray();
void setdata(int index,double data);
double getdata(int index);
double getlen()const;
int result[];
double* e;
myarray &operator =(const myarray&);
int &operator[](int i)const;
myarray &operator+(const myarray & ma);
friend ostream & operator << (ostream & os,const myarray & ma);
friend istream & operator >> (istream & is,const myarray & ma);
private:
int len;
int *space;
};
myarray::myarray(){this->len = 0;this->space = NULL;
}
myarray::myarray(int len)
{
if (len <= 0) {
this->len = 0; return; }
else{
this->len = len;
this->space = new int[this->len];
}
}
myarray::~myarray(){
if((this->space)!= NULL){
delete this->space;
this->space=NULL;
len = 0;
}
}
void myarray::setdata(int index,double data){
if(this->space != NULL){this->space[index]=data;
}
};
double myarray::getdata(int index){
return this->space[index];
};
double myarray::getlen()const {return this->len;};
myarray& myarray::operator =(const myarray & m){
if (this == &m) { return *this; }
if (this->space != NULL){
delete[] this->space;
this->space = NULL;
}
}
int & myarray::operator [](int i)const {return this->space[i];}
ostream & operator << (ostream & os,const myarray & ma){
for (int i=0;i<ma.getlen();i++){
os<<ma[i]<<"\t";
}
return os;
}
istream & operator >>(istream & is,myarray & ma){
cout <<"输入"<<ma.getlen()<<"个数"<<endl;
for (int i=0;i<ma.getlen();i++){is>>ma[i];
}
return is;
}
myarray &myarray::operator+(const myarray &ma)
{
myarray *t = new myarray(ma.getlen());
for (int i = 0; i < ma.getlen(); ++i)
{
t->space[i] = space[i] + ma[i];
}
return *t;
}
int main(){
int buff;
cin>>buff;
myarray arr1(buff);
myarray arr2(buff);
cin>>arr1;
cin>>arr2;
cout<<"arr2:"<<arr2<<endl;
myarray arr3 = arr1 + arr2;
cout<<"arr1+arr2="<<arr3<<endl;
}
```