Don't like ads? PRO users don't see any ads ;-)
Guest

2darryJayPATEL1234

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.15 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <TwoD.h>
  2.  
  3. TwoD::TwoD()
  4. {
  5.     maxCols = 1;
  6.     maxRows = 1;
  7.  
  8.     mAry = new DoubleAryPtr[maxRows];
  9.  
  10.     for(int i=0; i<maxCols; i++)
  11.         mAry[i]=new double[maxRows];
  12. }
  13.  
  14. TwoD::TwoD(int a1, int a2)
  15. {
  16.     maxRows = a1;
  17.     maxCols = a2;
  18.  
  19.     mAry = new DoubleAryPtr[maxRows];
  20.  
  21.     for(int i=0; i<maxCols; i++)
  22.         mAry[i]=new double[maxRows];
  23. }
  24.  
  25. //copy constructor
  26. TwoD::TwoD(const TwoD& ary1, const TwoD& ary2)
  27. {
  28.     for(int i=0; i<maxRows; i++)
  29.     {
  30.         for(int j=0; j<maxCols; j++)
  31.             ary1.mAry[i][j]=ary1.mAry[i][j];
  32.     }
  33. }
  34.  
  35. TwoD::~TwoD()
  36. {
  37.     for(int i=0; i<maxRows; i++)
  38.         delete []mAry[i];
  39.  
  40.     delete []mAry;
  41. }
  42.  
  43. void TwoD::setElement(int b1, int b2)
  44. {
  45.     mAry[b1][b2]=1;
  46. }
  47.  
  48. double TwoD::getElement(int c1, int c2)const
  49. {
  50.     return mAry[c1][c2];
  51. }
  52.  
  53. TwoD TwoD::operator +(const TwoD& addAry1)
  54. {
  55.     TwoD sumAry;
  56.  
  57.     for(int i=0; i<maxRows; i++)
  58.     {
  59.         for(int j=0; j<maxCols; j++)
  60.             sumAry.mAry[i][j]=(addAry1.mAry[i][j]+addAry1.mAry[i][j]);
  61.     }
  62. }
  63.  
  64. TwoD TwoD::operator =(const TwoD& equalAry1)
  65. {
  66.     return (equalAry1.mAry=equalAry1.mAry);
  67. }