[SOLVED] CSCI1300 Homework 8-Binary numbers and recursive functions

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon HW-8-mfz7d4.zip (98 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
Rate this product

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.

 

 

  • HW-8-mfz7d4.zip