Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

#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;

}

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

Students also viewed these Databases questions

Question

4. Support and enliven your speech with effective research

Answered: 1 week ago

Question

3. Choose an appropriate topic and develop it

Answered: 1 week ago