Recursively Printing Even Numbers

advertisement
Recursively Printing Even Numbers
The goal for this exercise is to start writing recursive code. You’ll start here,
with a task that resembles previous code samples that you’ve seen, but that is
different enough that you (hopefully) will have to give the task some thought.
For this exercise, you need to implement the
PrintEvenNumbers_Iteratively 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. This class will print out only even
numbers, from N down to 0 (including zero), using a perfectly normal loop. The
objective here is to code up the problem in a simple, straight-forward way that will
allow you visually see what work is being done at each step of the program.
You may want to use the Recursively_Printing_Even_Numbers.
RunExercise method (in the Program.cs file, in the same project) to informally
test this yourself (remember to set this project as the Startup Project in order to
run this program).
Once you’ve done that, implement the PrintEvenNumbers_Recursively
method in your RecursiveMethods class. This should print out only even
numbers, from N down to 0 (including zero), but this time will do so recursively.
Once you’ve done this, make sure that all the tests in the
NUnit_Tests_PrintEven_Recursive class pass.
What you need to do for this exercise:
1. Implement the PrintEvenNumbers_Iteratively method to print even numbers
using a loop
a. Optionally, test this out on your own, using the Program.cs file.
b. The format of the output must match what the NUnit test is expecting
EXACTLY. Here's an example of 'correct' output, when told to print
values starting with 5 (notice that 5 is not even)
Argument: 4
Argument: 2
Argument: 0
i. You'll need to match the spelling, capitalization, and spacing
exactly (there's 1 space between the "Argument:" and the
number). Anything else will cause the test to fail.
2. Implement the PrintEvenNumbers_Recursively method that will print even
numbers recursively.
3. Once you’ve completed the above tasks, you should run the tests in the
NUnit_Tests_PrintEven_Recursive 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