Objectives
- Learn binary numbers and how to use recursive functions ● Develop some methods that will be useful in your future!
You can find hw8 note: binary and recursio n on Moodle.
Questions
Question 1: decimalToBinaryIterative
Write a function decimalToBinaryIterative that converts a decimal value to binary using a loop. This function takes a single parameter, a non-negative integer, and returns a string corresponding to the binary representation of the given value.
Function specifications:
- The function name: decimalToBinaryIterative
- The function parameter: An integer to be converted to binary
- Your function should return the binary representation of the given value as a string
- Your function should not print anything
- Your function should use a loop
| Sample main (Be sure to test all methods!) | Expected outputs |
| decimalToBinaryIterative(5) decimalToBinaryIterative(8) | 101
1000 |
The file should be named as iterative.cpp . Don’t forget to head over to the code runner on Moodle and paste your solution in the answer box! In the main, make sure to have test cases.
Question 2: decimalToBinaryRecursive
Write a function decimalToBinaryRecursive that converts a decimal value to binary using recursion. This function takes a single parameter, a non-negative integer, and returns a string corresponding to the binary representation of the given value.
Function specifications:
- The function name: decimalToBinaryRecursive
- The function parameter: An integer to be converted to binary
- Your function should return the binary representation of the given value as a string
- Your function should not print anything
- Your function should use recursion. Loops are not allowed.
| Sample main (Be sure to test all methods!) | Expected outputs |
| decimalToBinaryRecursive(5) decimalToBinaryRecursive(8) | 101
1000 |
The file should be named as recursive.cpp . Don’t forget to head over to the code runner on Moodle and paste your solution in the answer box! In the main, make sure to have test cases.



