Question: I need my C++ code to translate numbers into words. For example: 1234 would be one thousand two hundred thirty four. My code is below

I need my C++ code to translate numbers into words.

For example: 1234 would be one thousand two hundred thirty four.

My code is below the instructions. My output is below my code.

I am having trouble getting the wording to come out correctly, particularly the tens place. (such as 1234, 725 or 25) it does not come out correctly.

I need my C++ code to translate numbers into words. For example:

#include #include #include

using namespace std;

class Numbers { private: int number; public: Numbers(int x) {

number = x;

}

const static string lessThan20[]; const static string tens[]; const static string hundred; const static string thousand;

void print();

};

const string Numbers::lessThan20[] = { "zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","tweleve","thirteen", "fourteen", "fifteen","sixteen","seventeen","eighteen","nineteen" };

const string Numbers::tens[] = { "zero","ten","twenty","thirty","forty","fifty","sixty", "seventy","eighty","ninety" };

const string Numbers::hundred = "hundred"; const string Numbers::thousand = "thousand";

void Numbers::print() {

number = abs(number); int x = number / 1000; if (x > 0)

cout 0)

cout = 20)

{ x = number / 10; if (x > 0) cout

else if (number >= 10)

{

cout

return;

}

number %= 10; if (number > 0)

cout

}

int main()

{ int num; cout : " > num;

while (1)

{ while (num > num; }

Numbers number(num); number.print(); cout :"; cin >> num;

if (num

{ break; }

}

system("pause");

return 0;

}

1234 would be one thousand two hundred thirty four. My code is

1. Numbers Class Design a class Numbers that can be used to translate whole dollar amounts in the range O through 9999 into an English description of the number. For example, the number 713 would be translated into the string seven hundred thirteen, and 8203 would be translated into eight thousand two hundred three. The class should have a single inte- ger member variable: int number; and a static array of string objects that specify how to translate key dollar amounts into the desired format. For example, you might use static strings such as string lessThan20[20] = {"zero", "one", ..., "eighteen", "nineteen"); string hundred = "hundred"; string thousand = "thousand"; The class should have a constructor that accepts a nonnegative integer and uses it to initialize the Numbers object. It should have a member function print() that prints the English description of the Numbers object. Demonstrate the class by writing a main program that asks the user to enter a number in the proper range and then prints out its English description. GN C:\Users\chris\Desktop\Troy Computer Science 2 CS 2255\hw6\Debug\hw6.exe This program translates whole dollar amounts into words for the purpuse of writing checks. Entering a negative number terminates the program. Enter an amount to be translated into words : 1234 one thousand two hundred three four Enter another number 0-9999 :725 seven hundred two five Enter another number 0-9999 :25 two five Enter another number 0-9999

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!