Ishni bajarish tartibi:
Qt Creator muhitini ishga tushirish
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Заголовочные oyna
7. Dastur kodi
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "math.h"
double num_first;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->pushButton_0, SIGNAL(clicked()), this, SLOT(digits_numbers()));
connect(ui->pushButton_1, SIGNAL(clicked()), this, SLOT(digits_numbers()));
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(digits_numbers()));
connect(ui->pushButton_3, SIGNAL(clicked()), this, SLOT(digits_numbers()));
connect(ui->pushButton_4, SIGNAL(clicked()), this, SLOT(digits_numbers()));
connect(ui->pushButton_5, SIGNAL(clicked()), this, SLOT(digits_numbers()));
connect(ui->pushButton_6, SIGNAL(clicked()), this, SLOT(digits_numbers()));
connect(ui->pushButton_7, SIGNAL(clicked()), this, SLOT(digits_numbers()));
connect(ui->pushButton_8, SIGNAL(clicked()), this, SLOT(digits_numbers()));
connect(ui->pushButton_9, SIGNAL(clicked()), this, SLOT(digits_numbers()));
connect(ui->pushButton_butun, SIGNAL(clicked()), this, SLOT(operations()));
connect(ui->pushButton_kasr, SIGNAL(clicked()), this, SLOT(operations()));
connect(ui->pushButton_yigindi, SIGNAL(clicked()), this, SLOT(math_operations()));
connect(ui->pushButton_kopaytma, SIGNAL(clicked()), this, SLOT(math_operations()));
connect(ui->pushButton_ayrma, SIGNAL(clicked()), this, SLOT(math_operations()));
connect(ui->pushButton_bolinma, SIGNAL(clicked()), this, SLOT(math_operations()));
ui->pushButton_kopaytma->setCheckable(true);
ui->pushButton_bolinma->setCheckable(true);
ui->pushButton_yigindi->setCheckable(true);
ui->pushButton_ayrma->setCheckable(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow :: digits_numbers()
{
QPushButton *button = (QPushButton*)sender();
double all_numbers;
QString new_label;
if(ui->results_show->text().contains(".")&& button->text()=="0"){
new_label = ui->results_show->text() + button->text();
} else {
all_numbers = (ui->results_show->text()+button->text()).toDouble();
new_label = QString::number(all_numbers, 'g', 15);
}
ui->results_show->setText(new_label);
}
void MainWindow::operations()
{
QPushButton *button = (QPushButton*)sender();
double all_numbers;
QString new_label;
if (button->text()== "+/-"){
all_numbers = (ui->results_show->text()).toDouble();
all_numbers = all_numbers * -1;
new_label= QString :: number (all_numbers, 'g', 15);
ui->results_show->setText(new_label);
}
else if (button->text()== "%"){
all_numbers = (ui->results_show->text()).toDouble();
all_numbers = all_numbers * 0.01;
new_label= QString :: number (all_numbers, 'g', 15);
ui->results_show->setText(new_label);
}
}
void MainWindow::math_operations()
{
QPushButton *button = (QPushButton*)sender();
num_first = ui->results_show->text().toDouble();
ui->results_show->setText("");
button->setChecked(true);
}
void MainWindow::on_pushButton_AC_clicked()
{
ui->pushButton_kopaytma->setChecked(false);
ui->pushButton_bolinma->setChecked(false);
ui->pushButton_yigindi->setChecked(false);
ui->pushButton_ayrma->setChecked(false);
ui->results_show->setText("0");
}
{
if (ui->pushButton_tenglik->isChecked())
else if (num_second==0){
ui->results_show->setText("0");
} else {
labelNumber=num_first/num_second;
new_label= QString::number(labelNumber, 'g', 15);
ui->results_show->setText(new_label);
}
ui->pushButton_tenglik->setChecked(false);
}
if else (ui->pushButton_p->isChecked()) {
labelNumber=num_first + num_second;
new_label= QString::number(labelNumber, 'g', 15);
ui->results_show->setText(new_label);
ui->pushButton_p->setChecked(false);
}
if else (ui->pushButton_m->isChecked()) {
labelNumber=num_first - num_second;
new_label= QString::number(labelNumber, 'g', 15);
ui->results_show->setText(new_label);
ui->pushButton_m->setChecked(false);
}
}
void MainWindow::on_pushButton_tenglik_clicked()
{
if(!(ui->results_show->text().contains('.')))
ui->results_show->setText(ui->results_show->text()+".");
}
void MainWindow::on_pushButton_kopaytma_clicked()
{
double labelNumber, num_second;
QString new_label;
num_second = ui->results_show->text().toDouble();
if (ui->pushButton_kopaytma->isChecked()) {
labelNumber=num_first*num_second;
new_label= QString::number(labelNumber, 'g', 15);
ui->results_show->setText(new_label);
ui->pushButton_kopaytma->setChecked(false);
}
Xulosa
Men bu kalkulyatorni yaratish jarayonida label va pushButton asosoy foydalanganlarim shular bo’ldi undan tashqari ayrim kutubxonalardan ham foydalandim qulayroq yani yaxshiroq ishlashi uchun . Kalkulyator yaratishdan maqsadim darslar davomida olgan bilimlarimdan maqsadli va samarali foydalanish .
6. Foydalanilgan adabiyotlar va manbalar
https://doc.qt.io/qt-5/qtpdf-index.html
https://www.google.com/search?q=Qt+pdf&oq=Qt+pdf+&aqs=chrome..69i57j0l9.10645j0j15&sourceid=chrome&ie=UTF-8
https:// code-live.ru/post/cpp-classes/
ziyonet kutubxonasi
Do'stlaringiz bilan baham: |