| | |
Please I Need U Again
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2005
Posts: 129
Reputation:
Solved Threads: 0
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
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
C++ Syntax (Toggle Plain Text)
#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; }
•
•
Join Date: Jul 2005
Posts: 1,678
Reputation:
Solved Threads: 263
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.
C++ Syntax (Toggle Plain Text)
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
•
•
Join Date: Apr 2005
Posts: 129
Reputation:
Solved Threads: 0
here is the code and the errors appear
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)
C++ Syntax (Toggle Plain Text)
#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)
![]() |
Other Threads in the C++ Forum
- Previous Thread: linked list small problem with Insert Function
- Next Thread: Strings V's Char Arrays[]
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






