-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
136 lines (112 loc) · 2.83 KB
/
mainwindow.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QMessageBox>
#include <QDebug>
MyStack <int> st(8);
void deleteTwoDigit(MyStack <int> &st){
MyStack <int> t(8);
int n=0;
while(!st.isEmpty())
{
int value=st.top();
st.pop();
if(value<10 or value>99){
t.push(value);
n++;
}
}
MyStack <int> t2(n);
while(!t.isEmpty())
{
t2.push(t.top());
t.pop();
}
st=t2;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->widget->setVisible(false);
}
MainWindow::~MainWindow()
{
delete ui;
}
/*void MainWindow::on_action_triggered()
{
QFile inputFile("input.txt");
if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::about(this,"Error","File could not be opened for reading");
//throw std::runtime_error("File could not be opened for reading");
}
QTextStream in(&inputFile);
while (!in.atEnd()) {
int value;
in >> value;
// qDebug()<<value<<" ";
st.push(value);
}
inputFile.close();
QString str=st.toQString();
//qDebug()<<str;
ui->textEdit->setText(str);
ui->widget->setVisible(true);
}
*/
void MainWindow::on_action_2_triggered()
{
QApplication::quit();
}
void MainWindow::on_pushButton_clicked()
{
int sum =st.Summa();
QString s=QString::number(sum);
s="Сумма = "+s;
QMessageBox::about(this,"Сумма елементов стека",s);
}
void MainWindow::on_pushButton_2_clicked()
{
st.removeTwoDigitNumbers();
//MyStack <int> t=st;
QString str=st.toQString();
//qDebug()<<str;
ui->textEdit->setText(str);
}
void MainWindow::on_pushButton_3_clicked()
{
/*MyStack <int> t=st;
int max=t.top();
t.pop();
while(!t.isEmpty())
{
if(t.top()>max)
max=t.top();
t.pop();
}
*/
int max=st.FindMax();
QMessageBox::about(this,"Максимальный элемент стека",QString::number(max));
}
void MainWindow::on_action_3_triggered()
{
QFile inputFile("input.txt");
if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::about(this,"Error","File could not be opened for reading");
//throw std::runtime_error("File could not be opened for reading");
}
QTextStream in(&inputFile);
while (!in.atEnd()) {
int value;
in >> value;
// qDebug()<<value<<" ";
st.push(value);
}
inputFile.close();
QString str=st.toQString();
//qDebug()<<str;
ui->textEdit->setText(str);
ui->widget->setVisible(true);
}