-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.cpp
More file actions
105 lines (82 loc) · 1.64 KB
/
widget.cpp
File metadata and controls
105 lines (82 loc) · 1.64 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
#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
money=0;
Rest();
}
Widget::~Widget()
{
delete ui;
}
void Widget::Rest()
{
ui->pbCoffee->setEnabled(false);
ui->pbmilk->setEnabled(false);
ui->pbTea->setEnabled(false);
if(money>=100){
ui->pbCoffee->setEnabled(true);
}
else if(money>=150){
ui->pbmilk->setEnabled(true);
}
else if(money>=200){
ui->pbTea->setEnabled(true);
}
ui->lcdNumber->display(money);
}
void Widget::increaseMoney(int value)
{
money+=value;
ui-> lcdNumber->display(money);
Rest();
}
void Widget::on_pb10_clicked()
{
increaseMoney(10);
}
void Widget::on_pb50_clicked()
{
increaseMoney(50);
}
void Widget::on_pb100_clicked()
{
increaseMoney(100);
}
void Widget::on_pb500_clicked()
{
increaseMoney(500);
}
void Widget::on_pbCoffee_clicked()
{
increaseMoney(-100);
}
void Widget::on_pbmilk_clicked()
{
increaseMoney(-150);
}
void Widget::on_pbTea_clicked()
{
increaseMoney(-200);
}
void Widget::on_pbReset_clicked()
{
int change = money;
int coin500 = change / 500;
change %= 500;
int coin100 = change / 100;
change %= 100;
int coin50 = change / 50;
change %= 50;
int coin10 = change / 10;
QString message = QString("500won: %1\n100won: %2\n50won: %3\n10won: %4")
.arg(coin500).arg(coin100).arg(coin50).arg(coin10);
QMessageBox::information(this, "Result", message);
// Reset money
money = 0;
ui->lcdNumber->display(money);
}