HI I KNOW I HAVE ASKED SO MUCH BUT PLEASE DO NOT IGNORE ME
I HAVE APART OF QUISTION THAT I COULDNOT COMPLETE IT
HERE IS IT
Then create an int specialization and in it add a function that returns the sum of all elements in the DoubleSubscriptedArray
HERE IS THE CODE I WANT TO ADD THIS FUNCTION TO IT
#include<iostream.h>
class DoubleSubscriptedArray{
int rows;
int columns;
int*ptr;
public:
DoubleSubscriptedArray(){rows=1;columns=1;ptr=new int[5];}
friend ostream &operator<<(ostream &stream,DoubleSubscriptedArray ob);
friend istream &operator>>(istream &stream,DoubleSubscriptedArray &ob);
int &operator()(int r,int c);
int getr(){return rows;}
int getc(){return columns;}
DoubleSubscriptedArray operator=(DoubleSubscriptedArray ob);
};
//---------------------------------------------------------------------//
int &DoubleSubscriptedArray::operator()(int r,int c){
return ptr[(r-1)*c+(c-1)];
}
//---------------------------------------------------------------------//
ostream &operator<<(ostream &stream,DoubleSubscriptedArray ob){
cout<<"The Array is: \n";
for(int i=1;i<=(ob.rows*ob.columns);i++){
cout<<ob.ptr[i-1]<<' ';
int j=i%ob.columns;
if(j==0)
cout<<"\n";}
return stream;
}
//--------------------------------------------------------------------//
istream &operator>>(istream &stream,DoubleSubscriptedArray &ob){
cout<<"Enter Number of Rows: \n";
cin>>ob.rows;
cout<<"\nEnter Number of Columns \n";
cin>>ob.columns;
delete []ob.ptr;
ob.ptr=new int[ob.columns*ob.rows];
for(int i=0;i<(ob.rows*ob.columns);i++){
cout<<"Enter value of point number "<<i+1<<" ";
cin>>ob.ptr[i];
cout<<endl;}
return stream;
}
//--------------------------------------------------------------------//
DoubleSubscriptedArray
DoubleSubscriptedArray::operator=(DoubleSubscriptedArray ob){
for(int i=0;i<(ob.rows*ob.columns);i++){
ptr[i]=ob.ptr[i];}
return *this;
}
//--------------------------------------------------------------------//
int main(){
int x,y,z;
DoubleSubscriptedArray d,n;
cout<<"Please enter Info of first object \n";
cin>>d;
cout<<"Please enter Info of second object \n";
cin>>n;
cout<<"The first object is:\n";
cout<<d;
cout<<"Enter the coordinates of point in first object:\n";
cout<<"row number: ";
cin>>x;
cout<<"\ncolumn Number: ";
cin>>y;
if((x>0&&x<=d.getr())&&(y>0&&y<=d.getc())){
cout<<"The value of this point is: \n";
z=d(x,y);
cout<<z;
cout<<endl;}
else
cout<<"Sorry numbers are wrong\n";
cout<<"The second object is:\n";
cout<<n;
if((d.getr()==n.getr())&&(d.getc()==n.getc())){
cout<<"We can assignement objects \n";
n=d;
cout<<"The second object become\n";
cout<<d;}
else
{ cout<<"Sorry we cant assignemet objects!!!\n";}
return 0;
}