Question

In: Computer Science

In 1-3 sentences, describe how you would "Change a number in to a word equivalent (132...

In 1-3 sentences, describe how you would "Change a number in to a word equivalent (132 -> one three two), Recursively" using C++

Solutions

Expert Solution

Description:

  • First we will give a base condition for the recursive function that is if the numbe is equal to zero then renurn the string word.
  • Else extract tha last digit from the number and using switch case add the appropriate word eqivalet.
  • Now make a recursive call with the new word equivalent and the number divided by 10.

The above steps is clearly show in the code below. The above description will become more clear once you go through the code shown below.

CODE--

#include<bits/stdc++.h>
using namespace std;
string word_equivalent(string word,int num)
{
   if(num==0)
   {
       return word;
   }
   switch(num%10)
   {
       case 0:
           word="zero "+word;
           break;
       case 1:
           word="one "+word;
           break;
       case 2:
           word="two "+word;
           break;
       case 3:
           word="three "+word;
           break;
       case 4:
           word="four "+word;
           break;
       case 5:
           word="five "+word;
           break;
       case 6:
           word="six "+word;
           break;
       case 7:
           word="seven "+word;
           break;
       case 8:
           word="eight "+word;
           break;
       case 9:
           word="nine "+word;
           break;                                  
   }
   return word_equivalent(word,num/10);
}
int main()
{
   cout<<"132 = "<< word_equivalent("",132)<<endl;
   cout<<"12311 = "<< word_equivalent("",12311)<<endl;
   cout<<"12300 = "<< word_equivalent("",12300)<<endl;
   cout<<"100 = "<< word_equivalent("",100)<<endl;
}

OUTPUT SCREENSHOT--

NOTE--

Please upvote if you like the effort.


Related Solutions

In 1-3 sentences, describe how you would "Find a path from lab to Del Taco using...
In 1-3 sentences, describe how you would "Find a path from lab to Del Taco using only sidewalks on an island", Recursively using C++
1. In a few sentences, describe how the functionality of vApps would be useful in a...
1. In a few sentences, describe how the functionality of vApps would be useful in a multi-tier application.
write a few English sentences describing how you would change the Linked-Chain implementation of the List...
write a few English sentences describing how you would change the Linked-Chain implementation of the List ADT to support removal of a node from the middle retaining order. Write PSEUDOCODE to insert a node at position 2 in a doubly-linked list (assume position follows classic indexing from 0 to item_count - 1)
In 3-5 sentences, Describe the kind of economic conditions that should exist before you would prescribe...
In 3-5 sentences, Describe the kind of economic conditions that should exist before you would prescribe designating an Enterprise Zone?
How would you best define Parallelism? In a 500-word paper describe describe parallelism and the different...
How would you best define Parallelism? In a 500-word paper describe describe parallelism and the different types of parallelism. Your answer should include the following: What Parallelism is and means. Define what events are and name a few examples. What is meant when we say Parallelism can be involved on several levels? Give some examples of these levels.
3) How would you define the number of layers when designing a circuit board? How would...
3) How would you define the number of layers when designing a circuit board? How would you organize them?
1) Describe, with 2-3 sentences for each, Type I and Type II Diabetes. How are they...
1) Describe, with 2-3 sentences for each, Type I and Type II Diabetes. How are they different from each other? 2) List at least 3-4 risk factors/causes for CVD 3) What are the top three types of cancer in men? Which are the top three types of cancer for women? 4) Which geographical regions of the world is tobacco use most prevalent? 5) List some of the health issues associated with alcohol abuse? List some of the social issues associated...
In your own word please explain and write in complete sentences. How do you care for...
In your own word please explain and write in complete sentences. How do you care for bleeding injury? What is shock? How do you care for it? What is asthma? How do you care for it? What is anaphylaxis? How do you care for it?
·       How would you describe your social competence as a young child? Did it change over...
·       How would you describe your social competence as a young child? Did it change over middle childhood? ·       Were you a high or a low status child then? ·       Did you play predominantly with high or low status children? ·       Were you popular? ·       Think of a popular child in your school and an unpopular child (first names only). o    Describe the popular child. Make sure you consider the characteristics that contributed to this child's popularity. § How do...
(a) In 3-4 sentences, describe what you understand by the term social CRM; and (b) Describe...
(a) In 3-4 sentences, describe what you understand by the term social CRM; and (b) Describe three factors that are driving it.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT