This repository was archived by the owner on May 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslae.cpp
More file actions
107 lines (91 loc) · 2.76 KB
/
slae.cpp
File metadata and controls
107 lines (91 loc) · 2.76 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
103
104
105
106
107
#include "slae.h"
#include "ui_slae.h"
#include "QDebug"
#include "QScrollArea"
#include <sstream>
SLAE::SLAE(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::SLAE)
{
ui->setupUi(this);
E.resize(countOfEquation);
S.resize(countOfEquation);
for (int i = 0; i < countOfEquation; ++i)
C[i].resize(countOfVariables);
CreateSLAE();
}
SLAE::~SLAE()
{
delete ui;
}
QString toQString(double value) {
std::stringstream ss;
ss << value;
return QString(ss.str().c_str());
}
void SLAE::CreateSLAE() {
QWidget *central = new QWidget;
QVBoxLayout *layout = new QVBoxLayout(central);
ui->SLAEContainer->setWidget(central);
ui->SLAEContainer->setWidgetResizable(true);
for (int i = 0; i < countOfEquation; ++i) {
QWidget *row = new QWidget();
QHBoxLayout *rowLayout = new QHBoxLayout(row);
for (int j{0}; j < countOfVariables; ++j) {
C[i][j] = new QSpinBox();
C[i][j]->setFixedWidth(100);
C[i][j]->setRange(-100000,100000);
QString labelText = "X" + toQString(j + 1);
if (j == countOfVariables - 1)
labelText += " = ";
else
labelText += " + ";
QLabel *label = new QLabel(labelText);
rowLayout->addWidget(C[i][j]);
rowLayout->addWidget(label);
}
E[i] = new QSpinBox();
E[i]->setFixedWidth(100);
E[i]->setRange(-100000,100000);
rowLayout->addWidget(E[i]);
layout->addWidget(row);
}
}
void SLAE::on_resizeButton_clicked()
{
for (int i = 0; i < countOfEquation; ++i) {
for (int j = 0; j < countOfVariables; ++j)
delete C[i][j];
delete E[i];
}
countOfEquation = ui->countOfEquation->value();
countOfVariables = ui->countOfVariables->value();
C.resize(countOfEquation);
for (int i = 0; i < countOfEquation; ++i)
C[i].resize(countOfVariables);
E.resize(countOfEquation);
A.resize(countOfEquation, countOfVariables);
S.resize(countOfEquation);
CreateSLAE();
}
void SLAE::on_Solve_clicked()
{
for (int i = 0; i < countOfEquation; ++i) {
for (int j = 0; j < countOfVariables; ++j)
A[i][j] = C[i][j]->value();
S[i] = E[i]->value();
}
QWidget *central = new QWidget;
QVBoxLayout *layout = new QVBoxLayout(central);
QScrollArea *scroll = new QScrollArea();
scroll->setWidget(central);
scroll->setWidgetResizable(true);
QLabel *label = new QLabel(solveSLAE(A, S).c_str());
layout->addWidget(label);
QMainWindow *w = new QMainWindow;
w->setGeometry(50,50,480,320);
w->setCentralWidget(scroll);
const QFont *font = new QFont("MS Shell Dlg", 12);
scroll->setFont(*font);
w->show();
}