-
Notifications
You must be signed in to change notification settings - Fork 0
/
romannumber.hpp
80 lines (74 loc) · 2.72 KB
/
romannumber.hpp
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
#include <iostream>
#include <string>
#include <exception>
#include <stdexcept>
#include <cstring>
using namespace std;
class RomanNumber{
private:
RomanNumber(){}
int value = 0;
public:
const string thousands[4] = {"", "M", "MM", "MMM"};
const string hundreds[10] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
const string tens[10] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
const string ones[10] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
static int CharToInt(char c){
switch (c){
case 'I':
return 1;
case 'V':
return 5;
case 'X':
return 10;
case 'L':
return 50;
case 'C':
return 100;
case 'D':
return 500;
case 'M':
return 1000;
}
throw std::runtime_error("Invalid Roman digit : " + c);
}
RomanNumber(const char* romanNumber);
RomanNumber(const string& romanNumber);
RomanNumber(const int& decimal);
void SetValue(const char* romanNumber);
void SetValue(const string& romanNumber);
void SetValue(const int& decimal);
int GetInt();
string GetString();
RomanNumber& operator+=(RomanNumber rhs);
RomanNumber& operator-=(RomanNumber rhs);
RomanNumber& operator*=(RomanNumber rhs);
RomanNumber& operator/=(RomanNumber rhs);
RomanNumber& operator%=(RomanNumber rhs);
RomanNumber& operator+=(const int& rhs);
RomanNumber& operator-=(const int& rhs);
RomanNumber& operator*=(const int& rhs);
RomanNumber& operator/=(const int& rhs);
RomanNumber& operator%=(const int& rhs);
RomanNumber& operator++();
RomanNumber operator++(int);
RomanNumber& operator--();
RomanNumber operator--(int);
};
RomanNumber operator+(RomanNumber lhs, RomanNumber rhs);
RomanNumber operator-(RomanNumber lhs, RomanNumber rhs);
RomanNumber operator*(RomanNumber lhs, RomanNumber rhs);
RomanNumber operator/(RomanNumber lhs, RomanNumber rhs);
RomanNumber operator%(RomanNumber lhs, RomanNumber rhs);
RomanNumber operator+(const int& lhs, RomanNumber rhs);
RomanNumber operator-(const int& lhs, RomanNumber rhs);
RomanNumber operator*(const int& lhs, RomanNumber rhs);
RomanNumber operator/(const int& lhs, RomanNumber rhs);
RomanNumber operator%(const int& lhs, RomanNumber rhs);
RomanNumber operator+(RomanNumber lhs, const int& rhs);
RomanNumber operator-(RomanNumber lhs, const int& rhs);
RomanNumber operator*(RomanNumber lhs, const int& rhs);
RomanNumber operator/(RomanNumber lhs, const int& rhs);
RomanNumber operator%(RomanNumber lhs, const int& rhs);
ostream& operator<<(ostream& os, RomanNumber num);
ostream& operator<<(RomanNumber num, ostream& os);