-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
67 lines (65 loc) · 2.09 KB
/
main.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
#include "header.h"
#include <regex>
int main(){
regex bigRealFilter("[-+]?[0-9]+\\.[0-9]+");
regex bigDecimalFilter("[-+]?[0-9]+");
BigNumber* num1;
BigNumber* num2;
string n1, n2;
while(true){
// Deallocate the dynamically allocated memory
cout << "Number 1 ====> ";
cin >> n1;
cout << "Number 2 ====> ";
cin >> n2;
if (regex_match(n1, bigRealFilter) && regex_match(n2, bigRealFilter))
{
num1 = new BigReal(n1);
num2 = new BigReal(n2);
dynamic_cast<BigReal*>(num1);
dynamic_cast<BigReal*>(num2);
}
else if(regex_match(n1, bigDecimalFilter) && regex_match(n2, bigDecimalFilter)){
num1 = new BigDecimalInt(n1);
num2 = new BigDecimalInt(n2);
dynamic_cast<BigDecimalInt*>(num1);
dynamic_cast<BigDecimalInt*>(num2);
}
else{
cout << "Invalid Input\n";
continue;
}
cout << "What operation do you want to make? ";
char n;
cin >> n;
switch (n)
{
case '+':
cout << "Result is ====> " << *num1 + *num2;
cout << '\n';
break;
case '-':
cout << "Result is ====> " << *num1 - *num2;
cout << '\n';
break;
case '=':
cout << ((*num1 == *num2) ? "Input 1 is equal to Input 2" : " Input 1 is not equal to Input 2 ");
cout << '\n';
break;
case '>':
cout << ((*num1 > *num2) ? "Input 1 is > than Input 2" : " Input 1 is not > than Input 2 ");
cout << '\n';
break;
case '<':
cout << ((*num1 < *num2) ? "Input 1 is < than Input 2" : " Input 1 is not < than Input 2 ");
cout << '\n';
break;
default:
cout << "Invalid Input\n";
break;
}
cout << "=========================\n";
}
delete num1;
delete num2;
}