Please I Need U Again

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2005
Posts: 129
Reputation: some one is an unknown quantity at this point 
Solved Threads: 0
some one some one is offline Offline
Junior Poster

Please I Need U Again

 
0
  #1
Dec 16th, 2005
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

  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. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 129
Reputation: some one is an unknown quantity at this point 
Solved Threads: 0
some one some one is offline Offline
Junior Poster

Re: Please I Need U Again

 
0
  #2
Dec 16th, 2005
Please Some One Help
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,678
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 263
Lerner Lerner is offline Offline
Posting Virtuoso

Re: Please I Need U Again

 
0
  #3
Dec 16th, 2005
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.
  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
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 129
Reputation: some one is an unknown quantity at this point 
Solved Threads: 0
some one some one is offline Offline
Junior Poster

Re: Please I Need U Again

 
0
  #4
Dec 16th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 129
Reputation: some one is an unknown quantity at this point 
Solved Threads: 0
some one some one is offline Offline
Junior Poster

Re: Please I Need U Again

 
0
  #5
Dec 16th, 2005
here is the code and the errors appear

  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)
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Please I Need U Again

 
0
  #6
Dec 17th, 2005
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU

I've more if you want them
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 129
Reputation: some one is an unknown quantity at this point 
Solved Threads: 0
some one some one is offline Offline
Junior Poster

Re: Please I Need U Again

 
0
  #7
Dec 17th, 2005
why not any way I have give t already because today is the only day
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC