double Calculator::operate(double a, char theta, double b)
{
double sum1;
switch (theta) {
case '+':
sum1 = a + b; break;
case '-':
sum1 = a - b; break;
case '*':
sum1 = a * b; break;
case '/':
sum1 = a / b; break;
}
return sum1;
}
char Calculator::button2char(QPushButton *button)
{
char optr;
if(button == buttonadd)
optr = '+';
else if(button == buttonsub)
optr = '-';
else if(button == buttonx)
optr = '*';
else if(button == buttondivide)
optr = '/';
else if(button == buttonLArc)
optr = '(';
else if(button == buttonRArc)
optr = ')';
else if(button == buttonequal)
optr = '=';
else if(button == button0)
optr = '0';
else if(button == button1)
optr = '1';
else if(button == button2)
optr = '2';
else if(button == button3)
optr = '3';
else if(button == button4)
optr = '4';
else if(button == button5)
optr = '5';
else if(button == button6)
optr = '6';
else if(button == button7)
optr = '7';
else if(button == button8)
optr = '8';
else if(button == button9)
optr = '9';
else if(button == buttondot)
optr = '.';
return optr;
}
char Calculator::precedeSign(char optr1, char optr2)
{
char compare;
int i1 = char2num(optr1);
int i2 = char2num(optr2);
if(f1[i1] > f2[i2])
compare = '>';
else if(f1[i1] < f2[i2])
compare = '<';
else
compare = '=';
return compare;
}
int Calculator::char2num(char optr)
{
int ii;
switch(optr)
{
case '+':
ii = 0; break;
case '-':
ii = 1; break;
case '*':
ii = 2; break;
case '/':
ii = 3; break;
case '(':
ii = 4; break;
case ')':
ii = 5; break;
default:
ii = 6;
}
return ii;
}
void Calculator::initData()
{
i = 1;
j = 0;
sum = 0;
f1[0] = f1[1] =3; f1[2] = f1[3] = 5; f1[4] = 1;
f1[5] = 6; f1[6] = 0;
f2[0] = f2[1] = 2; f2[2] = f2[3] = 4; f2[4] = 6;
f2[5] = 1; f2[6] = 0;
isPoint = false;
isLArc = false;
sign = ' ';
isTwoOptrsFlag = false;
isEqualClicked = false;
isEnter = true;
}
void Calculator::initVector()
{
vectorOptr.append('#');
vectorOpnd.append(0);
vectorOpnd.append(0);
vectorOpnd.append(0);
}
Calculator::~Calculator()
{
}
//main.cpp
#include "calculator.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Calculator cal;
cal.show();
return a.exec();
}