1. Write a program in C++ that can convert a given integer value
into words. Assume the largest integer value to be 999 billion
For an input of say 1108 your out should be ONE THOUSAND
ONE HUNDRED AND EIGHT​

Answers

Answer 1

Answer:

Hope this works

#include <iostream>

   #include <string>

   #include <vector>

   using namespace std;

   string digitName(int digit);

   string teenName(int number);

   string tensName(int number);

   string intName(int number);

   vector<string> ones {"","one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

   vector<string> teens {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen","sixteen", "seventeen", "eighteen", "nineteen"};

   vector<string> tens {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};

   string nameForNumber (long number) {

       if (number < 10) {

           return ones[number];

       } else if (number < 20) {

           return teens [number - 10];

       } else if (number < 100) {

           return tens[number / 10] + ((number % 10 != 0) ? " " + nameForNumber(number % 10) : "");

       } else if (number < 1000) {

           return nameForNumber(number / 100) + " hundred" + ((number % 100 != 0) ? " " + nameForNumber(number % 100) : "");

       } else if (number < 1000000) {

           return nameForNumber(number / 1000) + " thousand" + ((number % 1000 != 0) ? " " + nameForNumber(number % 1000) : "");

       } else if (number < 1000000000) {

           return nameForNumber(number / 1000000) + " million" + ((number % 1000000 != 0) ? " " + nameForNumber(number % 1000000) : "");

       } else if (number < 999000000001) {

           return nameForNumber(number / 1000000000) + " billion" + ((number % 1000000000 != 0) ? " " + nameForNumber(number % 1000000000) : "");

       }

       return "error";

   }

   int main()

   {

       long input;

       do

       {

           cout << "Please enter a positive integer: ";    

           cin >> input;

           cout << "\n" << nameForNumber(input) << endl;

           cout << "\n\n" << endl;

       }while (input > 0);

       return 0;

   }


Related Questions

Using the chores.csv file fat the very bottom; write an awk script to return the average number of minutes required to complete a chore. Your solution must handle an undefined number of chores. zero points will be given to solutions that use a static number in their calculation.
Format floating point numbers to 2 decimal places.
Example output;
Average: 28.12
chores.csv
Chore Name,Assigned to,estimate,done?
Laundry,Chelsey,45,N
Wash Windows,Sam,60,Y
Mop kitchen,Sam,20,N
Clean cookware,Chelsey,30,N
Unload dishwasher,Chelsey,10,N
Dust living room,Chelsey,20,N
Wash the dog,Sam,40,N

Answers

Answer: Provided in the explanation section

Explanation:

According to the question:

Using the chores.csv file fat the very bottom; write an awk script to return the average number of minutes required to complete a chore. Your solution must handle an undefined number of chores. zero points will be given to solutions that use a static number in their calculation.

Format floating point numbers to 2 decimal places.

Example output;

Average: 28.12

chores.csv

Chore Name,Assigned to,estimate,done?

Laundry,Chelsey,45,N

Wash Windows,Sam,60,Y

Mop kitchen,Sam,20,N

Clean cookware,Chelsey,30,N

Unload dishwasher,Chelsey,10,N

Dust living room,Chelsey,20,N

Wash the dog,Sam,40,N

ANSWER:

BEGIN{

FS=","

}

{

if(NR!=1)

sum += $3

}

END{

avg=sum/NR

printf("Average: %.2f ", avg)

}' ./chores.csv

cheers i hope this helped !!

Write a script called checkLetter.sh Review Greeting.sh for an example. Use a read statement and ask user to "Enter A, B, or C: "

If user types A, echo "You entered A"
If user types B, echo " You entered B"
If user types C, echo " You entered C"
Use the case structure to test the user’s string.
If user types any letter from lower case ‘a through z’ or upper case ‘D through Z’, echo "You did not enter A, B, or C".

Answers

Answer:

The code is given as below: The input and output is as given for one case.

Explanation:

echo -e "Enter A, B or C : \c" #Printing the line on the screen

read -rN 1 test #read the character in the variable test

echo

case $test in #Setting up the case structure for variable test

[[:lower:]] ) #checking all lower case letters

echo You did not enter A, B or C;;

[D-Z] ) #checking upper case letters from D to Z

echo You did not enter A, B or C;;

A ) #Condition to check A

echo You entered A;;

B ) #Condition to check B

echo You entered B;;

C ) #Condition to check C

echo You entered C;;

esac #Exiting the case structure

Other Questions
Which of the following hormones is synthesized in hypothalmus and secreted from pitutary? Vasopressi or adrenocorticotropic hormones What is the character of revising Maya sells candles to her 5 neighbors. Each neighbor buys 2 boxes of candles. There are 6 candles in each box. What is the total number of candles that all of her neighbors will get? Outline the procedure for finding probabilities of any given compound events. My lady, never a man in the wide world should have a fault to find with you. Your name has gone out under heaven like the sweet honor of some god-fearing king, who rules in equity over the strong: his black lands bear both wheat and barley, fruit trees laden bright, new lambs at lambing timeand the deep sea gives great hauls of fish by his good strategy, his folk fare well. Based on the epic simile, the reader should envision Penelope as a queen who is conscientious. decisive. judgmental. righteous. On a coordinate plane, a curved line with minimum values of (negative 0.5, negative 7) and (2.5, negative 1), and a maximum value of (1.5, 1), crosses the x-axis at (negative 1, 0), (1, 0), and (3, 0), and crosses the y-axis at (0, negative 6). Which interval for the graphed function contains the local maximum? To eliminate the y-terms and solve for x in the fewest steps, by which constants should the equations be multiplied by before adding the equations together? First Equation: 5x 4y = 28 Second equation: 3x - 9y = 30 Which best describes the authors purpose in including this anecdote for Black Boy need of constitution Discuss how the air pollution produced in one country can affect country. Is it possible for polluted water to be transported to another country Read the excerpt from chapter 6 of Lizzie Bright and the Buckminster Boy. One afternoon, after another dreary Sunday, he walked home from Mrs. Cobb's with the sea breeze determined to shove him to Malaga Island. It scooted around him and pulled at his ears. It threw up the dust of the road into his face to turn him around, and when he leaned into it, it suddenly let go and pushed at him from behind, laughing. But with the iron word forbidden tolling like a heavy bell by his ears, Turner would not let himself be brought to Malaga. And so with a last abrupt kick, the sea breeze twisted around and left him. Turner watched it rushing pell-mell down Parker Head and toward the shore. "Go find Lizzie," he whispered. In this excerpt, which indicates that the story is being told from the third-person point of view? Turner refers to himself as I, and the reader is able to hear his thoughts and feelings. Turner is referred to as he, and the reader is able to hear his thoughts and feelings. The narrator describes in great detail Turners words and actions but not his thoughts. The narrator describes in great detail Turners thoughts but not his words or actions. 1.46 g H2 is allowed to react with 10.5 g N2, producing 2.72 g NH3. What is the theoretical yield in grams for this reaction under the given conditions?Express your answer to three significant figures and include the appropriate units. a kangaroo and a wallaby are in a race. They have to get to a flagbole that is 100 meters away and back. For every 2 hops the kangaroo does, the wallaby does three but the kangaroo's jumps are 3 meters while the wallaby's are 2. Who gets there and back first (hint: it isnt a draw) the frequency of down syndrom increase with the age of parents ? Which of the following expressions can be used to find the area of the polygon? Select all that apply.An irregular shape that is a rectangle with a piece missing from the upper right corner. The bottom length is twenty feet. The left side width is nine feet. The top length is eighteen feet with a rectangle cut out of the upper right corner. The right side width is six feet.A.(9 20) 6B.(9 18) (6 2)C.(9 18) + (6 2)D.(20 6) + (18 3)E.(20 9) (3 2) The debate on the effects of raising the minimum wage is ongoing. A few years ago, Seattle, Los Angeles, and San Francisco passed laws to gradually raise the minimum wage to $15/hour. Beaudry, Paul, David A. Green, and Ben M. Sand (investigated the possible effects of these laws on the labor market and concluded that "...for workers below $10 per hour in Seattle, the employment rate declines by over 10 percent in response to raising the minimum wage to $15. Meanwhile, for the larger group with wages at or below $15, the decline is approximately 7 percent." The authors' conclusion is consistent with the specific economic theory discussed in the course that In the spinner below, what is the probability of landingon 6?A. 1/4B. 1/8C. 1/3D. 1/6 In general, the probability that a blood donor has Type A blood is 0.40.Consider 8 randomly chosen blood donors, what is the probability that more than half of them have Type A blood? EQ: What happened with the clock while Gatsby wasreacquainting himself with Daisy? How would youdescribe the scene between the two of them? What fearsdoes Gatsby share with Nick when they step aside fromDaisy? What is the slope of the line passing through the points (1,2) and (5,4)? 2 1/2 2 1