Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ I have a rectangle object with two sides and need a function to recursivly i

ID: 3663673 • Letter: C

Question

C++ I have a rectangle object with two sides and need a function to recursivly increase each side member variable 'n' times.

void incSides(int n);

will increase the length of each side n times recursively (see description below)

For the function incSides(int n) you must come up with a recursive solution to increase each side n times. Yes, this is the same as multiplying each side by n. Yes, this could be done in a loop very easily. No, you may not do either of those things. This is to practice recursion so your solution must use recursion. Remember that each recursive function needs to have a base case(s) and a recursive step.

Explanation / Answer

Shape.h:



Shape.cpp:



Triangle.h:



Triangle.cpp:



Rectangle.h:



Rectangle.cpp:




Square.h:




Square.cpp:




main.cpp:

  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  
  #ifndef SHAPE_H  #define SHAPE_H    class Shape{    // This is the base class!            public:                  Shape();                  float get_area();            private:                  float area, perimeter;    };    #endif