Hi I am trying to fill up an area from a rectangle. I have operator overloading function that returns this number. Question is how do I create a recursive function that will take in the number from the operator overload function and divide that by tiles. Each tile = 2.1*3.2
I understand for a regular simple function, the code would look like this, but I am lost with the operator overload function.
void simple()
{
cout << "this is a simple recursive function" << endl;
simple();
}
I know this will create a continuous loop but Its a good starting point.
I'm not entirely sure what you need recursion for. The operator function you provided is not recursive.
Recursion is useful as an alternative to looping. You can often make looping much simpler by utilizing recursion. However, whenever you use it, you need to ensure that you have an exit condition that leads you to a path which does not invoke another recursive call (similar to a break statement or exit condition in a while loop).
according to the practice problem this is what it shows:
Please add a public recursion function that calculates how many tiles needed to fill up the area of the Rectangle object. Each tile is 2.1*3.2. The result should be an integer (ceiling). Please do NOT use division calculation to get the result (too trivial), but use recursion technique to resolve the issue.
I came up with this so far, get am errpr redifinition of formal parameters 'tile'
Still not sure what you're trying to do, however rect and tile are always set to the orignal value and 6.72 respectively. Therefore you're really just returning x! (x factoral). That's likely to explode with any x greater than 13. What are you trying to do with rect and tile?
Thanks for the response, I don't have the code with me but what I did was have the area of the rectangle subtract the tile. The amount of loops the tile did is the amount of tiles it would take to fill up the area.
In which case your function should take two arguments, AreaOfRectagle and NumberOfTiles. Each recursion will subtract from AreaOfRectangle and add to NumberOfTiles just like you said. Once AreaOfRectangle becomes less than or equal to zero return NumberOfTiles.