1-laboratoriya ishi. Kalkulyator yaratish I. Masalaning qo’yilishi



Download 2,12 Mb.
bet2/2
Sana12.07.2022
Hajmi2,12 Mb.
#783355
1   2
Bog'liq
1-topshiriq

Ishni bajarish tartibi:

  1. Qt Creator muhitini ishga tushirish










4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

Заголовочные oyna





7. Dastur kodi

  1. #include "mainwindow.h"

  2. #include "ui_mainwindow.h"

  3. #include "math.h"

  4. double num_first;


  5. MainWindow::MainWindow(QWidget *parent) :

  6. QMainWindow(parent),

  7. ui(new Ui::MainWindow)

  8. {

  9. ui->setupUi(this);


  10. connect(ui->pushButton_0, SIGNAL(clicked()), this, SLOT(digits_numbers()));

  11. connect(ui->pushButton_1, SIGNAL(clicked()), this, SLOT(digits_numbers()));

  12. connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(digits_numbers()));

  13. connect(ui->pushButton_3, SIGNAL(clicked()), this, SLOT(digits_numbers()));

  14. connect(ui->pushButton_4, SIGNAL(clicked()), this, SLOT(digits_numbers()));

  15. connect(ui->pushButton_5, SIGNAL(clicked()), this, SLOT(digits_numbers()));

  16. connect(ui->pushButton_6, SIGNAL(clicked()), this, SLOT(digits_numbers()));

  17. connect(ui->pushButton_7, SIGNAL(clicked()), this, SLOT(digits_numbers()));

  18. connect(ui->pushButton_8, SIGNAL(clicked()), this, SLOT(digits_numbers()));

  19. connect(ui->pushButton_9, SIGNAL(clicked()), this, SLOT(digits_numbers()));

  20. connect(ui->pushButton_butun, SIGNAL(clicked()), this, SLOT(operations()));

  21. connect(ui->pushButton_kasr, SIGNAL(clicked()), this, SLOT(operations()));

  22. connect(ui->pushButton_yigindi, SIGNAL(clicked()), this, SLOT(math_operations()));

  23. connect(ui->pushButton_kopaytma, SIGNAL(clicked()), this, SLOT(math_operations()));

  24. connect(ui->pushButton_ayrma, SIGNAL(clicked()), this, SLOT(math_operations()));

  25. connect(ui->pushButton_bolinma, SIGNAL(clicked()), this, SLOT(math_operations()));


  26. ui->pushButton_kopaytma->setCheckable(true);

  27. ui->pushButton_bolinma->setCheckable(true);

  28. ui->pushButton_yigindi->setCheckable(true);

  29. ui->pushButton_ayrma->setCheckable(true);

  30. }

  31. MainWindow::~MainWindow()

  32. {

  33. delete ui;

  34. }


  35. void MainWindow :: digits_numbers()

  36. {

  37. QPushButton *button = (QPushButton*)sender();

  38. double all_numbers;

  39. QString new_label;


  40. if(ui->results_show->text().contains(".")&& button->text()=="0"){

  41. new_label = ui->results_show->text() + button->text();

  42. } else {

  43. all_numbers = (ui->results_show->text()+button->text()).toDouble();

  44. new_label = QString::number(all_numbers, 'g', 15);

  45. }



  46. ui->results_show->setText(new_label);

  47. }



  48. void MainWindow::operations()

  49. {

  50. QPushButton *button = (QPushButton*)sender();

  51. double all_numbers;

  52. QString new_label;


  53. if (button->text()== "+/-"){

  54. all_numbers = (ui->results_show->text()).toDouble();

  55. all_numbers = all_numbers * -1;

  56. new_label= QString :: number (all_numbers, 'g', 15);


  57. ui->results_show->setText(new_label);

  58. }

  59. else if (button->text()== "%"){

  60. all_numbers = (ui->results_show->text()).toDouble();

  61. all_numbers = all_numbers * 0.01;

  62. new_label= QString :: number (all_numbers, 'g', 15);


  63. ui->results_show->setText(new_label);

  64. }

  65. }

  66. void MainWindow::math_operations()

  67. {

  68. QPushButton *button = (QPushButton*)sender();


  69. num_first = ui->results_show->text().toDouble();

  70. ui->results_show->setText("");

  71. button->setChecked(true);

  72. }

  73. void MainWindow::on_pushButton_AC_clicked()

  74. {

  75. ui->pushButton_kopaytma->setChecked(false);

  76. ui->pushButton_bolinma->setChecked(false);

  77. ui->pushButton_yigindi->setChecked(false);

  78. ui->pushButton_ayrma->setChecked(false);


  79. ui->results_show->setText("0");

  80. }


  81. {

  82. if (ui->pushButton_tenglik->isChecked())

  83. else if (num_second==0){

  84. ui->results_show->setText("0");

  85. } else {

  86. labelNumber=num_first/num_second;

  87. new_label= QString::number(labelNumber, 'g', 15);


  88. ui->results_show->setText(new_label);


  89. }

  90. ui->pushButton_tenglik->setChecked(false);

  91. }

  92. if else (ui->pushButton_p->isChecked()) {

  93. labelNumber=num_first + num_second;

  94. new_label= QString::number(labelNumber, 'g', 15);


  95. ui->results_show->setText(new_label);

  96. ui->pushButton_p->setChecked(false);

  97. }

  98. if else (ui->pushButton_m->isChecked()) {

  99. labelNumber=num_first - num_second;

  100. new_label= QString::number(labelNumber, 'g', 15);


  101. ui->results_show->setText(new_label);

  102. ui->pushButton_m->setChecked(false);

  103. }

  104. }



  105. void MainWindow::on_pushButton_tenglik_clicked()

  106. {

  107. if(!(ui->results_show->text().contains('.')))

  108. ui->results_show->setText(ui->results_show->text()+".");


  109. }


  110. void MainWindow::on_pushButton_kopaytma_clicked()

  111. {

  112. double labelNumber, num_second;

  113. QString new_label;


  114. num_second = ui->results_show->text().toDouble();


  115. if (ui->pushButton_kopaytma->isChecked()) {

  116. labelNumber=num_first*num_second;

  117. new_label= QString::number(labelNumber, 'g', 15);


  118. ui->results_show->setText(new_label);

  119. ui->pushButton_kopaytma->setChecked(false);


  120. }

  121. 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

  1. https://doc.qt.io/qt-5/qtpdf-index.html

  2. https://www.google.com/search?q=Qt+pdf&oq=Qt+pdf+&aqs=chrome..69i57j0l9.10645j0j15&sourceid=chrome&ie=UTF-8

  3. https:// code-live.ru/post/cpp-classes/

  4. ziyonet kutubxonasi

Download 2,12 Mb.

Do'stlaringiz bilan baham:
1   2




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish