Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "widget.h"
- #include "ui_widget.h"
- #include <math.h>
- #include <QMessageBox>
- Widget::Widget(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::Widget)
- {
- ui->setupUi(this);
- }
- Widget::~Widget()
- {
- delete ui;
- }
- bool flagMI, flagPL, flagDI, flagSQ, flagMU;
- //ф-ции radiobutton
- void Widget::on_SQbutton_clicked()
- {
- flagSQ = true;
- flagMI = flagPL = flagDI = flagMU = false;
- ui->input2->hide();
- ui->op2->hide();
- ui->REname->setText("evolution");
- ui->op1->setText("radicand");
- }
- void Widget::on_DIbutton_clicked()
- {
- flagDI = true;
- flagMI = flagPL = flagSQ = flagMU = false;
- ui->input2->show();
- ui->op2->show();
- ui->REname->setText("division");
- ui->op1->setText("dividend");
- ui->op2->setText("divisor");
- }
- void Widget::on_MUbutton_clicked()
- {
- flagMU = true;
- flagMI = flagPL = flagSQ = flagDI = false;
- ui->input2->show();
- ui->op2->show();
- ui->REname->setText("multiplication");
- ui->op1->setText("multiplicands");
- ui->op2->setText("multiplier");
- }
- void Widget::on_MIbutton_clicked()
- {
- flagMI = true;
- flagMU = flagPL = flagSQ = flagDI = false;
- ui->input2->show();
- ui->op2->show();
- ui->REname->setText("difference");
- ui->op1->setText("minuend");
- ui->op2->setText("subtrahend");
- }
- void Widget::on_PLbutton_clicked()
- {
- flagPL = true;
- flagMU = flagMI = flagSQ = flagDI = false;
- ui->input2->show();
- ui->op2->show();
- ui->REname->setText("sum");
- ui->op1->setText("1st addend");
- ui->op2->setText("2nd addend");
- }
- //ф-ции главной кнопки(calculate)
- void Widget::on_RESULTbutton_clicked()
- {
- if(flagSQ) { //sqrt
- QString str1 = ui->input1->text();
- bool ok1;
- double aa = str1.toDouble(&ok1);
- if(ok1 and aa >= 0) {
- double SQ = sqrt(aa);
- QString SQ_str = QString::number(SQ);
- ui->output1->setText(SQ_str);
- }
- else if(aa < 0){
- QMessageBox::warning(this,"error","negative number!");
- ui->output1->setText(" ");
- }
- else if(ok1 == false){
- QMessageBox::warning(this,"error","no number!");
- ui->output1->setText(" ");
- }
- }
- if (flagDI){ //:
- QString str1 = ui->input1->text();
- QString str2 = ui->input2->text();
- bool ok1,ok2;
- double aa = str1.toDouble(&ok1);
- double bb = str2.toDouble(&ok2);
- if(bb != 0 and ok1 and ok2){
- double DI = aa/bb;
- QString DI_str = QString::number(DI);
- ui->output1->setText(DI_str);
- }
- else if(bb == 0 and ok1 and ok2){
- QMessageBox::warning(this,"error","division by zero!");
- ui->output1->setText(" ");
- }
- else if(ok1 == false){
- QMessageBox::warning(this,"error","no number in 1st");
- ui->output1->setText(" ");
- }
- else if(ok2 == false){
- QMessageBox::warning(this,"error","no number in 2nd");
- ui->output1->setText(" ");
- }
- else if(ok1 == ok2 == false){
- QMessageBox::warning(this,"error","no number in 1st and 2nd");
- ui->output1->setText(" ");
- }
- }
- if (flagMU){ //*
- QString str1 = ui->input1->text();
- QString str2 = ui->input2->text();
- bool ok1,ok2;
- double aa = str1.toDouble(&ok1);
- double bb = str2.toDouble(&ok2);
- if(ok1 and ok2){
- double MU = aa*bb;
- QString MU_str = QString::number(MU);
- ui->output1->setText(MU_str);
- }
- else if(ok1 == false){
- QMessageBox::warning(this,"error","no number in 1st");
- ui->output1->setText(" ");
- }
- else if(ok2 == false){
- QMessageBox::warning(this,"error","no number in 2nd");
- ui->output1->setText(" ");
- }
- else if(ok1 == ok2 == false){
- QMessageBox::warning(this,"error","no number in 1st and 2nd");
- ui->output1->setText(" ");
- }
- }
- if(flagMI){ //-
- QString str1 = ui->input1->text();
- QString str2 = ui->input2->text();
- bool ok1,ok2;
- double aa = str1.toDouble(&ok1);
- double bb = str2.toDouble(&ok2);
- if(ok1 and ok2){
- double MI = aa-bb;
- QString MI_str = QString::number(MI);
- ui->output1->setText(MI_str);
- }
- else if(ok1 == false){
- QMessageBox::warning(this,"error","no number in 1st");
- ui->output1->setText(" ");
- }
- else if(ok2 == false){
- QMessageBox::warning(this,"error","no number in 2nd");
- ui->output1->setText(" ");
- }
- else if(ok1 == ok2 == false){
- QMessageBox::warning(this,"error","no number in 1st and 2nd");
- ui->output1->setText(" ");
- }
- }
- if(flagPL){ //+
- QString str1 = ui->input1->text();
- QString str2 = ui->input2->text();
- bool ok1,ok2;
- double aa = str1.toDouble(&ok1);
- double bb = str2.toDouble(&ok2);
- if(ok1 and ok2){
- double PL = aa+bb;
- QString PL_str = QString::number(PL);
- ui->output1->setText(PL_str);
- }
- else if(ok1 == false){
- QMessageBox::warning(this,"error","no number in 1st");
- ui->output1->setText(" ");
- }
- else if(ok2 == false){
- QMessageBox::warning(this,"error","no number in 2nd");
- ui->output1->setText(" ");
- }
- else if(ok1 == ok2 == false){
- QMessageBox::warning(this,"error","no number in 1st and 2nd");
- ui->output1->setText(" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement