Starting Out with C++ from Control Structures to Objects, Student Value Edition (9th Edition)
Starting Out with C++ from Control Structures to Objects, Student Value Edition (9th Edition)
9th Edition
ISBN: 9780134443829
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 20, Problem 2PC
Program Plan Intro

Recursive conversion

Program Plan:

  • Include the required header files.
  • Declare the necessary function prototype and constants.
  • Define the main () function.
    • Declare the necessary variables to get the input.
    • Get the required input from the user.
    • Call the method “sign()” to indicate the sign.
    • User input gets validated and call the function recursively for the user given input.
  • Define the “sign()” method
    • Declare the necessary variables
    • Validates the value given by the user using “if” statement.
    • If the condition becomes true, it will call the function recursively for the number of times based on the input provided by the user.
    • If the condition becomes false, it gets returned to the “main()” method.

Blurred answer
Students have asked these similar questions
Consider the following function: void fun_with_recursion(int x) { printf("%i\n", x); fun_with_recursion(x + 1); } What will happen when this function is called by passing it the value 0?
Write a recursive function that converts a decimal number into a binary number as a string. The function header is: string decimalToBinary(int value) Write a test program that prompts the user to enter a decimal number and dis- plays its binary equivalent.
For glass box testing of a recursive function, you should test cases where: a) the function returns without a recursive call, ie using a base case b) the function makes exactly one recursive call c) the function makes more than one recursive call d) all of these
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning