-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho6.cpp
75 lines (66 loc) · 1.83 KB
/
o6.cpp
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
#include<iostream>
using namespace std;
class Numbers{
private:
int number;
static string lessThan20[20];
static string tens[10];
static string hundred;
static string thousand;
public:
//constructor
Numbers(int num): number(num){}
void print(){
if (number < 0 || number > 9999){
cout << "Number out of range!" << endl;
return;
}
if (number == 0){
cout << "zero" << endl;
}
string result;
//important
int thousands = number / 1000;
int hundreds = (number % 1000) / 100;
int tens = (number % 100) / 10;
int ones = number % 10;
if (thousands > 0){
result += lessThan20[thousands] + " " + thousand + " ";
}
if (hundreds > 0){
result += lessThan20[hundreds] + " " + hundred + " ";
}
if (tens > 1){
result += Numbers::tens[tens] + " ";
if (ones > 1){
result += Numbers::lessThan20[ones];
}
}
else if (tens == 1){
result += Numbers::lessThan20[10 + ones];
}
else if (ones > 0){
result += Numbers::lessThan20[ones];
}
cout << result << endl;
}
};
string Numbers::lessThan20[20] = {
"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven",
"twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"
};
string Numbers::tens[10] = {
"","","twenty","thirty","fourty","fifty","sixty","seventy","ninety"
};
string Numbers::hundred = "hundred";
string Numbers::thousand = "thousand";
int main()
{
int num;
cout << "Enter a number between 0 and 9999: ";
cin >> num;
Numbers numberObj(num);
cout << "English description: ";
numberObj.print();
return 0;
}