1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
/*
This is a class that can translate whole dollar amounts in the range 0 through 9999
into an English description of the number.
***********
Designed by: Demetri Mallous
*/
#include <iostream>
#include <string>
using namespace std;
//class Numbers
class Numbers
{
public:
//single member variable
string number;
//print function, gets return value from numOfDigits, then prints accordingly
void print()
{
//static string members
const static string lessThan20[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy"
"eighty", "ninety" };
const static string hundred = "hundred";
const static string thousand = "thousand";
if (numOfDigits() == 2 || numOfDigits() == 1)
{
cout << lessThan20[atoi(number.c_str())] << '\n';
}
if (number == "30")
cout << lessThan20[21];
if (number == "40")
cout << lessThan20[22];
if (number == "50")
cout << lessThan20[23];
if (number == "60")
cout << lessThan20[24];
if (number == "70")
cout << lessThan20[25];
if (number == "80")
cout << lessThan20[26];
if (number == "90")
cout << lessThan20[27];
if (numOfDigits() == 3)
{
cout << lessThan20[atoi(number.c_str())] << hundred << '\n';
}
if (numOfDigits() == 4)
{
cout << lessThan20[atoi(number.c_str())] << thousand << '\n';
}
}
//Determines how many digits there are in a number and returns the value
int numOfDigits()
{
if(!number.length()) return(-1);
int Digit_count(0);
for(unsigned int I(0); I < number.length(); ++I)
if(isdigit(number[I])) ++Digit_count;
return(Digit_count);
}
};
// main function
int main()
{
Numbers object;
cout << "Enter number: ";
cin >> object.number;
object.print();
cout << endl;
system("PAUSE");
return 0;
}
|