944,059 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1687
  • C++ RSS
Dec 16th, 2005
0

Please I Need U Again

Expand Post »
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

C++ Syntax (Toggle Plain Text)
  1. #include<iostream.h>
  2.  
  3.  
  4. class DoubleSubscriptedArray{
  5.  
  6. int rows;
  7. int columns;
  8. int*ptr;
  9. public:
  10.  
  11. DoubleSubscriptedArray(){rows=1;columns=1;ptr=new int[5];}
  12. friend ostream &operator<<(ostream &stream,DoubleSubscriptedArray ob);
  13. friend istream &operator>>(istream &stream,DoubleSubscriptedArray &ob);
  14. int &operator()(int r,int c);
  15. int getr(){return rows;}
  16. int getc(){return columns;}
  17. DoubleSubscriptedArray operator=(DoubleSubscriptedArray ob);
  18.  
  19. };
  20. //---------------------------------------------------------------------//
  21.  
  22. int &DoubleSubscriptedArray::operator()(int r,int c){
  23. return ptr[(r-1)*c+(c-1)];
  24. }
  25. //---------------------------------------------------------------------//
  26. ostream &operator<<(ostream &stream,DoubleSubscriptedArray ob){
  27.  
  28. cout<<"The Array is: \n";
  29. for(int i=1;i<=(ob.rows*ob.columns);i++){
  30. cout<<ob.ptr[i-1]<<' ';
  31. int j=i%ob.columns;
  32. if(j==0)
  33. cout<<"\n";}
  34. return stream;
  35. }
  36. //--------------------------------------------------------------------//
  37. istream &operator>>(istream &stream,DoubleSubscriptedArray &ob){
  38. cout<<"Enter Number of Rows: \n";
  39. cin>>ob.rows;
  40. cout<<"\nEnter Number of Columns \n";
  41. cin>>ob.columns;
  42. delete []ob.ptr;
  43. ob.ptr=new int[ob.columns*ob.rows];
  44. for(int i=0;i<(ob.rows*ob.columns);i++){
  45. cout<<"Enter value of point number "<<i+1<<" ";
  46. cin>>ob.ptr[i];
  47. cout<<endl;}
  48. return stream;
  49. }
  50. //--------------------------------------------------------------------//
  51. DoubleSubscriptedArray
  52. DoubleSubscriptedArray::operator=(DoubleSubscriptedArray ob){
  53. for(int i=0;i<(ob.rows*ob.columns);i++){
  54. ptr[i]=ob.ptr[i];}
  55. return *this;
  56. }
  57. //--------------------------------------------------------------------//
  58. int main(){
  59. int x,y,z;
  60. DoubleSubscriptedArray d,n;
  61. cout<<"Please enter Info of first object \n";
  62. cin>>d;
  63. cout<<"Please enter Info of second object \n";
  64. cin>>n;
  65. cout<<"The first object is:\n";
  66. cout<<d;
  67. cout<<"Enter the coordinates of point in first object:\n";
  68. cout<<"row number: ";
  69. cin>>x;
  70. cout<<"\ncolumn Number: ";
  71. cin>>y;
  72. if((x>0&&x<=d.getr())&&(y>0&&y<=d.getc())){
  73. cout<<"The value of this point is: \n";
  74. z=d(x,y);
  75. cout<<z;
  76. cout<<endl;}
  77. else
  78. cout<<"Sorry numbers are wrong\n";
  79.  
  80. cout<<"The second object is:\n";
  81. cout<<n;
  82.  
  83. if((d.getr()==n.getr())&&(d.getc()==n.getc())){
  84. cout<<"We can assignement objects \n";
  85. n=d;
  86. cout<<"The second object become\n";
  87. cout<<d;}
  88. else
  89. { cout<<"Sorry we cant assignemet objects!!!\n";}
  90.  
  91. return 0;
  92. }
Reputation Points: 10
Solved Threads: 0
Junior Poster
some one is offline Offline
129 posts
since Apr 2005
Dec 16th, 2005
0

Re: Please I Need U Again

Please Some One Help
Reputation Points: 10
Solved Threads: 0
Junior Poster
some one is offline Offline
129 posts
since Apr 2005
Dec 16th, 2005
0

Re: Please I Need U Again

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)
  1. template <T> //use templated class for a general case class
  2. class DblSSA
  3. {
  4. T ** internalArray; //declare size of internalArray using dynamic memory in constructor
  5. int r;
  6. int c;
  7. .
  8. .
  9. .
  10. }
  11.  
  12. class IntDblSSSA //int specialization of prior template class
  13. {
  14. DblSSSa <int> idsa; //object of templated class only allowing int as type
  15. .
  16. .
  17. .
  18. int sumOfArrayElements() //find sum of all elements
  19. {
  20. int sum = 0; //initialize variable to zero
  21. for each row
  22. for each col
  23. sum += given element of idsa.internalArray
  24. return sum
  25. }
  26. }
  27.  
  28. int main()
  29. IntDblSSSA idsssa; //declare an object of desired type
  30. int result = idsssa.sumOfArrayElements()
  31. cout << result
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Dec 16th, 2005
0

Re: Please I Need U Again

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
Reputation Points: 10
Solved Threads: 0
Junior Poster
some one is offline Offline
129 posts
since Apr 2005
Dec 16th, 2005
0

Re: Please I Need U Again

here is the code and the errors appear

C++ Syntax (Toggle Plain Text)
  1. #include<iostream.h>
  2.  
  3.  
  4.  
  5. class DoubleSubscriptedArray{
  6.  
  7. int rows;
  8. int columns;
  9. int*ptr;
  10. public:
  11.  
  12. DoubleSubscriptedArray(){rows=1;columns=1;ptr=new int[5];}
  13. friend ostream &operator<<(ostream &stream,DoubleSubscriptedArray ob);
  14. friend istream &operator>>(istream &stream,DoubleSubscriptedArray &ob);
  15. int &operator()(int r,int c);
  16. int getr(){return rows;}
  17. int getc(){return columns;}
  18. DoubleSubscriptedArray operator=(DoubleSubscriptedArray ob);
  19.  
  20. };
  21. //---------------------------------------------------------------------//
  22.  
  23. int &DoubleSubscriptedArray::operator()(int r,int c){
  24. return ptr[(r-1)*c+(c-1)];
  25. }
  26. //---------------------------------------------------------------------//
  27. ostream &operator<<(ostream &stream,DoubleSubscriptedArray ob){
  28.  
  29. cout<<"The Array is: \n";
  30. for(int i=1;i<=(ob.rows*ob.columns);i++){
  31. cout<<ob.ptr[i-1]<<' ';
  32. int j=i%ob.columns;
  33. if(j==0)
  34. cout<<"\n";}
  35. return stream;
  36. }
  37. //--------------------------------------------------------------------//
  38. istream &operator>>(istream &stream,DoubleSubscriptedArray &ob){
  39. cout<<"Enter Number of Rows: \n";
  40. cin>>ob.rows;
  41. cout<<"\nEnter Number of Columns \n";
  42. cin>>ob.columns;
  43. delete []ob.ptr;
  44. ob.ptr=new int[ob.columns*ob.rows];
  45. for(int i=0;i<(ob.rows*ob.columns);i++){
  46. cout<<"Enter value of point number "<<i+1<<" ";
  47. cin>>ob.ptr[i];
  48. cout<<endl;}
  49. return stream;
  50. }
  51. //--------------------------------------------------------------------//
  52. DoubleSubscriptedArray
  53. DoubleSubscriptedArray::operator=(DoubleSubscriptedArray ob){
  54. for(int i=0;i<(ob.rows*ob.columns);i++){
  55. ptr[i]=ob.ptr[i];}
  56. return *this;
  57. }
  58. //--------------------------------------------------------------------//
  59. template <class T> //use templated class for a general case class
  60. int DblSSA ()
  61. {
  62. T ** internalArray; //declare size of internalArray using dynamic memory in constructor
  63. int r;
  64. int c;
  65.  
  66. }
  67. //-------------------------------------------------------------------//
  68. class IntDblSSSA //int specialization of prior template class
  69. {
  70. IntDblSSSA <int> idsa; //object of templated class only allowing int as type
  71.  
  72. int sumOfArrayElements() //find sum of all elements
  73. {
  74. int sum = 0; //initialize variable to zero
  75. for each_row
  76. for each_col
  77. sum += given element of idsa.internalArray
  78. return sum
  79. }
  80. };
  81.  
  82. //------------------------------------------------------------------//
  83. int main(){
  84. int x,y,z;
  85. DoubleSubscriptedArray d,n;
  86. IntDblSSSA idsssa; //declare an object of desired type
  87. cout<<"Please enter Info of first object \n";
  88. cin>>d;
  89. cout<<"Please enter Info of second object \n";
  90. cin>>n;
  91. cout<<"The first object is:\n";
  92. cout<<d;
  93. cout<<"Enter the coordinates of point in first object:\n";
  94. cout<<"row number: ";
  95. cin>>x;
  96. cout<<"\ncolumn Number: ";
  97. cin>>y;
  98. if((x>0&&x<=d.getr())&&(y>0&&y<=d.getc())){
  99. cout<<"The value of this point is: \n";
  100. z=d(x,y);
  101. cout<<z;
  102. cout<<endl;}
  103. else
  104. cout<<"Sorry numbers are wrong\n";
  105.  
  106. cout<<"The second object is:\n";
  107. cout<<n;
  108.  
  109. if((d.getr()==n.getr())&&(d.getc()==n.getc())){
  110. cout<<"We can assignement objects \n";
  111. n=d;
  112. cout<<"The second object become\n";
  113. cout<<d;}
  114. else
  115. { cout<<"Sorry we cant assignemet objects!!!\n";}
  116.  
  117. int result;
  118. result= idsssa.sumOfArrayElements();
  119. cout << result<<endl;
  120.  
  121. return 0;
  122. }


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)
Reputation Points: 10
Solved Threads: 0
Junior Poster
some one is offline Offline
129 posts
since Apr 2005
Dec 17th, 2005
0

Re: Please I Need U Again

UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU

I've more if you want them
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Dec 17th, 2005
0

Re: Please I Need U Again

why not any way I have give t already because today is the only day
Reputation Points: 10
Solved Threads: 0
Junior Poster
some one is offline Offline
129 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: linked list small problem with Insert Function
Next Thread in C++ Forum Timeline: Strings V's Char Arrays[]





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC