fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Rectangle {
  5. public:
  6. void SetSize(int heightVal, int widthVal) {
  7. height = 2;
  8. width = 3;
  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, 4);
  30. if (myRectangle.GetArea() != 4) {
  31. cout << "FAILED GetArea() for 1, 4" << endl;
  32. }
  33. if (myRectangle.GetPerimeter() != 10) {
  34. cout << "FAILED GetPerimeter() for 1, 4" << endl;
  35. }
  36.  
  37. myRectangle.SetSize(2, 6);
  38. if (myRectangle.GetArea() != 12) {
  39. cout << "FAILED GetArea() for 2, 6" << endl;
  40. }
  41. if (myRectangle.GetPerimeter() != 16) {
  42. cout << "FAILED GetPerimeter() for 2, 6" << endl;
  43. }
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
FAILED GetArea() for 1, 4
FAILED GetArea() for 2, 6
FAILED GetPerimeter() for 2, 6