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;
}

Recommended Answers

All 6 Replies

Please Some One Help

Depending on your needs and knowledge something along these lines might work. This is only a rough outline of one possible way to proceed. If it looks like something that might suffice, it's up to you to fill in the details.

template <T>    //use templated class for a general case class
class DblSSA  
{
   T ** internalArray;  //declare size of internalArray using dynamic memory in constructor
   int r;
   int c;
  . 
  .
  .
}

class IntDblSSSA  //int specialization of prior template class
{
   DblSSSa <int> idsa;   //object of templated class only allowing int as type
   .
   .  
   .
   int sumOfArrayElements()  //find sum of all elements
   {
     int sum = 0;  //initialize variable to zero
     for each row
       for each col
           sum += given element of idsa.internalArray
     return sum       
   }
}

int main()
  IntDblSSSA idsssa;  //declare an object of desired type
  int result = idsssa.sumOfArrayElements()
  cout << result

thanks learner but if you do not mind would you write it complete because when i work on it some errors appear and i have to finish it today please

here is the code and the errors appear

#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;
}
//--------------------------------------------------------------------//
template <class T>    //use templated class for a general case class
int DblSSA () 
{
   T ** internalArray;  //declare size of internalArray using dynamic memory in constructor
   int r;
   int c;
 
}
//-------------------------------------------------------------------//
class IntDblSSSA  //int specialization of prior template class
{
 IntDblSSSA <int> idsa;   //object of templated class only allowing int as type
  
   int sumOfArrayElements()  //find sum of all elements
   {
     int sum = 0;  //initialize variable to zero
     for each_row
       for each_col
           sum += given element of idsa.internalArray
     return sum       
   }
};

 //------------------------------------------------------------------// 
int main(){
	int x,y,z;
  DoubleSubscriptedArray d,n;
  IntDblSSSA idsssa;  //declare an object of desired type
  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";}
  
  int result;
	  result= idsssa.sumOfArrayElements();
  cout << result<<endl;

return 0;
}

errors are:

--------------------Configuration: sh5 - Win32 Debug--------------------
Compiling...
1.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\sh5\1.cpp(70) : error C2059: syntax error : '<'
C:\Program Files\Microsoft Visual Studio\MyProjects\sh5\1.cpp(70) : error C2238: unexpected token(s) preceding ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\sh5\1.cpp(118) : error C2248: 'sumOfArrayElements' : cannot access private member declared in class 'IntDblSSSA'
C:\Program Files\Microsoft Visual Studio\MyProjects\sh5\1.cpp(72) : see declaration of 'sumOfArrayElements'
Error executing cl.exe.

sh5.exe - 3 error(s), 0 warning(s)

UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU

I've more if you want them ;)

why not any way I have give t already because today is the only day

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.