-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completed basic functionality of calculator
- Loading branch information
Antonio Kim
committed
Apr 4, 2020
1 parent
fc384d5
commit b6ffb9e
Showing
23 changed files
with
237 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,6 @@ MathEngine/libMathEngine.a | |
Tests/run | ||
CalcUI/CalcUI | ||
.includes/ | ||
.libs/ | ||
.sandbox/*/sandbox | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
py_ncurses_test | ||
basic_evaluation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CXX = g++ | ||
CXXFLAGS = -Ofast -std=c++17 -Wall -MMD -Werror=vla -DDEBUG | ||
EXEC = sandbox | ||
|
||
OBJECTS = sandbox.o | ||
DEPENDS = ${OBJECTS:.o=.d} | ||
|
||
${EXEC}: ${OBJECTS} | ||
${CXX} ${CXXFLAGS} ${OBJECTS} -o ${EXEC} | ||
|
||
-include ${DEPENDS} | ||
|
||
clean: | ||
rm ${OBJECTS} ${EXEC} ${DEPENDS} | ||
.PHONY: clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <cstdlib> | ||
#include <ctime> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
cout << std::setprecision(16) << sin(3) << endl; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import torch | ||
import numpy as np | ||
|
||
def main(): | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
#!/bin/bash | ||
|
||
cd CalcUI/ | ||
qmake CalcUI.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug | ||
make | ||
|
||
if [ ! -f Makefile ]; then | ||
qmake CalcUI.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug | ||
fi | ||
|
||
make 2> calcui.cerr | ||
if [ $? -ne 0 ]; then | ||
vi -R calcui.cerr | ||
exit 1 | ||
else | ||
rm -f calcui.cerr | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,45 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <sstream> | ||
|
||
#include "calcwindow.h" | ||
#include "ui_calcwindow.h" | ||
#include <QTextEdit> | ||
#include <QString> | ||
|
||
#include <Expressions/InvalidExpression.h> | ||
#include <Utils/exceptions.h> | ||
|
||
using namespace std; | ||
|
||
CalcWindow::CalcWindow(QWidget *parent) | ||
: QMainWindow(parent) | ||
, ui(new Ui::CalcWindow) | ||
{ | ||
ui->setupUi(this); | ||
|
||
connect(ui->input1, &QTextEdit::textChanged, this, &CalcWindow::on_textChanged); | ||
} | ||
|
||
CalcWindow::~CalcWindow() | ||
{ | ||
delete ui; | ||
} | ||
|
||
|
||
void CalcWindow::on_textChanged() | ||
{ | ||
string input = ui->input1->toPlainText().toStdString(); | ||
|
||
try { | ||
auto expr = engine.evaluate(input); | ||
if (!dynamic_cast<InvalidExpression*>(expr.get())){ | ||
ostringstream out; | ||
out << expr; | ||
string output = out.str(); | ||
ui->output1->setText(QString::fromUtf8(output.c_str())); | ||
} | ||
} catch(const Exception& e){ | ||
cerr << e.what() << endl; | ||
} catch(...){} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
#include <sstream> | ||
#include <gsl/gsl_math.h> | ||
|
||
#include "../InvalidExpression.h" | ||
|
||
using namespace std; | ||
|
||
InvalidExpression::InvalidExpression(const Exception& e): message{e.msg} {} | ||
|
||
expression InvalidExpression::simplify() { | ||
return make_unique<InvalidExpression>(message); | ||
} | ||
expression InvalidExpression::derivative(const std::string& var) { | ||
return make_unique<InvalidExpression>(message); | ||
} | ||
expression InvalidExpression::integrate(const std::string& var) { | ||
return make_unique<InvalidExpression>(message); | ||
} | ||
|
||
bool InvalidExpression::evaluable(){ return false; } | ||
|
||
double InvalidExpression::value() { return GSL_NAN; } | ||
|
||
double InvalidExpression::value(const Variables& vars) { return GSL_NAN; } | ||
|
||
bool InvalidExpression::complex(){ return false; } | ||
|
||
expression InvalidExpression::copy() { | ||
return make_unique<InvalidExpression>(message); | ||
} | ||
|
||
std::ostream& InvalidExpression::print(std::ostream& out) { | ||
return out << message; | ||
} | ||
|
||
std::ostream& InvalidExpression::postfix(std::ostream& out) { | ||
return out << message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "Expression.h" | ||
#include "../Utils/exceptions.h" | ||
|
||
class InvalidExpression: public Expression { | ||
|
||
std::string message; | ||
|
||
public: | ||
InvalidExpression(const Exception&); | ||
|
||
EXPRESSION_OVERRIDES | ||
|
||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.