fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Rectangle {
  5. public:
  6. void SetSize(int heightVal, int widthVal) {
  7. height = heightVal;
  8. width = widthVal;
  9. }
  10. int GetArea() const;
  11. int GetPerimeter() const;
  12.  
  13. private:
  14. int height;
  15. int width;
  16. };
  17.  
  18. int Rectangle::GetArea() const {
  19. return height * width;
  20. }
  21.  
  22. int Rectangle::GetPerimeter() const {
  23. return (height * 2) + (width * 2);
  24. }
  25.  
  26. int main() {
  27. Rectangle myRectangle;
  28.  
  29. myRectangle.SetSize(1, 1);
  30. if (myRectangle.GetArea() != 1) {
  31. cout << "FAILED GetArea() for 1, 1" << endl;
  32. }
  33. if (myRectangle.GetPerimeter() != 3) {
  34. cout << "FAILED GetPerimeter() for 1, 1" << endl;
  35. }
  36.  
  37. myRectangle.SetSize(2, 3);
  38. if (myRectangle.GetArea() != 8) {
  39. cout << "FAILED GetArea() for 2, 3" << endl;
  40. }
  41. if (myRectangle.GetPerimeter() != 10) {
  42. cout << "FAILED GetPerimeter() for 2, 3" << endl;
  43. }
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
FAILED GetPerimeter() for 1, 1
FAILED GetArea() for 2, 3