-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.cpp
88 lines (73 loc) · 3.75 KB
/
demo.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
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <chrono>
#include "./include/BigInteger.h"
using namespace std;
int main()
{
BigInteger bigint_1 {
"178978478678327583947589347893275849768937583743089769342057832754057"
"645789768394758932758932674839758932768937589433422344759438738974545"
"586476577546565473563543545436893476892758942376892374896486473543535"
"324325323343643542325453895875978904389054396789578439678976884096834"
"656865775426252352095825304832099534758943758943243253253244768975389"
"243434323643543643537589644375893476892758942376892374896486473543535"
"723564636255343542545389582475978904389054396789578439678976884096834"
"936357390689320834095830483267099534758943758943243253253244768975389"
"754754654654436435375894375893889476892758942376892374896486473543535"
"322582385280939048903286902849318902384098239058902859022352309892828"
};
BigInteger bigint_2 {
"324325323343643542325453895875978904389054396789578439678976884096834"
"656865775426252352095825304832099534758943758943243253253244768975389"
"243434323643543643537589644375893476892758942376892374896486473543535"
"723564636255343542545389582475978904389054396789578439678976884096834"
"656865775426252352095825304832099534758943758943243253253244768975389"
};
// Testing basic arithmetic computation
cout << "Testing basic arithmetic computation... " << endl;
cout << "------------------" << endl;
auto start_t = chrono::steady_clock::now();
BigInteger add_r = bigint_1 - bigint_2;
auto add_time = chrono::steady_clock::now() - start_t;
cout << "(1) - (2) = " << add_r << endl;
cout << "addition time = " << chrono::duration<double, nano> (add_time).count() << "ns" << endl << endl;
start_t = chrono::steady_clock::now();
BigInteger product = bigint_1 * bigint_2;
auto mul_time = chrono::steady_clock::now() - start_t;
cout << "(1) * (2) = " << product << endl;
cout << "multiplication time = " << chrono::duration<double, micro>(mul_time).count() << "us" << endl << endl;
start_t = chrono::steady_clock::now();
BigInteger quotient = bigint_1 / bigint_2;
auto div_time = chrono::steady_clock::now() - start_t;
cout << "(1) / (2) = " << quotient << endl;
cout << "division time = " << chrono::duration<double, milli>(div_time).count() << "ms" << endl << endl;
start_t = chrono::steady_clock::now();
BigInteger remainder = bigint_1 % bigint_2;
auto mod_time = chrono::steady_clock::now() - start_t;
cout << "(1) % (2) = " << remainder << endl;
cout << "modulo time = " << chrono::duration<double, milli>(mod_time).count() << "ms" << endl << endl;
// Verifying the consistence of the results
cout << "Verifying the consistence of the results... " << endl;
if (bigint_1 == (quotient * bigint_2 + remainder))
cout << "Yes, (1) == (2) * quotient + remainder." << endl;
else
cout << "NoNoNo, (1) != (2) * quotient + remainder." << endl;
system("pause");
cout << endl;
// Testing User's input data
BigInteger dividend, divisor;
cout << "Testing User's input data..." << endl;
cout << "Enter a dividend integer number: "; cin >> dividend;
cout << "Enter a divisor integer number: "; cin >> divisor;
quotient = dividend / divisor;
remainder = dividend % divisor;
cout << "quotient = " << quotient << endl;
cout << "remainder = " << remainder << endl;
if (dividend == (quotient * divisor + remainder))
cout << "The dividend is consistent with quotient * divisor + remainder" << endl;
else
cout << "The dividend is not consistent with quotient * divisor + remainder" << endl;
system("pause");
cout << endl;
return 0;
}