Recursive Multiplication

advertisement
Multiplication, Recursively
The goal for this exercise is to practice writing (increasingly complex) recursive
code.
For this exercise, you need to implement the MultR method in the
provided RecursiveMethods class.
This class should be found in the Student_Answers.cs file in a project
named something like 03_PCE_StudentCode. The method should take two
integer parameters, and will return the product of them. You're not allowed to
simply multiply the two numbers inside the function, and return the value, though
– you need to find a way, by using simpler mathematical operations on the
values that you pass to the successive recursive calls, to get this to happen.
MultR needs to correctly calculate the result of multiplying any two whole
numbers – positive, negative, and zero.
Once you’ve done this, make sure that all the tests in the
NUnit_Tests_Recursive_Multiplication class pass.
What you need to do for this exercise:
1. Implement MultR, as described above
a. Note that the best way to approach this is to have two methods – a
public method that other classes are intended to call (that handles any
one-time, "initialization" type work), and a private method (this is the
one that's actually recursive)
2. Once you’ve completed the above task, you should run the tests in the
NUnit_Tests_Recursive_Multiplication class. They should all pass at this
point, and if not, then you should fix your program so that those tests do pass.
You can run the tests using the NUnit support in the provided starter project.
You should feel free to supplement that code with your own test cases if you
wish, but you are neither required nor expected to.
Download