Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.16 KB | None | 0 0
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3. #include <math.h>
  4. #include <QMessageBox>
  5.  
  6. Widget::Widget(QWidget *parent) :
  7. QWidget(parent),
  8. ui(new Ui::Widget)
  9. {
  10. ui->setupUi(this);
  11. }
  12.  
  13. Widget::~Widget()
  14. {
  15. delete ui;
  16. }
  17.  
  18. bool flagMI, flagPL, flagDI, flagSQ, flagMU;
  19.  
  20.  
  21.  
  22. //ф-ции radiobutton
  23.  
  24.  
  25.  
  26.  
  27. void Widget::on_SQbutton_clicked()
  28. {
  29. flagSQ = true;
  30. flagMI = flagPL = flagDI = flagMU = false;
  31. ui->input2->hide();
  32. ui->op2->hide();
  33. ui->REname->setText("evolution");
  34. ui->op1->setText("radicand");
  35. }
  36.  
  37. void Widget::on_DIbutton_clicked()
  38. {
  39. flagDI = true;
  40. flagMI = flagPL = flagSQ = flagMU = false;
  41. ui->input2->show();
  42. ui->op2->show();
  43. ui->REname->setText("division");
  44. ui->op1->setText("dividend");
  45. ui->op2->setText("divisor");
  46. }
  47.  
  48. void Widget::on_MUbutton_clicked()
  49. {
  50. flagMU = true;
  51. flagMI = flagPL = flagSQ = flagDI = false;
  52. ui->input2->show();
  53. ui->op2->show();
  54. ui->REname->setText("multiplication");
  55. ui->op1->setText("multiplicands");
  56. ui->op2->setText("multiplier");
  57. }
  58.  
  59. void Widget::on_MIbutton_clicked()
  60. {
  61. flagMI = true;
  62. flagMU = flagPL = flagSQ = flagDI = false;
  63. ui->input2->show();
  64. ui->op2->show();
  65. ui->REname->setText("difference");
  66. ui->op1->setText("minuend");
  67. ui->op2->setText("subtrahend");
  68. }
  69.  
  70. void Widget::on_PLbutton_clicked()
  71. {
  72. flagPL = true;
  73. flagMU = flagMI = flagSQ = flagDI = false;
  74. ui->input2->show();
  75. ui->op2->show();
  76. ui->REname->setText("sum");
  77. ui->op1->setText("1st addend");
  78. ui->op2->setText("2nd addend");
  79. }
  80.  
  81.  
  82.  
  83.  
  84.  
  85. //ф-ции главной кнопки(calculate)
  86.  
  87.  
  88.  
  89. void Widget::on_RESULTbutton_clicked()
  90. {
  91.  
  92.  
  93. if(flagSQ) { //sqrt
  94. QString str1 = ui->input1->text();
  95. bool ok1;
  96. double aa = str1.toDouble(&ok1);
  97. if(ok1 and aa >= 0) {
  98. double SQ = sqrt(aa);
  99. QString SQ_str = QString::number(SQ);
  100. ui->output1->setText(SQ_str);
  101. }
  102. else if(aa < 0){
  103. QMessageBox::warning(this,"error","negative number!");
  104. ui->output1->setText(" ");
  105. }
  106. else if(ok1 == false){
  107. QMessageBox::warning(this,"error","no number!");
  108. ui->output1->setText(" ");
  109. }
  110. }
  111. if (flagDI){ //:
  112. QString str1 = ui->input1->text();
  113. QString str2 = ui->input2->text();
  114. bool ok1,ok2;
  115. double aa = str1.toDouble(&ok1);
  116. double bb = str2.toDouble(&ok2);
  117. if(bb != 0 and ok1 and ok2){
  118. double DI = aa/bb;
  119. QString DI_str = QString::number(DI);
  120. ui->output1->setText(DI_str);
  121. }
  122. else if(bb == 0 and ok1 and ok2){
  123. QMessageBox::warning(this,"error","division by zero!");
  124. ui->output1->setText(" ");
  125. }
  126. else if(ok1 == false){
  127. QMessageBox::warning(this,"error","no number in 1st");
  128. ui->output1->setText(" ");
  129. }
  130. else if(ok2 == false){
  131. QMessageBox::warning(this,"error","no number in 2nd");
  132. ui->output1->setText(" ");
  133.  
  134. }
  135. else if(ok1 == ok2 == false){
  136. QMessageBox::warning(this,"error","no number in 1st and 2nd");
  137. ui->output1->setText(" ");
  138. }
  139. }
  140. if (flagMU){ //*
  141. QString str1 = ui->input1->text();
  142. QString str2 = ui->input2->text();
  143. bool ok1,ok2;
  144. double aa = str1.toDouble(&ok1);
  145. double bb = str2.toDouble(&ok2);
  146. if(ok1 and ok2){
  147. double MU = aa*bb;
  148. QString MU_str = QString::number(MU);
  149. ui->output1->setText(MU_str);
  150. }
  151. else if(ok1 == false){
  152. QMessageBox::warning(this,"error","no number in 1st");
  153. ui->output1->setText(" ");
  154. }
  155. else if(ok2 == false){
  156. QMessageBox::warning(this,"error","no number in 2nd");
  157. ui->output1->setText(" ");
  158.  
  159. }
  160. else if(ok1 == ok2 == false){
  161. QMessageBox::warning(this,"error","no number in 1st and 2nd");
  162. ui->output1->setText(" ");
  163. }
  164.  
  165. }
  166. if(flagMI){ //-
  167. QString str1 = ui->input1->text();
  168. QString str2 = ui->input2->text();
  169. bool ok1,ok2;
  170. double aa = str1.toDouble(&ok1);
  171. double bb = str2.toDouble(&ok2);
  172. if(ok1 and ok2){
  173. double MI = aa-bb;
  174. QString MI_str = QString::number(MI);
  175. ui->output1->setText(MI_str);
  176. }
  177. else if(ok1 == false){
  178. QMessageBox::warning(this,"error","no number in 1st");
  179. ui->output1->setText(" ");
  180. }
  181. else if(ok2 == false){
  182. QMessageBox::warning(this,"error","no number in 2nd");
  183. ui->output1->setText(" ");
  184.  
  185. }
  186. else if(ok1 == ok2 == false){
  187. QMessageBox::warning(this,"error","no number in 1st and 2nd");
  188. ui->output1->setText(" ");
  189. }
  190. }
  191. if(flagPL){ //+
  192. QString str1 = ui->input1->text();
  193. QString str2 = ui->input2->text();
  194. bool ok1,ok2;
  195. double aa = str1.toDouble(&ok1);
  196. double bb = str2.toDouble(&ok2);
  197. if(ok1 and ok2){
  198. double PL = aa+bb;
  199. QString PL_str = QString::number(PL);
  200. ui->output1->setText(PL_str);
  201. }
  202. else if(ok1 == false){
  203. QMessageBox::warning(this,"error","no number in 1st");
  204. ui->output1->setText(" ");
  205. }
  206. else if(ok2 == false){
  207. QMessageBox::warning(this,"error","no number in 2nd");
  208. ui->output1->setText(" ");
  209.  
  210. }
  211. else if(ok1 == ok2 == false){
  212. QMessageBox::warning(this,"error","no number in 1st and 2nd");
  213. ui->output1->setText(" ");
  214. }
  215. }
  216.  
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement