Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. class GeometricalObject
  2. {
  3. public:
  4.     double Length = 0;
  5.     double SurfaceArea = 0;
  6.  
  7. protected:
  8.     virtual double GetSurfaceArea();
  9. };
  10.  
  11.  
  12. class Square :
  13.     public GeometricalObject
  14. {
  15. public:
  16.     Square(double length);
  17.  
  18.     double GetLength();
  19.     void SetLength(double value);
  20.  
  21.     double GetSurfaceArea() override;
  22.  
  23. };
  24.  
  25. // dont forget the scope
  26. Square::Square(double length)
  27. {
  28.     this->Length = length;
  29.     this->SurfaceArea = GetSurfaceArea();
  30. }
  31.  
  32. // dont forget the scope
  33. double Square::GetLength()
  34. {
  35.     return Length;
  36. }
  37.  
  38. // dont forget the scope
  39. void Square::SetLength(double value)
  40. {
  41.     if (value >= 0)
  42.     {
  43.         GeometricalObject::Length = value;
  44.     }
  45. }
  46.  
  47. // dont forget the scope
  48. double Square::GetSurfaceArea()
  49. {
  50.     return this->Length * this->Length;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement