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++
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?
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...
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?
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.
1. For each of the following sentences, fill in the blanks with the correct word or...
1. For each of the following sentences, fill in the blanks with the correct word or phrase from the list below. You may use a term more than once in this section. 2 pts Plasma membrane proteins are synthesized in the ___. Proteins are transported into the Golgi apparatus via ___. Nuclear proteins are synthesized in the___. Acid hydrolase enzymes are taken to the ____ after they are synthesized. All proteins being transported out of the cell pass through the...
Question 1: (a) Under what circumstances would the number of equivalent units of materials differ from...
Question 1: (a) Under what circumstances would the number of equivalent units of materials differ from the number of equivalent units of labor and overhead in the same department in the same period? Under what circumstances would they be the same? (b) Units are usually assumed to be at the same stage of completion for both labor and overhead. What is the reason for this assumption? (c) Would an automobile plant that makes specialty race cars use job costing or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT