-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
102 lines (81 loc) · 2.29 KB
/
MainWindow.cpp
File metadata and controls
102 lines (81 loc) · 2.29 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <QMessageBox>
#include <iomanip>
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "Integer.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->lNumR->setText("0");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pshBtnSumar_clicked()
{
Integer num1(ui->tNum1->text().toInt());
Integer num2(ui->tNum2->text().toInt());
Integer result = num1 + num2;
ui->lNumR->setText(QString::number(result.Get()));
}
void MainWindow::on_pshBtnRestar_clicked()
{
Integer num1(ui->tNum1->text().toInt());
Integer num2(ui->tNum2->text().toInt());
Integer result = num1 - num2;
ui->lNumR->setText(QString::number(result.Get()));
}
void MainWindow::on_pshBtnMutiplicar_clicked()
{
clock_t start, end;
double elapsedTimeNormal;
double elapsedTimeKaratsuba;
Integer num1(ui->tNum1->text().toInt());
Integer num2(ui->tNum2->text().toInt());
Integer::SetMultiplyMethod(false);
start = clock();
// for(long i = 0; i < 10000000; i++);
Integer resultNormal = num1 * num2;
end = clock();
elapsedTimeNormal = ((double)(end - start) / CLOCKS_PER_SEC);
QString normal = "Método Tradicional: ";
normal += QString::number(resultNormal.Get());
normal += "\n";
normal += "Tiempo Invertido: ";
normal += QString::number(elapsedTimeNormal);
Integer::SetMultiplyMethod(true);
start = clock();
// for(long i = 0; i < 10000000; i++);
Integer resultKaratsuba = num1 * num2;
end = clock();
elapsedTimeKaratsuba = ((double)(end - start) / CLOCKS_PER_SEC);
QString karatsuba = "\nMétodo Karatsuba: ";
karatsuba += QString::number(resultKaratsuba.Get());
karatsuba += "\n";
karatsuba += "Tiempo Invertido: ";
karatsuba += QString::number(elapsedTimeKaratsuba);
QString message = normal + karatsuba;
QMessageBox::information(this, "Comparación métodos de multiplión", message);
}
int* MainWindow::convertirEntero(int n, int s)
{
int *integer = new int[s];
int i = 0;
while (n != 0) {
integer[i] = n % 10;
n /= 10;
i++;
}
return integer;
}
int MainWindow::seeSize(int n)
{
int i;
for (i = 0; n != 0; i++) {
n /= 10;
}
return i;
}