answersLogoWhite

0

#include<iostream>

class expand

{

public:

expand(unsigned long long num):value(num){}

std::ostream& operator()(std::ostream& out)const;

private:

unsigned long long value;

static const char * const units[20];

static const char * const tens[10];

};

const char * const expand::units[20] = {"zero", "one", "two", "three","four","five","six","seven",

"eight","nine", "ten", "eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen",

"eighteen","nineteen"};

const char * const expand::tens[10] = {"", "ten", "twenty", "thirty","forty","fifty","sixty","seventy",

"eighty","ninety"};

std::ostream &operator<< (std::ostream &out, expand number)

{

return(number(out));

}

std::ostream &expand::operator()(std::ostream &out) const

{

const unsigned long long quintillion=1000000000000000000;

const unsigned long long quadrillion=1000000000000000;

const unsigned long long trillion=1000000000000;

const unsigned long long billion=1000000000;

const unsigned long long million=1000000;

const unsigned long long thousand=1000;

const unsigned long long hundred=100;

const unsigned long long twenty=20;

const unsigned long long ten=10;

unsigned long long multiple=quintillion;

unsigned long long remain;

if(value>=thousand)

{

while(multiple>value&&(multiple!=quintillionmultiple!=quadrillion

multiple!=trillionmultiple!=billionmultiple!=millionmultiple!=thousand))

multiple/=1000;

out<<expand(value/multiple);

switch(multiple)

{

case(quintillion):out<<"-quintillion"; break;

case(quadrillion):out<<"-quadrillion"; break;

case(trillion):out<<"-trillion"; break;

case(billion):out<<"-billion"; break;

case(million):out<<"-million";break;

case(thousand):out<<"-thousand";break;

}

if(remain=value%multiple)

{

if(remain<hundred)

out<<"-and";

out<<"-"<<expand(remain);

}

}

else if(value>=hundred)

{

out<<expand(value/hundred)<<"-hundred";

if(remain=value%hundred)

out<<"-and-"<<expand(remain);

}

else if(value>=twenty)

{

out<<tens[value/ten];

if(remain=value%ten)

out<<"-"<<expand(remain);

}

else

out<<units[value];

return(out);

}

int main()

{

for(unsigned long long ull=0; ull<0xffffffffffffffff; ++ull)

std::cout<<expand(ull)<<std::endl;

return(0);

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

How many digits are there in a phone number in Russia?

Telephone numbers throughout Russia are uniformly 3 digits for the area code plus 7 digits for the local number.


Which American state calling code his plus 160?

No such code. +1 is the country code for America The calling code is therefore the three digits beginning with 60 in this case.


Where is this phone from plus 494142907529?

The first two digits (49) suggest a number in Germany. HOWEVER - there is no area code starting with the next three digits (414),


What area code has the number plus 800 144 Or what telephone instrument uses plus 800 prefix and has three digits after it?

the International Freephone Service


How do you write 200 thousand plus 10 thousand in digits instead of words?

200,000 + 10,000 = 210,000


What is hexadecimal code?

Computer engineers use to use the hexadecimal code to program computers, or the base 16. Hexadecimal numbers use the digits 0 through 9, plus the letters A through F to represent the digits 10 through 15.


What country are you calling with 23480xxxxxxxx?

Country code +234 is Nigeria, and +234 80 plus 8 more digits is a mobile number.


How do you convert a turbo c plus plus code into Linux shell scripting code without using gcc or g plus plus compiler?

You cannot. C++ and shell script (which shell, by the way? there are more than one) are entirely different languages.


Which country has zip code plus 9?

+9 is not a ZIP Code. ZIP Codes are postal codes used in the USA. They are uniformly 5 digits, with a 4-digit extension. There are telephone country codes that begin with +9, but you need one or two more digits.


What country that's starts with an area code of plus 175?

I believe that that is not a valid country code - in others words no country has that code.


What is the 14209 plus 4 zip code?

Somewhere in the Elmwood Village region of Buffalo, New York. Insufficient information. There are hundreds, if not thousands, of different ZIP+4 codes in each 5-digit ZIP Code. You need to ask about a specific address.


How do you convert from assembly to binary in c plus plus?

Use inline assembly instructions. Then compile your C++ program to produce the machine code.