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
|
#include<iostream>
#include<string>
using namespace::std;
class Numbers {
private:
int num;
public:
static string twoDigit[];
Numbers()
{ num=0;}
void setNumber(int number)
{ num=number;}
int getNumber()
{ return num;}
void print()
{
if(num>=1000)
{
int thousand;
thousand=(num%10000-num%1000)/1000;
cout<<twoDigit[thousand]<<" thousand ";
}//end if
if(num>=100)
{
int hundred;
hundred=(num%1000-num%100)/100;
cout<<twoDigit[hundred]<<" hundred and ";
}//end if
if(num>=0)
{
int ten;
ten=num%100;
cout<<twoDigit[ten]<<endl;
//cout<<ten<<endl;
}//end if
}//end void
};
string Numbers::twoDigit[100]={"zero","one","two","three","four","five","six","seven","eight","nine",
"ten","eleven","twelve", "thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen",
"twenty","twenty-one","twenty-two","twenty-three","twenty-four","twenty-five","twenty-six",
"twenty-seven","twenty-eight","twenty-nine","thirty","thirty-one","thirty-two","thirty-three",
"thirty-four","thirty-five","thirty-six","thirty-seven","thirty-eight","thirty-nine",
"forty","forty-one","forty-two","forty-three","forty-four","forty-five","forty-six","forty-seven",
"forty-eigth","forty-nine","fifty","fifty-one","fifty-two","fifty-three","fifty-four","fifty-five",
"fifty-six","fifty-seven","fifty-eight","fifty-nine","sixty", "sixty-one","sixty-two","sixty-three",
"sixty-four","sixty-five","sixty-six","sixty-seven","sixty-eight","sixty-nine","seventy","seventy-one",
"seventy-two","seventy-three","seventy-four","seventy-five","seventy-six","seventy-seven",
"seventy-eight","seventy-nine","eighty","eighty-one","eighty-two","eighty-three","eighty-four",
"eighty-five","eighty-six","eighty-seven","eighty-eight","eighty-nine","ninety","ninety-one",
"ninety-two","ninety-three","ninety-four","ninety-five","ninety-six","ninety-seven",
"ninety-eight","ninety-nine"};
int main ()
{
int number;
Numbers conversion;
cout<<"Enter a number between the range of 0-9999 and the program"<<endl<<"will convert it to words."<<endl;
cin>>number;
if(number<0||number>9999)
{
cout<<"Error.Number is out of range."<<endl;
cout<<"Enter a number between the range of 0-9999 and the program"<<endl<<"will convert it to words."<<endl;
cin>>number;
}
conversion.setNumber(number);
conversion.print();
system("pause");
return 0;
}
|