diff --git a/.gitignore b/.gitignore index b4da41f..a15b871 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ assignments/0?/0?_? **Makefile **.idx **-Desktop-Debug/ +**.pro.user # latex compiling files **.toc diff --git a/assignments/04/04_2.cpp b/assignments/04/04_2.cpp new file mode 100644 index 0000000..c5a1b9a --- /dev/null +++ b/assignments/04/04_2.cpp @@ -0,0 +1,52 @@ +#include // for isdigit() +#include // for pow() +#include +#include +#include + +using namespace std; + +int convert(const string &s) { + string split_string = s; + stack digits; + int conversion = 0; + auto it_s = s.begin(); + + for (;(*it_s == ' ') && (it_s != s.end()); it_s++); // skip all spaces + for (;(isdigit(*it_s)) && (it_s != s.end()); it_s++) { + digits.push((int) *it_s - (int) '0'); // put all decimal digits onto the stack + }; + if(it_s == s.end() || *it_s == ' ') { + for (int i = 0; !(digits.empty()); i++) { + conversion += digits.top() * pow(10, i); + digits.pop(); + } + } else { + // throw std::invalid_argument(s + " is not a correct int representation."); + // is what I'd like to do, but I guess I couldn't return -1 then, right? + cout << s + " is not a correct non-negative int representation." << endl; + return -1; + } + return conversion; +} + +void use_convert_function(const string &s) { + cout << s << " : " << convert(s) << endl << endl; +} + +void test_convert_function() { + use_convert_function("0"); + use_convert_function("128"); + use_convert_function("+128"); + use_convert_function("12x128"); + use_convert_function("128 + x"); + use_convert_function("128 Punkte"); +} + +int main() { + string s = ""; + cout << "Please input a number: " << endl; + getline(cin, s); + use_convert_function(s); + return 0; +} diff --git a/assignments/04/ExtendedVector/.gitignore b/assignments/04/ExtendedVector/.gitignore deleted file mode 100644 index 4a0b530..0000000 --- a/assignments/04/ExtendedVector/.gitignore +++ /dev/null @@ -1,74 +0,0 @@ -# This file is used to ignore files which are generated -# ---------------------------------------------------------------------------- - -*~ -*.autosave -*.a -*.core -*.moc -*.o -*.obj -*.orig -*.rej -*.so -*.so.* -*_pch.h.cpp -*_resource.rc -*.qm -.#* -*.*# -core -!core/ -tags -.DS_Store -.directory -*.debug -Makefile* -*.prl -*.app -moc_*.cpp -ui_*.h -qrc_*.cpp -Thumbs.db -*.res -*.rc -/.qmake.cache -/.qmake.stash - -# qtcreator generated files -*.pro.user* -CMakeLists.txt.user* - -# xemacs temporary files -*.flc - -# Vim temporary files -.*.swp - -# Visual Studio generated files -*.ib_pdb_index -*.idb -*.ilk -*.pdb -*.sln -*.suo -*.vcproj -*vcproj.*.*.user -*.ncb -*.sdf -*.opensdf -*.vcxproj -*vcxproj.* - -# MinGW generated files -*.Debug -*.Release - -# Python byte code -*.pyc - -# Binaries -# -------- -*.dll -*.exe - diff --git a/assignments/04/ExtendedVector/README.md b/assignments/04/ExtendedVector/README.md index 8a34628..77553fc 100644 --- a/assignments/04/ExtendedVector/README.md +++ b/assignments/04/ExtendedVector/README.md @@ -1,2 +1,2 @@ -Requires Qt6 +Requires Qt6. You can open it in QtCreator, but you might have to manually compile the mainwindow.ui with `uic -o ui_mainwindow.h mainwindow.ui` (qt6 uic), since `qtchooser` is not supporting qt6 yet. diff --git a/assignments/04/ExtendedVector/mainwindow.cpp b/assignments/04/ExtendedVector/mainwindow.cpp index 1ac3304..a095211 100644 --- a/assignments/04/ExtendedVector/mainwindow.cpp +++ b/assignments/04/ExtendedVector/mainwindow.cpp @@ -22,6 +22,7 @@ void parseAsDoubleVector(QString vec_string, vector *vec) { vec->push_back(t_value); } else { throw std::invalid_argument("Please only write doubles into the Input field."); + return; } } return; diff --git a/assignments/04/ExtendedVector/ui_mainwindow.h b/assignments/04/ExtendedVector/ui_mainwindow.h new file mode 100644 index 0000000..1cce70a --- /dev/null +++ b/assignments/04/ExtendedVector/ui_mainwindow.h @@ -0,0 +1,113 @@ +/******************************************************************************** +** Form generated from reading UI file 'mainwindow.ui' +** +** Created by: Qt User Interface Compiler version 6.4.2 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef UI_MAINWINDOW_H +#define UI_MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Ui_MainWindow +{ +public: + QWidget *centralwidget; + QLineEdit *vec1Input; + QLineEdit *vec2Input; + QLabel *label; + QLabel *label_2; + QPushButton *okButton; + QTextBrowser *outputBrowser; + QDoubleSpinBox *factorSpinBox; + QLabel *label_3; + QMenuBar *menubar; + QMenu *menuIst_das_hier_gen_gender_User_Input; + QStatusBar *statusbar; + + void setupUi(QMainWindow *MainWindow) + { + if (MainWindow->objectName().isEmpty()) + MainWindow->setObjectName("MainWindow"); + MainWindow->resize(571, 681); + centralwidget = new QWidget(MainWindow); + centralwidget->setObjectName("centralwidget"); + vec1Input = new QLineEdit(centralwidget); + vec1Input->setObjectName("vec1Input"); + vec1Input->setGeometry(QRect(110, 30, 391, 51)); + vec2Input = new QLineEdit(centralwidget); + vec2Input->setObjectName("vec2Input"); + vec2Input->setGeometry(QRect(110, 100, 391, 51)); + label = new QLabel(centralwidget); + label->setObjectName("label"); + label->setGeometry(QRect(30, 40, 67, 21)); + label_2 = new QLabel(centralwidget); + label_2->setObjectName("label_2"); + label_2->setGeometry(QRect(30, 110, 67, 21)); + okButton = new QPushButton(centralwidget); + okButton->setObjectName("okButton"); + okButton->setGeometry(QRect(410, 170, 91, 29)); + outputBrowser = new QTextBrowser(centralwidget); + outputBrowser->setObjectName("outputBrowser"); + outputBrowser->setGeometry(QRect(30, 220, 511, 391)); + factorSpinBox = new QDoubleSpinBox(centralwidget); + factorSpinBox->setObjectName("factorSpinBox"); + factorSpinBox->setGeometry(QRect(200, 170, 66, 29)); + label_3 = new QLabel(centralwidget); + label_3->setObjectName("label_3"); + label_3->setGeometry(QRect(110, 170, 81, 21)); + MainWindow->setCentralWidget(centralwidget); + menubar = new QMenuBar(MainWindow); + menubar->setObjectName("menubar"); + menubar->setGeometry(QRect(0, 0, 571, 26)); + menuIst_das_hier_gen_gender_User_Input = new QMenu(menubar); + menuIst_das_hier_gen_gender_User_Input->setObjectName("menuIst_das_hier_gen_gender_User_Input"); + MainWindow->setMenuBar(menubar); + statusbar = new QStatusBar(MainWindow); + statusbar->setObjectName("statusbar"); + MainWindow->setStatusBar(statusbar); + + menubar->addAction(menuIst_das_hier_gen_gender_User_Input->menuAction()); + + retranslateUi(MainWindow); + + QMetaObject::connectSlotsByName(MainWindow); + } // setupUi + + void retranslateUi(QMainWindow *MainWindow) + { + MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr)); + vec1Input->setText(QCoreApplication::translate("MainWindow", "1.2, 4.3, -2.7, -11", nullptr)); + vec2Input->setText(QCoreApplication::translate("MainWindow", "-0.9, 4.5", nullptr)); + label->setText(QCoreApplication::translate("MainWindow", "Vector 1", nullptr)); + label_2->setText(QCoreApplication::translate("MainWindow", "Vector 2", nullptr)); + okButton->setText(QCoreApplication::translate("MainWindow", "Ok", nullptr)); + label_3->setText(QCoreApplication::translate("MainWindow", "Multiply by", nullptr)); + menuIst_das_hier_gen_gender_User_Input->setTitle(QCoreApplication::translate("MainWindow", "Is this a good enough UI now?", nullptr)); + } // retranslateUi + +}; + +namespace Ui { + class MainWindow: public Ui_MainWindow {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // UI_MAINWINDOW_H