Numbers Class Design a class Numbers that can be used to translate whole dollar
ID: 3657915 • Letter: N
Question
Numbers Class
Design a class Numbers that can be used to translate whole dollar amounts in the range 0 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 integer 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] = {
Explanation / Answer
#include #include using namespace std; int main () { string name (""); string lessthan[20] = {"","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"} ; string hundred("hundred"); string thousand("thousand"); string twodigit[8] = {"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"} cout >i; if(i > 1000){ p = i /1000; name += lessthan[p]; name += thousand; i = i%1000; } if(i > 100) { p = i/100; name += lessthan[p]; name += hundred; i = i %100; } if(i > 20){ p = i / 10; name += twodigit[p-2]; i = i%10; } name += lessthan[i]; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.