-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
43 lines (35 loc) · 1.26 KB
/
main.cpp
File metadata and controls
43 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <QCoreApplication>
#include <QDebug>
#include "infixexpression.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
InfixExpression expression("1 + 2 * pow(-3, 4) + ((5 > 7) || 6 < 2 ? max(5, 7) : min(6, 2))");
//1 2 3 (-) 4 pow * + 5 7 > 6 2 < || 5 7 max 6 2 min ? +
//165
qDebug() << expression.getPostfix();
//qDebug() << QString::fromStdString(expression.getPostfix());
qDebug() << expression.calc();
expression.set("-1");
//1 (-)
//-1
qDebug() << expression.getPostfix();
//qDebug() << QString::fromStdString(expression.getPostfix());
qDebug() << expression.calc();
expression.set("1 + 2 * 3 > 4 ? 5 / abs(6) : (7 + 8) * 9");
//1 2 3 * + 4 > 5 6 abs / 7 8 + 9 * ?
//0.833
qDebug() << expression.getPostfix();
//qDebug() << QString::fromStdString(expression.getPostfix());
qDebug() << expression.calc();
expression.set("a > b ? (a > c ? a : c) : (b > c ? b : c)");
//a b > a c > a c ? b c > b c ? ?
QMap<QString, double> para;
para.insert("a", 7);
para.insert("b", 5);
para.insert("c", 9);
qDebug() << expression.getPostfix();
//qDebug() << QString::fromStdString(expression.getPostfix());
qDebug() << expression.calc(para);
return 0;
}