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
|
#include <iostream>
#include "Classes.h"
#include <string>
using namespace std;
NaturalNumber::NaturalNumber()
{
wholeNumber = 0;
}
NaturalNumber::NaturalNumber(int num)
{
wholeNumber = num;
}
const string NaturalNumber::lessThan20[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
const string NaturalNumber::tens[] = { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
void NaturalNumber::displayNumber()
{
int a, b, c, d, e;
a = wholeNumber % 10;
wholeNumber = wholeNumber / 10;
b = wholeNumber % 10;
wholeNumber = wholeNumber / 10;
c = wholeNumber % 10;
wholeNumber = wholeNumber / 10;
d = wholeNumber % 10;
wholeNumber = wholeNumber / 10;
e = wholeNumber % 10;
cout << "The number is ";
if (e == 1)
cout << lessThan20[d + 10] << " " << "thousand ";
else if (d != 0)
cout << lessThan20[d] << " " << "thousand ";
if (c != 0)
cout << lessThan20[c] << " " << "hundred ";
if (b == 1)
cout << lessThan20[a + 10] << " ";
if (b > 1)
{
cout << tens[b - 2] << " ";
if (a != 0)
cout << lessThan20[a]<< " ";
}
cout << "." << endl;
}
NaturalNumber operator+(const NaturalNumber& lhs, const NaturalNumber& rhs)
{
NaturalNumber sum;
sum.wholeNumber = lhs.wholeNumber + rhs.wholeNumber;
return sum;
}
|