prprice16

Untitled

Oct 26th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #include "rectangle.h"
  5.  
  6. //initialize static variable
  7. int Rectangle::count = 0;
  8.  
  9. int Rectangle::getCount()
  10. {
  11. return count;
  12. }
  13. Rectangle::~Rectangle()
  14. {
  15. //cout << "destructor called" << endl;
  16. }
  17.  
  18. Rectangle::Rectangle()
  19. {
  20. //cout << "default constructor called" << endl;
  21. //initialize length and width
  22. length = 1;
  23. width = 1;
  24. //count it
  25. count++;
  26. }
  27.  
  28. //parameterized constructor
  29. Rectangle::Rectangle(double len, double wid)
  30. {
  31. //cout << "parameterized constructor called" << endl;
  32. //store len and wid into the private variables
  33. length = len;
  34. width = wid;
  35. //count it
  36. count++;
  37. }
  38.  
  39. Rectangle::Rectangle(double value)
  40. {
  41. length = width = value;
  42. //count it
  43. count++;
  44. }
  45.  
  46. double Rectangle::getPerim()
  47. {
  48. return 2 * (length + width);
  49. }
  50.  
  51. double Rectangle::getArea() const
  52. {
  53. //cout << "in getArea length is " << length << endl;
  54. //double area; //local variable to getArea
  55. //area = length * width;
  56. //return area;
  57. //calculate and return the area
  58. return length * width;
  59. }
  60.  
  61. bool Rectangle::setLength(double length)
  62. {
  63. //make sure len is good
  64. if (length <= 0) //bad data
  65. return false;
  66. //store len into private variable length
  67. this->length = length;
  68. this->length = length;
  69. return true;
  70.  
  71. }
  72. /*
  73. //class function defintions go here
  74. bool Rectangle::setLength(double len)
  75. {
  76. //make sure len is good
  77. if (len <= 0) //bad data
  78. return false;
  79. //store len into private variable length
  80. length = len;
  81. return true;
  82. }
  83. */
  84. /*
  85. double Rectangle::getLength()
  86. {
  87. //return the value of length
  88. return length;
  89. }
  90. */
  91. void Rectangle::setWidth(double wid)
  92. {
  93. //store wid in width
  94. width = wid;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment