├── .gitignore ├── C++11_Intro ├── ProductManager │ ├── ProductManager.pro │ ├── data.txt │ ├── dataaccesslayer.cpp │ ├── dataaccesslayer.h │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mainwindow.ui │ ├── product.cpp │ ├── product.h │ ├── productlistmodel.cpp │ └── productlistmodel.h └── TRMatrix │ ├── TRMatrix.pro │ ├── main.cpp │ └── matrix.hpp ├── CPlusPlusBasics ├── CPlusPlusBasics.pro └── main.cpp ├── CafeMenuEditor ├── CafeMenu.pro ├── Linux.Doxyfile ├── composite.cpp ├── composite.h ├── consoleprintmenuvisitor.cpp ├── consoleprintmenuvisitor.h ├── main.cpp ├── menu.cpp ├── menu.h ├── menuitem.cpp ├── menuitem.h ├── menuiterator.cpp ├── menuiterator.h └── menuvisitor.h ├── CafeMenuEditorQtVersion ├── CafeMenu.pro ├── Linux.Doxyfile ├── composite.cpp ├── composite.h ├── consoleprintmenuvisitor.cpp ├── consoleprintmenuvisitor.h ├── main.cpp ├── menu.cpp ├── menu.h ├── menuitem.cpp ├── menuitem.h ├── menuiterator.cpp ├── menuiterator.h └── menuvisitor.h ├── ClassInterface ├── ClassInterface.pro └── main.cpp ├── LICENSE ├── OOP ├── .gitignore ├── OOP.pro ├── dammoop.cpp ├── dammoop.h ├── iloveencapsulation.cpp ├── iloveencapsulation.h ├── inheritace.h ├── main.cpp └── polymorphism.h ├── ObjectConstructDestructAndCopy ├── ObjectConstructDestructAndCopy.pro └── main.cpp ├── QtBasics ├── QtBasics.pro ├── main.cpp └── someCoolFile.txt ├── README.md ├── WidgetExample ├── WidgetExample.pro ├── analogclock.cpp ├── analogclock.h ├── main.cpp ├── mainwindow.cpp └── mainwindow.h ├── WidgetsAppliction ├── WidgetsAppliction.pro ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── myclass.cpp └── myclass.h ├── Zoo ├── Zoo.pro ├── deployment.pri └── main.cpp ├── compile_test_2 ├── class1.cpp ├── class1.h ├── class2.cpp ├── class2.h ├── class3.cpp ├── class3.h ├── compile_test_2.pro ├── cplusplustypes.h ├── deployment.pri ├── main.cpp ├── personalinformation.cpp └── personalinformation.h └── datatypes ├── datatypes.pro └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | 3 | *.slo 4 | *.lo 5 | *.o 6 | *.a 7 | *.la 8 | *.lai 9 | *.so 10 | *.dll 11 | *.dylib 12 | 13 | # Qt-es 14 | 15 | /.qmake.cache 16 | /.qmake.stash 17 | *.pro.user 18 | *.pro.user.* 19 | *.moc 20 | moc_*.cpp 21 | qrc_*.cpp 22 | ui_*.h 23 | Makefile* 24 | *-build-* 25 | 26 | # QtCreator 27 | 28 | *.autosave 29 | 30 | #QtCtreator Qml 31 | *.qmlproject.user 32 | *.qmlproject.user.* 33 | -------------------------------------------------------------------------------- /C++11_Intro/ProductManager/ProductManager.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2015-10-27T19:11:48 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = ProductManager 12 | TEMPLATE = app 13 | 14 | 15 | SOURCES += main.cpp\ 16 | mainwindow.cpp \ 17 | productlistmodel.cpp \ 18 | product.cpp \ 19 | dataaccesslayer.cpp 20 | 21 | HEADERS += mainwindow.h \ 22 | productlistmodel.h \ 23 | product.h \ 24 | dataaccesslayer.h 25 | 26 | FORMS += mainwindow.ui 27 | 28 | DISTFILES += \ 29 | data.txt 30 | -------------------------------------------------------------------------------- /C++11_Intro/ProductManager/data.txt: -------------------------------------------------------------------------------- 1 | 4 2 | butter 3 3 | meat 15 4 | wine 13 5 | bread 5 6 | -------------------------------------------------------------------------------- /C++11_Intro/ProductManager/dataaccesslayer.cpp: -------------------------------------------------------------------------------- 1 | #include "dataaccesslayer.h" 2 | 3 | DataAccessLayer::DataAccessLayer(const std::string &fileName) 4 | { 5 | _dataReader.open(fileName); 6 | } 7 | 8 | std::vector DataAccessLayer::readProducts(ProdPred pred) 9 | { 10 | int n; 11 | std::vector result; 12 | _dataReader >> n; 13 | std::string name; 14 | int price; 15 | 16 | if( !pred ) 17 | pred = [](Product) { return true; }; 18 | 19 | for(int i = 0; i < n; ++i) 20 | { 21 | _dataReader >> name >> price; 22 | Product product(name, price); 23 | if( pred(product) ) 24 | result.push_back(product); 25 | } 26 | return result; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /C++11_Intro/ProductManager/dataaccesslayer.h: -------------------------------------------------------------------------------- 1 | #ifndef DATAACCESSLAYER_H 2 | #define DATAACCESSLAYER_H 3 | 4 | #include "product.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | class DataAccessLayer 12 | { 13 | public: 14 | typedef std::function ProdPred; 15 | DataAccessLayer(const std::string &fileName); 16 | 17 | std::vector readProducts( 18 | ProdPred pred = ProdPred() 19 | ); 20 | 21 | private: 22 | std::ifstream _dataReader; 23 | }; 24 | 25 | #endif // DATAACCESSLAYER_H 26 | -------------------------------------------------------------------------------- /C++11_Intro/ProductManager/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /C++11_Intro/ProductManager/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | _dbLayer = std::make_unique("data.txt"); 10 | 11 | // _dbLayer.reset(new DataAccessLayer('data.txt')) 12 | _model = new ProductListModel(nullptr); 13 | 14 | ui->treeView->setModel(_model); 15 | 16 | auto pred = [](Product prod) { return prod.price() < 13; }; 17 | 18 | _model->ResetModel( _dbLayer->readProducts(pred) ); 19 | 20 | init(); 21 | } 22 | 23 | MainWindow::~MainWindow() 24 | { 25 | delete ui; 26 | } 27 | 28 | void MainWindow::removeClicked() 29 | { 30 | int index = ui->treeView->currentIndex().row(); 31 | if(index < 0) 32 | return; 33 | 34 | auto product = _model->removeProduct(index); 35 | 36 | auto undoFunction = [=]() { 37 | _model->insertProduct(index, product); 38 | }; 39 | 40 | _undoStack.push(undoFunction); 41 | } 42 | 43 | void MainWindow::undoClicked() 44 | { 45 | if(!_undoStack.empty()) 46 | { 47 | _undoStack.top()(); 48 | _undoStack.pop(); 49 | } 50 | } 51 | 52 | void MainWindow::init() 53 | { 54 | connect(ui->removeButton, &QPushButton::clicked, 55 | this, &MainWindow::removeClicked); 56 | connect(ui->undoButton, &QPushButton::clicked, 57 | this, &MainWindow::undoClicked); 58 | } 59 | -------------------------------------------------------------------------------- /C++11_Intro/ProductManager/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | #include "dataaccesslayer.h" 10 | #include "productlistmodel.h" 11 | 12 | namespace Ui { 13 | class MainWindow; 14 | } 15 | 16 | class MainWindow : public QMainWindow 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit MainWindow(QWidget *parent = 0); 22 | ~MainWindow(); 23 | 24 | private: 25 | void removeClicked(); 26 | void undoClicked(); 27 | void init(); 28 | 29 | private: 30 | typedef std::function UndoAction; 31 | 32 | Ui::MainWindow *ui; 33 | std::unique_ptr _dbLayer; 34 | ProductListModel *_model; 35 | std::stack _undoStack; 36 | }; 37 | 38 | #endif // MAINWINDOW_H 39 | -------------------------------------------------------------------------------- /C++11_Intro/ProductManager/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | Remove 27 | 28 | 29 | 30 | 31 | 32 | 33 | Undo 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 0 45 | 0 46 | 400 47 | 21 48 | 49 | 50 | 51 | 52 | 53 | TopToolBarArea 54 | 55 | 56 | false 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /C++11_Intro/ProductManager/product.cpp: -------------------------------------------------------------------------------- 1 | #include "product.h" 2 | 3 | Product::Product() 4 | { 5 | _name = "Undef"; 6 | _price = -1; 7 | } 8 | 9 | Product::Product(std::string name, int price) 10 | { 11 | _name = name; 12 | _price = price; 13 | } 14 | 15 | std::string Product::name() const 16 | { 17 | return _name; 18 | } 19 | 20 | int Product::price() const 21 | { 22 | return _price; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /C++11_Intro/ProductManager/product.h: -------------------------------------------------------------------------------- 1 | #ifndef PRODUCT_H 2 | #define PRODUCT_H 3 | 4 | #include 5 | 6 | class Product 7 | { 8 | public: 9 | Product(); 10 | Product(std::string name, int price); 11 | 12 | std::string name() const; 13 | int price() const; 14 | 15 | private: 16 | std::string _name; 17 | int _price; 18 | 19 | }; 20 | 21 | 22 | #endif // PRODUCT_H 23 | -------------------------------------------------------------------------------- /C++11_Intro/ProductManager/productlistmodel.cpp: -------------------------------------------------------------------------------- 1 | #include "productlistmodel.h" 2 | 3 | ProductListModel::ProductListModel(QObject *parent) : QAbstractListModel(parent) 4 | { 5 | 6 | } 7 | 8 | void ProductListModel::ResetModel(std::vector products) 9 | { 10 | beginResetModel(); 11 | _data = products; 12 | endResetModel(); 13 | } 14 | 15 | void ProductListModel::insertProduct(int index, Product product) 16 | { 17 | auto where = _data.begin(); 18 | std::advance(where, index); 19 | 20 | beginInsertRows(QModelIndex(), index, index + 1); 21 | _data.insert(where, product); 22 | endInsertRows(); 23 | } 24 | 25 | Product ProductListModel::removeProduct(int index) 26 | { 27 | 28 | Product rValue; 29 | if( index >= 0 && index < _data.size() ) 30 | { 31 | rValue = _data[index]; 32 | 33 | beginRemoveRows(QModelIndex(), index, index + 1); 34 | _data.erase(_data.begin() + index); 35 | endRemoveRows(); 36 | } 37 | 38 | return rValue; 39 | 40 | } 41 | 42 | Product ProductListModel::getProduct(int index) 43 | { 44 | if( index >= 0 && index < _data.size() ) 45 | return _data[index]; 46 | return Product(); 47 | } 48 | 49 | int ProductListModel::rowCount(const QModelIndex &parent) const 50 | { 51 | return _data.size(); 52 | } 53 | 54 | QVariant ProductListModel::data(const QModelIndex &index, int role) const 55 | { 56 | if(role != Qt::DisplayRole) 57 | return QVariant(); 58 | 59 | if( index.row() < 0 || index.row() >= _data.size() ) 60 | return QVariant(); 61 | 62 | Columns column = static_cast(index.column()); 63 | 64 | switch(column) 65 | { 66 | case Columns::Name: 67 | return QVariant(_data[index.row()].name().c_str()); break; 68 | case Columns::Price: 69 | return QVariant(_data[index.row()].price()); break; 70 | default: 71 | return QVariant(); 72 | } 73 | } 74 | 75 | 76 | int ProductListModel::columnCount(const QModelIndex &parent) const 77 | { 78 | return 2; 79 | } 80 | 81 | QVariant ProductListModel::headerData(int section, Qt::Orientation orientation, int role) const 82 | { 83 | 84 | if( role != Qt::DisplayRole ) 85 | return QVariant(); 86 | 87 | if(orientation == Qt::Vertical) 88 | return QVariant(); 89 | 90 | if(section == 0) 91 | return QVariant("Name"); 92 | else if( section == 1) 93 | return QVariant("Price"); 94 | else 95 | return QVariant(); 96 | 97 | } 98 | -------------------------------------------------------------------------------- /C++11_Intro/ProductManager/productlistmodel.h: -------------------------------------------------------------------------------- 1 | #ifndef PRODUCTLISTMODEL_H 2 | #define PRODUCTLISTMODEL_H 3 | 4 | #include 5 | 6 | #include 7 | #include "product.h" 8 | 9 | 10 | class ProductListModel : public QAbstractListModel 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit ProductListModel(QObject *parent = 0); 15 | 16 | enum Columns { Name, Price }; 17 | 18 | 19 | void ResetModel(std::vector products); 20 | void insertProduct(int index, Product product); 21 | 22 | Product removeProduct(int index); 23 | 24 | Product getProduct(int index); 25 | 26 | 27 | private: 28 | std::vector _data; 29 | 30 | 31 | // QAbstractItemModel interface 32 | public: 33 | virtual int rowCount(const QModelIndex &parent) const; 34 | virtual QVariant data(const QModelIndex &index, int role) const; 35 | 36 | // QAbstractItemModel interface 37 | public: 38 | virtual int columnCount(const QModelIndex &parent) const; 39 | virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; 40 | }; 41 | 42 | #endif // PRODUCTLISTMODEL_H 43 | -------------------------------------------------------------------------------- /C++11_Intro/TRMatrix/TRMatrix.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console c++11 3 | CONFIG -= app_bundle 4 | CONFIG -= qt 5 | 6 | SOURCES += main.cpp 7 | 8 | HEADERS += \ 9 | matrix.hpp 10 | 11 | -------------------------------------------------------------------------------- /C++11_Intro/TRMatrix/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | const float M_PI = 3.14; 6 | 7 | class Matrix 8 | { 9 | public: 10 | Matrix() 11 | { 12 | for(int i = 0; i < 3; ++i) 13 | for(int j = 0; j < 3; ++j) 14 | _data[i][j] = 0.0f; 15 | 16 | _data[0][0] = _data[1][1] = _data[2][2] = 1.0f; 17 | } 18 | 19 | static Matrix&& BuildTranslation(float a, float b) 20 | { 21 | Matrix result; 22 | result._data[0][2] = a; 23 | result._data[1][2] = b; 24 | 25 | return std::move(result); 26 | } 27 | 28 | static Matrix&& BuildRotation(float angle) 29 | { 30 | angle = angle / 180.0f * M_PI; 31 | Matrix result; 32 | result._data[0][0] = result._data[1][1] = cos(angle); 33 | result._data[0][1] = -sin(angle); 34 | result._data[1][0] = sin(angle); 35 | 36 | return std::move(result); 37 | } 38 | 39 | friend Matrix&& operator*(Matrix &&left, Matrix &&right) 40 | { 41 | return std::move(left); 42 | } 43 | 44 | void print() const 45 | { 46 | for(int i = 0; i < 3; ++i) 47 | { 48 | for(int j = 0; j < 3; ++j) 49 | cout << _data[i][j] << " "; 50 | cout << endl; 51 | } 52 | } 53 | 54 | private: 55 | float _data[3][3]; 56 | }; 57 | 58 | 59 | 60 | int main() 61 | { 62 | Matrix mtx = Matrix::BuildRotation(30.0f) * Matrix::BuildTranslation(3.0f, 4.0f) * Matrix(); 63 | mtx.print(); 64 | return 0; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /C++11_Intro/TRMatrix/matrix.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MATRIX_HPP 2 | #define MATRIX_HPP 3 | 4 | 5 | 6 | #endif // MATRIX_HPP 7 | 8 | -------------------------------------------------------------------------------- /CPlusPlusBasics/CPlusPlusBasics.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console c++14 3 | CONFIG -= app_bundle qt 4 | QMAKE_CXXFLAGS += -std=c++14 5 | 6 | SOURCES += main.cpp 7 | 8 | -------------------------------------------------------------------------------- /CPlusPlusBasics/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define printTypeInfo(value) std::cout << std::boolalpha << typeid(value).name() << " " << #value << ": " << value << " size: " << sizeof(value) << " byte." << std::endl; 10 | 11 | enum class Planets 12 | { 13 | Mercury = 0, 14 | Venus, 15 | Earth, 16 | Mars, 17 | Jupiter, 18 | Saturn, 19 | Uranus, 20 | Neptune, 21 | Pluto 22 | }; 23 | 24 | void printPlanetName(Planets planet) 25 | { 26 | switch (planet) 27 | { 28 | case Planets::Mercury: 29 | std::cout << "Mercury" << std::endl; 30 | break; 31 | case Planets::Venus: 32 | std::cout << "Venus" << std::endl; 33 | break; 34 | case Planets::Earth: 35 | std::cout << "Earth" << std::endl; 36 | break; 37 | case Planets::Mars: 38 | std::cout << "Mars" << std::endl; 39 | break; 40 | case Planets::Jupiter: 41 | std::cout << "Jupiter" << std::endl; 42 | break; 43 | case Planets::Saturn: 44 | std::cout << "Saturn" << std::endl; 45 | break; 46 | case Planets::Uranus: 47 | std::cout << "Uranus" << std::endl; 48 | break; 49 | case Planets::Neptune: 50 | std::cout << "Neptune" << std::endl; 51 | break; 52 | case Planets::Pluto: 53 | std::cout << "Pluto" << std::endl; 54 | break; 55 | default: 56 | std::cout << "Wrong planet!" << std::endl; 57 | break; 58 | } 59 | } 60 | 61 | void testFunctionParameters(std::vector firstPrm, std::vector& secondPrm, std::vector* thirdPrm) 62 | { 63 | firstPrm.push_back(2); 64 | 65 | std::sort(std::begin(secondPrm), std::end(secondPrm)); 66 | 67 | auto f = [](int value){ return value % 2 == 0; }; 68 | thirdPrm->clear(); 69 | int newSize = std::count_if(std::begin(secondPrm), std::end(secondPrm), f); 70 | thirdPrm->resize(newSize); 71 | std::copy_if(std::begin(secondPrm), std::end(secondPrm), std::begin(*thirdPrm), f); 72 | } 73 | 74 | void printVector(const std::vector& vector) 75 | { 76 | for(const auto& element : vector) 77 | { 78 | std::cout << element << " "; 79 | } 80 | std::cout << "size: " << vector.size() << std::endl; 81 | std::cout << std::endl; 82 | } 83 | 84 | int main(int argc, char *argv[]) 85 | { 86 | //Logic type 87 | // bool logic {true}; 88 | // printTypeInfo(logic); 89 | 90 | //Integer types 91 | // char symbol {'s'}; 92 | // printTypeInfo(symbol); 93 | 94 | // short integerShort {1}; 95 | // printTypeInfo(integerShort); 96 | 97 | // int integer {2}; 98 | // printTypeInfo(integer); 99 | 100 | // long integerLong {3}; 101 | // printTypeInfo(integerLong); 102 | 103 | // long long integerLongLong {4}; 104 | // printTypeInfo(integerLongLong); 105 | 106 | //Float types 107 | // float floatNumber {1.1}; 108 | // printTypeInfo(floatNumber); 109 | 110 | // double doubleNumber {2.1}; 111 | // printTypeInfo(doubleNumber); 112 | 113 | // long double doubleNumberLong {3.1autoVariable}; 114 | // printTypeInfo(doubleNumberLong); 115 | 116 | // auto autoVariable = *argv; 117 | // printTypeInfo(autoVariable); 118 | 119 | //Initialize and assign operator 120 | // int firstInitialize {1}; 121 | // int forthInitialize = {4}; 122 | // int secondInitialize {INT64_MAX + 1}; 123 | // int thirdInitialize = INT64_MAX + 1; 124 | 125 | //References and pointers 126 | // auto hardcodedValue = 42; 127 | 128 | // auto& reference = hardcodedValue; 129 | // printTypeInfo(reference); 130 | 131 | // decltype(hardcodedValue)* pointer {&hardcodedValue}; 132 | // printTypeInfo(pointer); 133 | // printTypeInfo(*pointer); 134 | // delete pointer; // Bad-bad delete 135 | 136 | // void* voidPointer = pointer; 137 | // printTypeInfo(voidPointer); 138 | // printTypeInfo(*((decltype(hardcodedValue)* )voidPointer)); 139 | 140 | //Smart pointers 141 | // auto uniquePtr = std::make_unique(hardcodedValue); 142 | // printTypeInfo(uniquePtr.get()); 143 | // printTypeInfo(*uniquePtr); 144 | 145 | // auto sharedPtr = std::make_shared(hardcodedValue); 146 | // printTypeInfo(sharedPtr.get()); 147 | // printTypeInfo(*sharedPtr); 148 | 149 | //Constants 150 | // const auto marsRadius = 3396.2; 151 | // const auto earthRadius = 6378.1; 152 | 153 | //If and swich 154 | // if(marsRadius > earthRadius) 155 | // { 156 | // printTypeInfo(marsRadius); 157 | // } 158 | // else 159 | // { 160 | // printTypeInfo(earthRadius); 161 | // } 162 | // printPlanetName(Planets::Earth); 163 | 164 | //Arrays, for and while loop 165 | // const auto arraySize = 3; 166 | // int array[arraySize] {0, 1, 2}; 167 | // printTypeInfo(array); 168 | // printTypeInfo(array[0]); 169 | // printTypeInfo(*array + 1); 170 | // printTypeInfo(2[array]); 171 | 172 | // int* arrayDynamic = new int[2]{2, 3}; 173 | // printTypeInfo(arrayDynamic); 174 | // printTypeInfo(*arrayDynamic); 175 | // printTypeInfo(arrayDynamic[1]); 176 | // delete[] arrayDynamic; 177 | // //Raw for loop 178 | // for (int i = 0; i < arraySize; ++i) 179 | // { 180 | // std::cout << array[i] << " "; 181 | // } 182 | // std::cout << std::endl; 183 | 184 | // //Iterator for loop 185 | // for(auto it = std::begin(array); it != std::end(array); ++it) 186 | // { 187 | // std::cout << (*it) << " "; 188 | // } 189 | // std::cout << std::endl; 190 | 191 | // //Range base for loop 192 | // for(const auto& element : array) 193 | // { 194 | // std::cout << element << " "; 195 | // } 196 | // std::cout << std::endl; 197 | 198 | // //std::algotithm for_each loop 199 | // std::for_each(std::begin(array), std::end(array),[](auto element) { 200 | // std::cout << element << " "; 201 | // }); 202 | // std::cout << std::endl; 203 | 204 | // std::array wordsArray {"first", "second", "third"}; 205 | // auto word = std::begin(wordsArray); 206 | // while(word != std::end(wordsArray)) 207 | // { 208 | // std::cout << *(word++) << " "; 209 | // } 210 | // std::cout << std::endl; 211 | 212 | std::vector firstVector(5); 213 | std::iota(std::begin(firstVector), std::end(firstVector), 0); 214 | printVector(firstVector); 215 | std::vector secondVector {5, 2, 6, 1, 3, 7, 4, 9, 0, 8}; 216 | std::vector thirdVector{0, 0, 0, 0, -1, 3}; 217 | 218 | testFunctionParameters(firstVector, secondVector, &thirdVector); 219 | 220 | printVector(firstVector); 221 | printVector(secondVector); 222 | printVector(thirdVector); 223 | 224 | return 0; 225 | } 226 | 227 | -------------------------------------------------------------------------------- /CafeMenuEditor/CafeMenu.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT = core 3 | CONFIG += console 4 | CONFIG += c++11 5 | CONFIG -= app_bundle 6 | 7 | SOURCES += main.cpp \ 8 | menuitem.cpp \ 9 | menu.cpp \ 10 | menuiterator.cpp \ 11 | consoleprintmenuvisitor.cpp \ 12 | composite.cpp 13 | 14 | HEADERS += \ 15 | menuitem.h \ 16 | menu.h \ 17 | menuiterator.h \ 18 | menuvisitor.h \ 19 | consoleprintmenuvisitor.h \ 20 | composite.h 21 | 22 | -------------------------------------------------------------------------------- /CafeMenuEditor/composite.cpp: -------------------------------------------------------------------------------- 1 | #include "composite.h" 2 | #include "menuvisitor.h" 3 | 4 | /*! 5 | * \brief Composite::Composite constructor 6 | * \param pTitle is item's title. 7 | */ 8 | Composite::Composite(const std::string &pTitle) 9 | : mTitle(pTitle) 10 | { 11 | } 12 | 13 | /*! 14 | * \brief Composite::~Composite destructor 15 | */ 16 | Composite::~Composite() 17 | { 18 | for (const auto &subitem : mListSubitems) 19 | { 20 | delete subitem; 21 | } 22 | 23 | mListSubitems.clear(); 24 | } 25 | 26 | /*! 27 | * \brief Composite::addSubitem 28 | * \param pItem is new child subitem for this item 29 | */ 30 | void Composite::addSubitem(Composite *pItem) 31 | { 32 | if (this != pItem) 33 | { 34 | mListSubitems.push_back(pItem); 35 | pItem->mParent = this; 36 | } 37 | } 38 | 39 | /*! 40 | * \brief Composite::subitemsCount 41 | * \return number of item's childs 42 | */ 43 | int Composite::subitemsCount() const 44 | { 45 | return mListSubitems.size(); 46 | } 47 | 48 | /*! 49 | * \brief Composite::child 50 | * \param pIndex is index of child item 51 | * \return child by index 52 | */ 53 | Composite *Composite::child(int pIndex) const 54 | { 55 | return mListSubitems.at(pIndex); 56 | } 57 | 58 | /*! 59 | * \brief Composite::parent 60 | * \return parent of this item 61 | */ 62 | Composite *Composite::parent() const 63 | { 64 | return mParent; 65 | } 66 | 67 | /*! 68 | * \brief Composite::title 69 | * \return title of this item 70 | */ 71 | std::string Composite::title() const 72 | { 73 | return mTitle; 74 | } 75 | -------------------------------------------------------------------------------- /CafeMenuEditor/composite.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPOSITE_H 2 | #define COMPOSITE_H 3 | 4 | #include 5 | #include 6 | 7 | class MenuVisitor; 8 | 9 | /*! 10 | * \brief The Composite basic class that realise compositor patern for cafe menu. 11 | */ 12 | class Composite 13 | { 14 | public: 15 | Composite(const std::string &pTitle); 16 | virtual ~Composite(); 17 | 18 | void addSubitem(Composite *pItem); 19 | int subitemsCount() const; 20 | Composite *child(int pIndex) const; 21 | Composite *parent() const; 22 | 23 | std::string title() const; 24 | 25 | virtual void accept(MenuVisitor *visitor) = 0; 26 | 27 | private: 28 | Composite *mParent; 29 | std::vector mListSubitems; 30 | std::string mTitle; 31 | }; 32 | 33 | #endif // COMPOSITE_H 34 | -------------------------------------------------------------------------------- /CafeMenuEditor/consoleprintmenuvisitor.cpp: -------------------------------------------------------------------------------- 1 | #include "consoleprintmenuvisitor.h" 2 | #include "menuitem.h" 3 | #include "menu.h" 4 | 5 | #include 6 | 7 | /*! 8 | * \brief ConsolePrintMenuVisitor::indent 9 | * \param item 10 | * \return 11 | */ 12 | std::string ConsolePrintMenuVisitor::indent(Composite *item) const 13 | { 14 | std::string rIndentString; 15 | 16 | std::string lIndentStep = " "; 17 | Composite *lMenuItem = item->parent(); 18 | while (lMenuItem) 19 | { 20 | lMenuItem = lMenuItem->parent(); 21 | rIndentString.append(lIndentStep); 22 | } 23 | 24 | return rIndentString; 25 | } 26 | 27 | /*! 28 | * \brief ConsolePrintMenuVisitor::visit 29 | * \param item 30 | */ 31 | void ConsolePrintMenuVisitor::visit(MenuItem *item) 32 | { 33 | std::string lIndentString = indent(item); 34 | 35 | std::cout << lIndentString << "> " << item->title() << " : " << item->price() << "$" << std::endl; 36 | 37 | if (!item->description().empty()) 38 | { 39 | std::cout << lIndentString << " ::::" << item->description() << "::::" << std::endl; 40 | } 41 | } 42 | 43 | /*! 44 | * \brief ConsolePrintMenuVisitor::visit 45 | * \param menu 46 | */ 47 | void ConsolePrintMenuVisitor::visit(Menu *menu) 48 | { 49 | std::cout << indent(menu) << "[" << menu->title() << "]" << std::endl; 50 | } 51 | -------------------------------------------------------------------------------- /CafeMenuEditor/consoleprintmenuvisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSOLEPRINTMENUVISITOR_H 2 | #define CONSOLEPRINTMENUVISITOR_H 3 | 4 | #include "menuvisitor.h" 5 | #include 6 | 7 | class Composite; 8 | /*! 9 | * \brief The ConsolePrintMenuVisitor class 10 | */ 11 | class ConsolePrintMenuVisitor : public MenuVisitor 12 | { 13 | public: 14 | void visit(MenuItem *item); 15 | void visit(Menu *menu); 16 | 17 | private: 18 | std::string indent(Composite *item) const; 19 | }; 20 | 21 | #endif // CONSOLEPRINTMENUVISITOR_H 22 | -------------------------------------------------------------------------------- /CafeMenuEditor/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "menuitem.h" 8 | #include "menu.h" 9 | #include "menuiterator.h" 10 | #include "composite.h" 11 | #include "consoleprintmenuvisitor.h" 12 | 13 | using namespace std; 14 | 15 | // ======== 16 | 17 | /* ============================ */ 18 | 19 | void createAndPrintMenu() 20 | { 21 | cout << "Restoraunt <>" << endl; 22 | cout << "--------------------------------------------------------" << endl; 23 | 24 | Menu lMenuMain("MAIN MENU"); 25 | 26 | Menu *lPizzaMenu = new Menu("Pizza Menu"); 27 | lPizzaMenu->addSubitem(new MenuItem("hawaiian pizza", 2.4, "cheese and tomato base with toppings of ham and pineapple")); 28 | lPizzaMenu->addSubitem(new MenuItem("vegetarian pizza", 4.2, "cheese and tomato ... ")); 29 | lMenuMain.addSubitem(lPizzaMenu); 30 | 31 | Menu *lBeveragesMenu = new Menu("Beverages"); 32 | lBeveragesMenu->addSubitem(new MenuItem("Coca-Cola", 2)); 33 | 34 | Menu *lCoffeMenu = new Menu("Coffe"); 35 | lCoffeMenu->addSubitem(new MenuItem("Late", 1, " ")); 36 | lCoffeMenu->addSubitem(new MenuItem("Capucino", 2, " ")); 37 | lBeveragesMenu->addSubitem(lCoffeMenu); 38 | 39 | lBeveragesMenu->addSubitem(new MenuItem("Pepsi-Cola", 3)); 40 | 41 | Menu *lMineralWatersMenu = new Menu("Mineral waters"); 42 | lMineralWatersMenu->addSubitem(new MenuItem("Borjomi", 2.43, " nice thing ")); 43 | lMineralWatersMenu->addSubitem(new MenuItem("Morshynska", 1.4, " ")); 44 | lBeveragesMenu->addSubitem(lMineralWatersMenu); 45 | 46 | Menu *lAlcoDrinksMenu = new Menu("Alco drinks"); 47 | Menu *lWinesMenu = new Menu("Wines"); 48 | Menu *lDryWines = new Menu("Dry Wines"); 49 | lDryWines->addSubitem(new MenuItem("Bordeaux", 20)); 50 | lWinesMenu->addSubitem(lDryWines); 51 | lWinesMenu->addSubitem(new MenuItem("Champagne", 16.5)); 52 | lAlcoDrinksMenu->addSubitem(lWinesMenu); 53 | lAlcoDrinksMenu->addSubitem(new MenuItem("Beer", 5)); 54 | lBeveragesMenu->addSubitem(lAlcoDrinksMenu); 55 | 56 | lMenuMain.addSubitem(lBeveragesMenu); 57 | 58 | // Iteration example 59 | MenuIterator it(&lMenuMain); 60 | 61 | // // visiting with visitor that prints each item 62 | // ConsolePrintMenuVisitor printVisitor; 63 | 64 | while (it.hasNext()) 65 | { 66 | Composite *item = it.next(); 67 | std::cout << item->title() << std::endl; 68 | // item->accept(&printVisitor); 69 | } 70 | } 71 | 72 | int main(int argc, char *argv[]) 73 | { 74 | createAndPrintMenu(); 75 | getchar(); 76 | 77 | return 0; 78 | } 79 | 80 | -------------------------------------------------------------------------------- /CafeMenuEditor/menu.cpp: -------------------------------------------------------------------------------- 1 | #include "menu.h" 2 | #include "menuvisitor.h" 3 | 4 | /*! 5 | * \brief Menu::Menu constructor 6 | * \param pTitle is menu title 7 | */ 8 | Menu::Menu(const std::string &pTitle) 9 | : Composite(pTitle) 10 | { 11 | } 12 | 13 | /*! 14 | * \brief Menu::accept 15 | * \param visitor 16 | */ 17 | void Menu::accept(MenuVisitor *visitor) 18 | { 19 | visitor->visit(this); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /CafeMenuEditor/menu.h: -------------------------------------------------------------------------------- 1 | #ifndef MENU_H 2 | #define MENU_H 3 | 4 | #include 5 | 6 | #include "composite.h" 7 | 8 | class MenuVisitor; 9 | 10 | /*! 11 | * \brief The Menu class is a composite class - menu of items and submenus 12 | */ 13 | class Menu : public Composite 14 | { 15 | public: 16 | Menu(const std::string &pTitle); 17 | 18 | void accept(MenuVisitor *visitor); 19 | }; 20 | #endif // MENU_H 21 | -------------------------------------------------------------------------------- /CafeMenuEditor/menuitem.cpp: -------------------------------------------------------------------------------- 1 | #include "menuitem.h" 2 | #include "menuvisitor.h" 3 | 4 | #include 5 | 6 | /*! 7 | * \brief MenuItem::MenuItem constructor 8 | * \param pTitle is menu item title 9 | * \param pPrice is menu item price 10 | * \param pDescription is menu item description 11 | */ 12 | MenuItem::MenuItem(const std::string &pTitle, double pPrice, std::string pDescription) 13 | : Composite(pTitle), 14 | mPrice(pPrice), 15 | mDescription(pDescription) 16 | { 17 | } 18 | 19 | /*! 20 | * \brief MenuItem::description 21 | * \return description of this menu item 22 | */ 23 | std::string MenuItem::description() const 24 | { 25 | return mDescription; 26 | } 27 | 28 | /*! 29 | * \brief MenuItem::price 30 | * \return price of this menu item 31 | */ 32 | double MenuItem::price() const 33 | { 34 | return mPrice; 35 | } 36 | 37 | /*! 38 | * \brief MenuItem::accept 39 | * \param visitor 40 | */ 41 | void MenuItem::accept(MenuVisitor *visitor) 42 | { 43 | visitor->visit(this); 44 | } 45 | -------------------------------------------------------------------------------- /CafeMenuEditor/menuitem.h: -------------------------------------------------------------------------------- 1 | #ifndef MENUITEM_H 2 | #define MENUITEM_H 3 | 4 | #include 5 | #include 6 | #include "composite.h" 7 | 8 | class MenuVisitor; 9 | 10 | /*! 11 | * \brief The MenuItem class is main component, from which derive composites and leaves 12 | * and also class for menu item - leave of our hierarchy. 13 | */ 14 | class MenuItem : public Composite 15 | { 16 | public: 17 | 18 | MenuItem(const std::string &pTitle, double pPrice = 0.0, std::string pDescription = std::string()); 19 | 20 | std::string description() const; 21 | double price() const; 22 | 23 | void accept(MenuVisitor *visitor); 24 | 25 | private: 26 | std::string mDescription; 27 | double mPrice; 28 | }; 29 | 30 | #endif // MENUITEM_H 31 | -------------------------------------------------------------------------------- /CafeMenuEditor/menuiterator.cpp: -------------------------------------------------------------------------------- 1 | #include "menuiterator.h" 2 | #include "composite.h" 3 | 4 | /*! 5 | * \brief MenuIterator::MenuIterator constructor 6 | * \param container is menu item to iterate 7 | */ 8 | MenuIterator::MenuIterator(Composite *container) 9 | { 10 | addChildrenForTraversal(container); 11 | } 12 | 13 | /*! 14 | * \brief MenuIterator::hasNext 15 | * \return true if next menu item is found, else - false 16 | */ 17 | bool MenuIterator::hasNext() const 18 | { 19 | return !mItemsStack.empty(); 20 | } 21 | 22 | /*! 23 | * \brief MenuIterator::next 24 | * \return next menu item 25 | */ 26 | Composite *MenuIterator::next() 27 | { 28 | Composite *nextItem = mItemsStack.top(); 29 | mItemsStack.pop(); 30 | 31 | addChildrenForTraversal(nextItem); 32 | return nextItem; 33 | } 34 | 35 | /*! 36 | * \brief MenuIterator::addChildrenForTraversal 37 | * \param contaner is menu item to iterate 38 | */ 39 | void MenuIterator::addChildrenForTraversal(Composite *container) 40 | { 41 | if (container) 42 | { 43 | for (int index = 0; index < container->subitemsCount(); ++index) 44 | { 45 | Composite *item = container->child(index); 46 | mItemsStack.push(item); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /CafeMenuEditor/menuiterator.h: -------------------------------------------------------------------------------- 1 | #ifndef MENUITERATOR_H 2 | #define MENUITERATOR_H 3 | 4 | #include 5 | 6 | class Composite; 7 | 8 | /*! 9 | * \brief The MenuIterator class implements depth first iteraotion 10 | * over the given menu item composite. 11 | */ 12 | class MenuIterator 13 | { 14 | public: 15 | MenuIterator(Composite *container); 16 | 17 | bool hasNext() const; 18 | Composite *next(); 19 | 20 | private: 21 | void addChildrenForTraversal(Composite *container); 22 | 23 | private: 24 | std::stack mItemsStack; 25 | }; 26 | 27 | #endif // MENUITERATOR_H 28 | -------------------------------------------------------------------------------- /CafeMenuEditor/menuvisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef MENUVISITOR_H 2 | #define MENUVISITOR_H 3 | 4 | class MenuItem; 5 | class Menu; 6 | 7 | /*! 8 | * \brief The MenuVisitor class 9 | */ 10 | class MenuVisitor 11 | { 12 | public: 13 | virtual void visit(MenuItem *) = 0; 14 | virtual void visit(Menu *) = 0; 15 | }; 16 | 17 | #endif // MENUVISITOR_H 18 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/CafeMenu.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | QT = core 3 | CONFIG += console 4 | CONFIG += c++14 5 | CONFIG -= app_bundle 6 | 7 | SOURCES += main.cpp \ 8 | menuitem.cpp \ 9 | menu.cpp \ 10 | menuiterator.cpp \ 11 | consoleprintmenuvisitor.cpp \ 12 | composite.cpp 13 | 14 | HEADERS += \ 15 | menuitem.h \ 16 | menu.h \ 17 | menuiterator.h \ 18 | menuvisitor.h \ 19 | consoleprintmenuvisitor.h \ 20 | composite.h 21 | 22 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/composite.cpp: -------------------------------------------------------------------------------- 1 | #include "composite.h" 2 | #include "menuvisitor.h" 3 | 4 | /*! 5 | * \brief Composite::Composite constructor 6 | * \param pTitle is item's title. 7 | */ 8 | Composite::Composite(const QString &pTitle, Composite *parent): 9 | mTitle{pTitle}, 10 | mParent{parent} 11 | { 12 | } 13 | 14 | /*! 15 | * \brief Composite::~Composite destructor 16 | */ 17 | Composite::~Composite() 18 | { 19 | qDeleteAll(mListSubitems); 20 | mListSubitems.clear(); 21 | } 22 | 23 | /*! 24 | * \brief Composite::addSubitem 25 | * \param pItem is new child subitem for this item 26 | */ 27 | void Composite::addSubitem(Composite *pItem) 28 | { 29 | if (this != pItem) 30 | { 31 | mListSubitems.push_back(pItem); 32 | pItem->mParent = this; 33 | } 34 | } 35 | 36 | /*! 37 | * \brief Composite::subitemsCount 38 | * \return number of item's childs 39 | */ 40 | int Composite::subitemsCount() const 41 | { 42 | return mListSubitems.size(); 43 | } 44 | 45 | /*! 46 | * \brief Composite::child 47 | * \param pIndex is index of child item 48 | * \return child by index 49 | */ 50 | Composite *Composite::child(int pIndex) const 51 | { 52 | return mListSubitems.value(pIndex); 53 | } 54 | 55 | /*! 56 | * \brief Composite::parent 57 | * \return parent of this item 58 | */ 59 | Composite *Composite::parent() const 60 | { 61 | return mParent; 62 | } 63 | 64 | /*! 65 | * \brief Composite::title 66 | * \return title of this item 67 | */ 68 | QString Composite::title() const 69 | { 70 | return mTitle; 71 | } 72 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/composite.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPOSITE_H 2 | #define COMPOSITE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class MenuVisitor; 9 | 10 | /*! 11 | * \brief The Composite basic class that realise compositor patern for cafe menu. 12 | */ 13 | class Composite 14 | { 15 | public: 16 | Composite(const QString &pTitle, Composite *parent = nullptr); 17 | virtual ~Composite(); 18 | 19 | void addSubitem(Composite *pItem); 20 | int subitemsCount() const; 21 | Composite *child(int pIndex) const; 22 | Composite *parent() const; 23 | 24 | QString title() const; 25 | 26 | virtual void accept(MenuVisitor *visitor) = 0; 27 | 28 | private: 29 | QString mTitle; 30 | Composite* mParent; 31 | QVector mListSubitems; 32 | }; 33 | 34 | #endif // COMPOSITE_H 35 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/consoleprintmenuvisitor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "menu.h" 4 | #include "menuitem.h" 5 | #include "consoleprintmenuvisitor.h" 6 | 7 | const QString cIndentStep {" "}; 8 | const QString cMenuTitle {"%1[%2]\n"}; 9 | const QString cMenuItemMainInfo {"%1> %2 : %3$\n"}; 10 | const QString cMenuItemDescription {"%1 ::::%2::::\n"}; 11 | 12 | /*! 13 | * \brief ConsolePrintMenuVisitor::indent 14 | * \param item 15 | * \return 16 | */ 17 | QString ConsolePrintMenuVisitor::indent(Composite *item) const 18 | { 19 | QString rIndentString{}; 20 | if(item) 21 | { 22 | auto lMenuItem = item->parent(); 23 | while (lMenuItem) 24 | { 25 | lMenuItem = lMenuItem->parent(); 26 | rIndentString.append(cIndentStep); 27 | } 28 | } 29 | return rIndentString; 30 | } 31 | 32 | /*! 33 | * \brief ConsolePrintMenuVisitor::visit 34 | * \param item 35 | */ 36 | void ConsolePrintMenuVisitor::visit(MenuItem *item) 37 | { 38 | QString lIndentString {std::move(indent(item))}; 39 | if(item) 40 | { 41 | QTextStream cout{stdout}; 42 | cout << cMenuItemMainInfo.arg(lIndentString).arg(item->title()).arg(item->price()); 43 | 44 | if (!item->description().isEmpty()) 45 | { 46 | cout << cMenuItemDescription.arg(lIndentString).arg(item->description()); 47 | } 48 | } 49 | } 50 | 51 | /*! 52 | * \brief ConsolePrintMenuVisitor::visit 53 | * \param menu 54 | */ 55 | void ConsolePrintMenuVisitor::visit(Menu *menu) 56 | { 57 | QTextStream cout{stdout}; 58 | cout << cMenuTitle.arg(indent(menu)).arg(menu->title()); 59 | } 60 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/consoleprintmenuvisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSOLEPRINTMENUVISITOR_H 2 | #define CONSOLEPRINTMENUVISITOR_H 3 | 4 | #include "menuvisitor.h" 5 | #include 6 | 7 | class Composite; 8 | class QTextStream; 9 | /*! 10 | * \brief The ConsolePrintMenuVisitor class 11 | */ 12 | class ConsolePrintMenuVisitor : public MenuVisitor 13 | { 14 | public: 15 | void visit(MenuItem *item); 16 | void visit(Menu *menu); 17 | 18 | private: 19 | QString indent(Composite *item) const; 20 | }; 21 | 22 | #endif // CONSOLEPRINTMENUVISITOR_H 23 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "menuitem.h" 4 | #include "menu.h" 5 | #include "menuiterator.h" 6 | #include "composite.h" 7 | #include "consoleprintmenuvisitor.h" 8 | 9 | void createAndPrintMenu() 10 | { 11 | QTextStream cout(stdout); 12 | cout << "Restoraunt <>\n"; 13 | cout << "--------------------------------------------------------\n"; 14 | 15 | Menu lMenuMain("MAIN MENU"); 16 | 17 | Menu *lPizzaMenu {new Menu{"Pizza Menu"}}; 18 | lPizzaMenu->addSubitem(new MenuItem{"hawaiian pizza", 2.4, "cheese and tomato base with toppings of ham and pineapple"}); 19 | lPizzaMenu->addSubitem(new MenuItem{"vegetarian pizza", 4.2, "cheese and tomato ... "}); 20 | lMenuMain.addSubitem(lPizzaMenu); 21 | 22 | Menu *lBeveragesMenu{new Menu{"Beverages"}}; 23 | lBeveragesMenu->addSubitem(new MenuItem{"Coca-Cola", 2}); 24 | 25 | Menu *lCoffeMenu{new Menu{"Coffe"}}; 26 | lCoffeMenu->addSubitem(new MenuItem{"Late", 1, " "}); 27 | lCoffeMenu->addSubitem(new MenuItem{"Capucino", 2, " "}); 28 | lBeveragesMenu->addSubitem(lCoffeMenu); 29 | 30 | lBeveragesMenu->addSubitem(new MenuItem{"Pepsi-Cola", 3}); 31 | 32 | Menu *lMineralWatersMenu{new Menu{"Mineral waters"}}; 33 | lMineralWatersMenu->addSubitem(new MenuItem{"Borjomi", 2.43, " nice thing "}); 34 | lMineralWatersMenu->addSubitem(new MenuItem{"Morshynska", 1.4, " "}); 35 | lBeveragesMenu->addSubitem(lMineralWatersMenu); 36 | 37 | Menu *lAlcoDrinksMenu {new Menu{"Alco drinks"}}; 38 | Menu *lWinesMenu {new Menu{"Wines"}}; 39 | Menu *lDryWines {new Menu{"Dry Wines"}}; 40 | lDryWines->addSubitem(new MenuItem{"Bordeaux", 20}); 41 | lWinesMenu->addSubitem(lDryWines); 42 | lWinesMenu->addSubitem(new MenuItem{"Champagne", 16.5}); 43 | lAlcoDrinksMenu->addSubitem(lWinesMenu); 44 | lAlcoDrinksMenu->addSubitem(new MenuItem{"Beer", 5}); 45 | lBeveragesMenu->addSubitem(lAlcoDrinksMenu); 46 | 47 | lMenuMain.addSubitem(lBeveragesMenu); 48 | 49 | // Iteration example 50 | MenuIterator it(&lMenuMain); 51 | 52 | // visiting with visitor that prints each item 53 | ConsolePrintMenuVisitor printVisitor; 54 | 55 | Composite *item{nullptr}; 56 | while (it.hasNext()) 57 | { 58 | item = it.next(); 59 | if(item) 60 | { 61 | item->accept(&printVisitor); 62 | } 63 | } 64 | } 65 | 66 | int main(int argc, char *argv[]) 67 | { 68 | QCoreApplication app(argc, argv); 69 | createAndPrintMenu(); 70 | return app.exec(); 71 | } 72 | 73 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/menu.cpp: -------------------------------------------------------------------------------- 1 | #include "menu.h" 2 | #include "menuvisitor.h" 3 | 4 | /*! 5 | * \brief Menu::Menu constructor 6 | * \param pTitle is menu title 7 | */ 8 | Menu::Menu(const QString &pTitle) 9 | : Composite(pTitle) 10 | { 11 | } 12 | 13 | /*! 14 | * \brief Menu::accept 15 | * \param visitor 16 | */ 17 | void Menu::accept(MenuVisitor *visitor) 18 | { 19 | if(visitor) 20 | { 21 | visitor->visit(this); 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/menu.h: -------------------------------------------------------------------------------- 1 | #ifndef MENU_H 2 | #define MENU_H 3 | 4 | #include "composite.h" 5 | 6 | class MenuVisitor; 7 | 8 | /*! 9 | * \brief The Menu class is a composite class - menu of items and submenus 10 | */ 11 | class Menu : public Composite 12 | { 13 | public: 14 | Menu(const QString &pTitle); 15 | 16 | void accept(MenuVisitor *visitor); 17 | }; 18 | #endif // MENU_H 19 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/menuitem.cpp: -------------------------------------------------------------------------------- 1 | #include "menuitem.h" 2 | #include "menuvisitor.h" 3 | 4 | /*! 5 | * \brief MenuItem::MenuItem constructor 6 | * \param pTitle is menu item title 7 | * \param pPrice is menu item price 8 | * \param pDescription is menu item description 9 | */ 10 | MenuItem::MenuItem(const QString &pTitle, double pPrice, QString pDescription) 11 | : Composite(pTitle), 12 | mPrice(pPrice), 13 | mDescription(pDescription) 14 | { 15 | } 16 | 17 | /*! 18 | * \brief MenuItem::description 19 | * \return description of this menu item 20 | */ 21 | QString MenuItem::description() const 22 | { 23 | return mDescription; 24 | } 25 | 26 | /*! 27 | * \brief MenuItem::price 28 | * \return price of this menu item 29 | */ 30 | double MenuItem::price() const 31 | { 32 | return mPrice; 33 | } 34 | 35 | /*! 36 | * \brief MenuItem::accept 37 | * \param visitor 38 | */ 39 | void MenuItem::accept(MenuVisitor *visitor) 40 | { 41 | if(visitor) 42 | { 43 | visitor->visit(this); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/menuitem.h: -------------------------------------------------------------------------------- 1 | #ifndef MENUITEM_H 2 | #define MENUITEM_H 3 | 4 | #include "composite.h" 5 | 6 | class MenuVisitor; 7 | 8 | /*! 9 | * \brief The MenuItem class is main component, from which derive composites and leaves 10 | * and also class for menu item - leave of our hierarchy. 11 | */ 12 | class MenuItem : public Composite 13 | { 14 | public: 15 | 16 | MenuItem(const QString &pTitle, double pPrice = 0.0, QString pDescription = QString()); 17 | 18 | QString description() const; 19 | double price() const; 20 | 21 | void accept(MenuVisitor *visitor); 22 | 23 | private: 24 | double mPrice; 25 | QString mDescription; 26 | }; 27 | 28 | #endif // MENUITEM_H 29 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/menuiterator.cpp: -------------------------------------------------------------------------------- 1 | #include "menuiterator.h" 2 | #include "composite.h" 3 | 4 | /*! 5 | * \brief MenuIterator::MenuIterator constructor 6 | * \param container is menu item to iterate 7 | */ 8 | MenuIterator::MenuIterator(Composite *container) 9 | { 10 | addChildrenForTraversal(container); 11 | } 12 | 13 | /*! 14 | * \brief MenuIterator::hasNext 15 | * \return true if next menu item is found, else - false 16 | */ 17 | bool MenuIterator::hasNext() const 18 | { 19 | return !mItemsStack.isEmpty(); 20 | } 21 | 22 | /*! 23 | * \brief MenuIterator::next 24 | * \return next menu item 25 | */ 26 | Composite *MenuIterator::next() 27 | { 28 | auto nextItem = mItemsStack.pop(); 29 | addChildrenForTraversal(nextItem); 30 | return nextItem; 31 | } 32 | 33 | /*! 34 | * \brief MenuIterator::addChildrenForTraversal 35 | * \param contaner is menu item to iterate 36 | */ 37 | void MenuIterator::addChildrenForTraversal(Composite *container) 38 | { 39 | if (container) 40 | { 41 | for (int index = 0; index < container->subitemsCount(); ++index) 42 | { 43 | auto item = container->child(index); 44 | if(item) 45 | { 46 | mItemsStack.push(item); 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/menuiterator.h: -------------------------------------------------------------------------------- 1 | #ifndef MENUITERATOR_H 2 | #define MENUITERATOR_H 3 | 4 | #include 5 | 6 | class Composite; 7 | 8 | /*! 9 | * \brief The MenuIterator class implements depth first iteraotion 10 | * over the given menu item composite. 11 | */ 12 | class MenuIterator 13 | { 14 | public: 15 | MenuIterator(Composite *container); 16 | 17 | bool hasNext() const; 18 | Composite *next(); 19 | 20 | private: 21 | void addChildrenForTraversal(Composite *container); 22 | 23 | private: 24 | QStack mItemsStack; 25 | }; 26 | 27 | #endif // MENUITERATOR_H 28 | -------------------------------------------------------------------------------- /CafeMenuEditorQtVersion/menuvisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef MENUVISITOR_H 2 | #define MENUVISITOR_H 3 | 4 | class MenuItem; 5 | class Menu; 6 | 7 | /*! 8 | * \brief The MenuVisitor class 9 | */ 10 | class MenuVisitor 11 | { 12 | public: 13 | virtual void visit(MenuItem *) = 0; 14 | virtual void visit(Menu *) = 0; 15 | }; 16 | 17 | #endif // MENUVISITOR_H 18 | -------------------------------------------------------------------------------- /ClassInterface/ClassInterface.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console c++11 3 | CONFIG -= app_bundle 4 | CONFIG -= qt 5 | 6 | SOURCES += main.cpp 7 | 8 | -------------------------------------------------------------------------------- /ClassInterface/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | #include 6 | 7 | // Our abstract class 8 | class Shape 9 | { 10 | public: 11 | Shape() {} 12 | ~Shape() 13 | { 14 | auto deleteShape = [](Shape *p) 15 | { 16 | cout << "deleting: " << p << endl; 17 | delete p; 18 | }; 19 | 20 | std::for_each(begin(childShapes), 21 | end(childShapes), 22 | deleteShape); 23 | 24 | // for(const Shape *shape : childShapes) 25 | // { 26 | // delete shape; 27 | // } 28 | } 29 | 30 | virtual void draw() const = 0; 31 | 32 | void addShape(Shape *shape) 33 | { 34 | childShapes.push_back(shape); 35 | } 36 | 37 | private: 38 | vector childShapes; 39 | }; 40 | 41 | void Shape::draw() const 42 | { 43 | for(const Shape *shape : childShapes) 44 | { 45 | shape->draw(); 46 | } 47 | } 48 | 49 | class Rectangle : public Shape 50 | { 51 | public: 52 | virtual void draw() const override 53 | { 54 | cout << "Rectangle!" << endl; 55 | Shape::draw(); 56 | } 57 | 58 | }; 59 | 60 | class Square : public Rectangle 61 | { 62 | public: 63 | virtual void draw() const override 64 | { 65 | cout << "Square!" << endl; 66 | Shape::draw(); 67 | } 68 | }; 69 | 70 | class Circle : public Shape 71 | { 72 | public: 73 | void draw() const override 74 | { 75 | cout << "Circle!" << endl; 76 | Shape::draw(); 77 | } 78 | }; 79 | 80 | template 81 | Shape *createAShapeByType() 82 | { 83 | Shape *shape = new T; 84 | return shape; 85 | } 86 | 87 | #include 88 | #include 89 | 90 | Shape *createAShape() 91 | { 92 | int randomInt = rand() % 2 + 1; 93 | 94 | Shape *shape = nullptr; 95 | switch (randomInt) 96 | { 97 | case 1: 98 | shape = new Rectangle; 99 | break; 100 | case 2: 101 | shape = new Circle; 102 | break; 103 | default: 104 | break; 105 | } 106 | 107 | return shape; 108 | } 109 | 110 | //Shape *createAShape() 111 | //{ 112 | // Shape *shape = new Rectangle; 113 | // return shape; 114 | //} 115 | 116 | void drawANewShape(const Shape &shape) 117 | { 118 | shape.draw(); 119 | } 120 | 121 | const int cNumberOfShapes = 10; 122 | 123 | int main() 124 | { 125 | srand(time(nullptr)); 126 | 127 | Circle *c1 = new Circle; 128 | Circle *c2 = new Circle; 129 | 130 | Rectangle *rightRect = new Rectangle; 131 | rightRect->addShape(c1); 132 | rightRect->addShape(c2); 133 | 134 | Rectangle *r1 = new Rectangle; 135 | Circle *leftCircle = new Circle; 136 | leftCircle->addShape(r1); 137 | 138 | Rectangle mainRect; 139 | mainRect.addShape(leftCircle); 140 | mainRect.addShape(rightRect); 141 | mainRect.draw(); 142 | 143 | // vector shapeList; 144 | 145 | 146 | 147 | // for(int i = 0; i < cNumberOfShapes; ++i) 148 | // { 149 | // shapeList.push_back(createAShape()); 150 | // } 151 | 152 | // for(auto val : shapeList) 153 | // { 154 | // val->draw(); 155 | // } 156 | 157 | // for(auto val : shapeList) 158 | // { 159 | // delete val; 160 | // } 161 | 162 | // Shape *shape = createAShapeByType(); 163 | // Shape *shape = createAShape(4321432); 164 | // if (shape) 165 | // { 166 | // drawANewShape(*shape); 167 | // } 168 | // delete shape; 169 | 170 | return 0; 171 | } 172 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | -------------------------------------------------------------------------------- /OOP/.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated 2 | # ---------------------------------------------------------------------------- 3 | 4 | *~ 5 | *.autosave 6 | *.a 7 | *.core 8 | *.moc 9 | *.o 10 | *.obj 11 | *.orig 12 | *.rej 13 | *.so 14 | *.so.* 15 | *_pch.h.cpp 16 | *_resource.rc 17 | *.qm 18 | .#* 19 | *.*# 20 | core 21 | !core/ 22 | tags 23 | .DS_Store 24 | *.debug 25 | Makefile* 26 | *.prl 27 | *.app 28 | moc_*.cpp 29 | ui_*.h 30 | qrc_*.cpp 31 | Thumbs.db 32 | *.res 33 | *.rc 34 | /.qmake.cache 35 | /.qmake.stash 36 | 37 | # qtcreator generated files 38 | *.pro.user* 39 | 40 | # xemacs temporary files 41 | *.flc 42 | 43 | # Vim temporary files 44 | .*.swp 45 | 46 | # Visual Studio generated files 47 | *.ib_pdb_index 48 | *.idb 49 | *.ilk 50 | *.pdb 51 | *.sln 52 | *.suo 53 | *.vcproj 54 | *vcproj.*.*.user 55 | *.ncb 56 | *.sdf 57 | *.opensdf 58 | *.vcxproj 59 | *vcxproj.* 60 | 61 | # MinGW generated files 62 | *.Debug 63 | *.Release 64 | 65 | # Python byte code 66 | *.pyc 67 | 68 | # Binaries 69 | # -------- 70 | *.dll 71 | *.exe 72 | 73 | 74 | -------------------------------------------------------------------------------- /OOP/OOP.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console c++11 3 | CONFIG -= app_bundle 4 | CONFIG -= qt 5 | 6 | SOURCES += main.cpp \ 7 | iloveencapsulation.cpp \ 8 | dammoop.cpp 9 | 10 | HEADERS += \ 11 | iloveencapsulation.h \ 12 | dammoop.h \ 13 | inheritace.h \ 14 | polymorphism.h 15 | 16 | -------------------------------------------------------------------------------- /OOP/dammoop.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | *** *** 3 | *** SourceLine - Crossplatform VCS Client. *** 4 | *** Copyright (C) 2014 by *** 5 | *** Priyma Yuriy (priymayuriy@gmail.com) *** 6 | *** *** 7 | *** This file is part of SourceLine Project. *** 8 | *** *** 9 | *** SourceLine is free software: you can redistribute it and/or modify *** 10 | *** it under the terms of the GNU General Public License as published by *** 11 | *** the Free Software Foundation, either version 3 of the License, or *** 12 | *** (at your option) any later version. *** 13 | *** *** 14 | *** SourceLine is distributed in the hope that it will be useful, *** 15 | *** but WITHOUT ANY WARRANTY; without even the implied warranty of *** 16 | *** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *** 17 | *** GNU General Public License for more details. *** 18 | *** *** 19 | *** You should have received a copy of the GNU General Public License *** 20 | *** along with this program. If not, see . *** 21 | *** *** 22 | *******************************************************************************/ 23 | 24 | #include "dammoop.h" 25 | #include 26 | 27 | DammOOP::DammOOP(initializer_list &&input): 28 | mTheBestItems(input) 29 | { 30 | itemsCount = mTheBestItems.size(); 31 | } 32 | 33 | void DammOOP::sortMeBaby() 34 | { 35 | sort(mTheBestItems.data(), mTheBestItems.data() + itemsCount); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /OOP/dammoop.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | *** *** 3 | *** SourceLine - Crossplatform VCS Client. *** 4 | *** Copyright (C) 2014 by *** 5 | *** Priyma Yuriy (priymayuriy@gmail.com) *** 6 | *** *** 7 | *** This file is part of SourceLine Project. *** 8 | *** *** 9 | *** SourceLine is free software: you can redistribute it and/or modify *** 10 | *** it under the terms of the GNU General Public License as published by *** 11 | *** the Free Software Foundation, either version 3 of the License, or *** 12 | *** (at your option) any later version. *** 13 | *** *** 14 | *** SourceLine is distributed in the hope that it will be useful, *** 15 | *** but WITHOUT ANY WARRANTY; without even the implied warranty of *** 16 | *** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *** 17 | *** GNU General Public License for more details. *** 18 | *** *** 19 | *** You should have received a copy of the GNU General Public License *** 20 | *** along with this program. If not, see . *** 21 | *** *** 22 | *******************************************************************************/ 23 | 24 | #ifndef DAMMOOP_H 25 | #define DAMMOOP_H 26 | 27 | #include 28 | 29 | using namespace std; 30 | 31 | 32 | class DammOOP 33 | { 34 | public: 35 | DammOOP(initializer_list&& input); 36 | void sortMeBaby(); 37 | int itemsCount; 38 | vector mTheBestItems; 39 | }; 40 | 41 | #endif // DAMMOOP_H 42 | -------------------------------------------------------------------------------- /OOP/iloveencapsulation.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | *** *** 3 | *** SourceLine - Crossplatform VCS Client. *** 4 | *** Copyright (C) 2014 by *** 5 | *** Priyma Yuriy (priymayuriy@gmail.com) *** 6 | *** *** 7 | *** This file is part of SourceLine Project. *** 8 | *** *** 9 | *** SourceLine is free software: you can redistribute it and/or modify *** 10 | *** it under the terms of the GNU General Public License as published by *** 11 | *** the Free Software Foundation, either version 3 of the License, or *** 12 | *** (at your option) any later version. *** 13 | *** *** 14 | *** SourceLine is distributed in the hope that it will be useful, *** 15 | *** but WITHOUT ANY WARRANTY; without even the implied warranty of *** 16 | *** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *** 17 | *** GNU General Public License for more details. *** 18 | *** *** 19 | *** You should have received a copy of the GNU General Public License *** 20 | *** along with this program. If not, see . *** 21 | *** *** 22 | *******************************************************************************/ 23 | 24 | #include "iloveencapsulation.h" 25 | #include 26 | 27 | ILoveEncapsulation::ILoveEncapsulation(initializer_list&& input): 28 | mTheBestItems(input) 29 | { 30 | itemsCount = mTheBestItems.size(); 31 | } 32 | 33 | void ILoveEncapsulation::sortMeBaby() 34 | { 35 | sort(mTheBestItems.data(), mTheBestItems.data() + itemsCount); 36 | } 37 | 38 | int ILoveEncapsulation::size() 39 | { 40 | return itemsCount; 41 | } 42 | 43 | int &ILoveEncapsulation::getItem(int pIndex) 44 | { 45 | if (pIndex >=0 && pIndex < itemsCount) 46 | { 47 | return mTheBestItems[pIndex]; 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /OOP/iloveencapsulation.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | *** *** 3 | *** SourceLine - Crossplatform VCS Client. *** 4 | *** Copyright (C) 2014 by *** 5 | *** Priyma Yuriy (priymayuriy@gmail.com) *** 6 | *** *** 7 | *** This file is part of SourceLine Project. *** 8 | *** *** 9 | *** SourceLine is free software: you can redistribute it and/or modify *** 10 | *** it under the terms of the GNU General Public License as published by *** 11 | *** the Free Software Foundation, either version 3 of the License, or *** 12 | *** (at your option) any later version. *** 13 | *** *** 14 | *** SourceLine is distributed in the hope that it will be useful, *** 15 | *** but WITHOUT ANY WARRANTY; without even the implied warranty of *** 16 | *** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *** 17 | *** GNU General Public License for more details. *** 18 | *** *** 19 | *** You should have received a copy of the GNU General Public License *** 20 | *** along with this program. If not, see . *** 21 | *** *** 22 | *******************************************************************************/ 23 | 24 | #ifndef ILOVEENCAPSULATION_H 25 | #define ILOVEENCAPSULATION_H 26 | #include 27 | 28 | using namespace std; 29 | 30 | class ILoveEncapsulation 31 | { 32 | public: 33 | ILoveEncapsulation(initializer_list &&input); 34 | void sortMeBaby(); 35 | int size();// wat is missing? 36 | int& getItem(int pIndex); 37 | private: 38 | int itemsCount; 39 | vector mTheBestItems; 40 | }; 41 | 42 | #endif // ILOVEENCAPSULATION_H 43 | -------------------------------------------------------------------------------- /OOP/inheritace.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | *** *** 3 | *** SourceLine - Crossplatform VCS Client. *** 4 | *** Copyright (C) 2014 by *** 5 | *** Priyma Yuriy (priymayuriy@gmail.com) *** 6 | *** *** 7 | *** This file is part of SourceLine Project. *** 8 | *** *** 9 | *** SourceLine is free software: you can redistribute it and/or modify *** 10 | *** it under the terms of the GNU General Public License as published by *** 11 | *** the Free Software Foundation, either version 3 of the License, or *** 12 | *** (at your option) any later version. *** 13 | *** *** 14 | *** SourceLine is distributed in the hope that it will be useful, *** 15 | *** but WITHOUT ANY WARRANTY; without even the implied warranty of *** 16 | *** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *** 17 | *** GNU General Public License for more details. *** 18 | *** *** 19 | *** You should have received a copy of the GNU General Public License *** 20 | *** along with this program. If not, see . *** 21 | *** *** 22 | *******************************************************************************/ 23 | 24 | #ifndef INHERITACE 25 | #define INHERITACE 26 | 27 | // copy from here http://www.cplusplus.com/doc/tutorial/inheritance/ 28 | 29 | #include 30 | using namespace std; 31 | namespace Inheritance { 32 | class Polygon { 33 | protected: 34 | int width, height; 35 | public: 36 | void set_values (int a, int b) 37 | { width=a; height=b;} 38 | }; 39 | 40 | class Rectangle: public Polygon { 41 | public: 42 | int area () 43 | { return width * height; } 44 | }; 45 | 46 | class Triangle: public Polygon { 47 | public: 48 | int area () 49 | { return width * height / 2; } 50 | }; 51 | 52 | 53 | 54 | class Mother { 55 | public: 56 | Mother () 57 | { cout << "Mother: no parameters\n"; } 58 | Mother (int a) 59 | { cout << "Mother: int parameter\n"; } 60 | }; 61 | 62 | class Daughter : public Mother { 63 | public: 64 | Daughter (int a) 65 | { cout << "Daughter: int parameter\n\n"; } 66 | }; 67 | 68 | class Son : public Mother { 69 | public: 70 | Son (int a) : Mother (a) 71 | { cout << "Son: int parameter\n\n"; } 72 | }; 73 | } 74 | #endif // INHERITACE 75 | 76 | -------------------------------------------------------------------------------- /OOP/main.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | *** *** 3 | *** SourceLine - Crossplatform VCS Client. *** 4 | *** Copyright (C) 2014 by *** 5 | *** Priyma Yuriy (priymayuriy@gmail.com) *** 6 | *** *** 7 | *** This file is part of SourceLine Project. *** 8 | *** *** 9 | *** SourceLine is free software: you can redistribute it and/or modify *** 10 | *** it under the terms of the GNU General Public License as published by *** 11 | *** the Free Software Foundation, either version 3 of the License, or *** 12 | *** (at your option) any later version. *** 13 | *** *** 14 | *** SourceLine is distributed in the hope that it will be useful, *** 15 | *** but WITHOUT ANY WARRANTY; without even the implied warranty of *** 16 | *** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *** 17 | *** GNU General Public License for more details. *** 18 | *** *** 19 | *** You should have received a copy of the GNU General Public License *** 20 | *** along with this program. If not, see . *** 21 | *** *** 22 | *******************************************************************************/ 23 | 24 | #include 25 | 26 | using namespace std; 27 | 28 | #include "dammoop.h" // why not <> ? 29 | #include "iloveencapsulation.h" 30 | #include "inheritace.h" 31 | #include "polymorphism.h" 32 | #define UNUSED(x) (void*)&x; 33 | 34 | void encapsulationExample(); // how not define body here? 35 | void inheritanceExample(); 36 | void polymorphismExample(); 37 | 38 | 39 | int main() 40 | { 41 | encapsulationExample(); 42 | inheritanceExample(); 43 | polymorphismExample(); 44 | } 45 | 46 | 47 | 48 | 49 | void encapsulationExample() 50 | { 51 | cin.get(); 52 | cout << "------Yo encapsulationExample------"; 53 | //try to change definitions 54 | ILoveEncapsulation bestPractice{1,4,2,2,1}; 55 | DammOOP monkey{5,4,3,2,1}; 56 | cout << "monkey\n"; 57 | for (int i = 0; i < monkey.itemsCount; ++i) { 58 | cout << monkey.mTheBestItems[i] << " "; 59 | } 60 | cout << endl << "bestPractice\n"; 61 | //TODO: uncoment me to see magic 62 | //monkey.itemsCount += 5; 63 | for (int i = 0; i < bestPractice.size(); ++i) { 64 | cout << bestPractice.getItem(i) << " "; 65 | } 66 | cout << endl << "AFTER sort" << endl; 67 | monkey.sortMeBaby(); 68 | bestPractice.sortMeBaby(); 69 | 70 | cout << "monkey\n"; 71 | for (int i = 0; i < monkey.itemsCount; ++i) { 72 | cout << monkey.mTheBestItems[i] << " "; 73 | } 74 | cout << endl << "bestPractice\n"; 75 | for (int i = 0; i < bestPractice.size(); ++i) { 76 | cout << bestPractice.getItem(i) << " "; 77 | } 78 | cin.get(); 79 | } 80 | 81 | void inheritanceExample() 82 | { 83 | using namespace Inheritance; 84 | //PART 1 no copy code 85 | cout << "------inheritanceExample------\n"; 86 | cout << "no copy code\n"; 87 | Rectangle rect; 88 | Triangle trgl; 89 | rect.set_values (4,5); 90 | trgl.set_values (4,5); 91 | cout << rect.area() << '\n'; 92 | cout << trgl.area() << '\n'; 93 | cin.get(); 94 | //PART 2 95 | //constructors order; 96 | cout << "\n\n\n\nconstructors order\n"; 97 | Daughter kelly(0); 98 | UNUSED(kelly); 99 | Son bud(0); 100 | UNUSED(bud); 101 | cin.get(); 102 | } 103 | 104 | void Report(Polymorphism::Animal &rAnimal) 105 | { 106 | cout << rAnimal.GetName() << " says " << rAnimal.Speak() << endl; 107 | } 108 | 109 | void polymorphismExample() { 110 | using namespace Polymorphism; 111 | cout << "------polymorphismExample------\n"; 112 | 113 | cout << "part 1\n"; 114 | Cat cCat("Fred"); 115 | Dog cDog("Garbo"); 116 | 117 | Report(cCat); 118 | Report(cDog); 119 | cin.get(); 120 | 121 | cout << "part 2\n"; 122 | Rectangle rect; 123 | Triangle trgl; 124 | Polygon * ppoly1 = ▭ 125 | Polygon * ppoly2 = &trgl; 126 | ppoly1->set_values (4,5); 127 | ppoly2->set_values (4,5); 128 | ppoly1->printarea(); 129 | ppoly2->printarea(); 130 | cin.get(); 131 | 132 | } 133 | -------------------------------------------------------------------------------- /OOP/polymorphism.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | *** *** 3 | *** SourceLine - Crossplatform VCS Client. *** 4 | *** Copyright (C) 2014 by *** 5 | *** Priyma Yuriy (priymayuriy@gmail.com) *** 6 | *** *** 7 | *** This file is part of SourceLine Project. *** 8 | *** *** 9 | *** SourceLine is free software: you can redistribute it and/or modify *** 10 | *** it under the terms of the GNU General Public License as published by *** 11 | *** the Free Software Foundation, either version 3 of the License, or *** 12 | *** (at your option) any later version. *** 13 | *** *** 14 | *** SourceLine is distributed in the hope that it will be useful, *** 15 | *** but WITHOUT ANY WARRANTY; without even the implied warranty of *** 16 | *** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *** 17 | *** GNU General Public License for more details. *** 18 | *** *** 19 | *** You should have received a copy of the GNU General Public License *** 20 | *** along with this program. If not, see . *** 21 | *** *** 22 | *******************************************************************************/ 23 | 24 | #ifndef POLYMORPHISM 25 | #define POLYMORPHISM 26 | 27 | #include 28 | #include 29 | using namespace std; 30 | namespace Polymorphism { 31 | class Polygon { 32 | protected: 33 | int width, height; 34 | public: 35 | void set_values (int a, int b) 36 | { width=a; height=b; } 37 | virtual int area() =0; 38 | void printarea() 39 | { cout << this->area() << '\n'; } 40 | }; 41 | 42 | class Rectangle: public Polygon { 43 | public: 44 | int area (void) 45 | { return (width * height); } 46 | }; 47 | 48 | class Triangle: public Polygon { 49 | public: 50 | int area (void) 51 | { return (width * height / 2); } 52 | }; 53 | 54 | 55 | 56 | class Animal 57 | { 58 | //http://www.learncpp.com/cpp-tutorial/122-virtual-functions/ 59 | protected: 60 | std::string m_strName; 61 | 62 | // We're making this constructor protected because 63 | // we don't want people creating Animal objects directly, 64 | // but we still want derived classes to be able to use it. 65 | Animal(std::string strName) 66 | : m_strName(strName) 67 | { 68 | } 69 | 70 | public: 71 | std::string GetName() { return m_strName; } 72 | virtual const char* Speak() {return "???";} 73 | }; 74 | 75 | class Cat: public Animal 76 | { 77 | public: 78 | Cat(std::string strName) 79 | : Animal(strName) 80 | { 81 | } 82 | 83 | virtual const char* Speak() { return "Meow"; } 84 | }; 85 | 86 | class Dog: public Animal 87 | { 88 | public: 89 | Dog(std::string strName) 90 | : Animal(strName) 91 | { 92 | } 93 | 94 | virtual const char* Speak() { return "Woof"; } 95 | }; 96 | 97 | } 98 | #endif // POLYMORPHISM 99 | 100 | -------------------------------------------------------------------------------- /ObjectConstructDestructAndCopy/ObjectConstructDestructAndCopy.pro: -------------------------------------------------------------------------------- 1 | QT -= core 2 | QT -= gui 3 | 4 | TARGET = ObjectConstructDestructAndCopy 5 | CONFIG += console 6 | CONFIG += c++14 7 | CONFIG -= app_bundle 8 | 9 | TEMPLATE = app 10 | 11 | SOURCES += main.cpp 12 | 13 | -------------------------------------------------------------------------------- /ObjectConstructDestructAndCopy/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Class, with move operations support, 6 | // holding large data 7 | class DataClass 8 | { 9 | public: 10 | // Default constructor 11 | DataClass() 12 | { 13 | this->data = new char[dataSize()]; 14 | fillWithChar(0); 15 | std::cout << this << " : DataClass() [new + fill]" << std::endl; 16 | } 17 | 18 | // Copy constructor 19 | DataClass(const DataClass &other) 20 | { 21 | this->data = new char[dataSize()]; 22 | std::copy(other.data, other.data + dataSize(), this->data); 23 | std::cout << this << " : DataClass(const DataClass &other) [new + copy]" << std::endl; 24 | } 25 | 26 | // Move constructor 27 | DataClass(DataClass &&other) 28 | { 29 | this->data = other.data; 30 | other.data = nullptr; 31 | std::cout << this << " : DataClass(DataClass &&other) [move!]" << std::endl; 32 | } 33 | 34 | // Copy assigment operator 35 | DataClass& operator=(const DataClass &other) 36 | { 37 | std::copy(other.data, other.data + dataSize(), this->data); 38 | std::cout << this << " : operator=(const DataClass &other) [copy]" << std::endl; 39 | } 40 | 41 | // Move assigment operator 42 | DataClass& operator=(DataClass &&other) 43 | { 44 | this->data = other.data; 45 | other.data = nullptr; 46 | std::cout << this << " : operator=(const DataClass &&other) [move!]" << std::endl; 47 | } 48 | 49 | // Public destructor 50 | ~DataClass() 51 | { 52 | delete[] data; 53 | std::cout << this << " : ~DataClass() [delete]" << std::endl; 54 | } 55 | 56 | // Getter for data 57 | const char *getData() 58 | { 59 | return data; 60 | } 61 | 62 | // Fills internal data array with the given character 63 | void fillWithChar(char ch) 64 | { 65 | std::fill(this->data, this->data + dataSize(), ch); 66 | } 67 | 68 | private: 69 | constexpr static int dataSize() 70 | { return 1024; } 71 | 72 | private: 73 | char *data; 74 | }; 75 | 76 | // Class, with move operations support, 77 | // holding large data 78 | class TestClass 79 | { 80 | public: 81 | TestClass() 82 | { std::cout << this << " Default Constructor" << std::endl;} 83 | 84 | TestClass(const TestClass &other) 85 | { std::cout << this << " Copy Constructor" << std::endl; } 86 | 87 | TestClass(TestClass &&other) 88 | { std::cout << this << " Move Constructor" << std::endl; } 89 | 90 | TestClass& operator=(const TestClass &other) 91 | { std::cout << this << " Copy Assigment" << std::endl; return *this; } 92 | 93 | TestClass& operator=(TestClass &&other) 94 | { std::cout << this << " Move Assigment" << std::endl; return *this; } 95 | 96 | ~TestClass() 97 | { std::cout << this << " Destructor" << std::endl; } 98 | }; 99 | 100 | int main(int argc, char *argv[]) 101 | { 102 | /// Constructors and destructors, assigment 103 | 104 | // { 105 | // TestClass t; 106 | // } 107 | 108 | // { 109 | // TestClass t1; 110 | // TestClass t2; 111 | // } 112 | 113 | // { 114 | // TestClass t1; 115 | // TestClass t2; 116 | // t1 = t2; 117 | // } 118 | 119 | // { 120 | // TestClass t1; 121 | // TestClass t2(t1); 122 | // } 123 | 124 | // { 125 | // TestClass t1; 126 | // TestClass t2{t1}; 127 | // } 128 | 129 | // { 130 | // TestClass t1; 131 | // TestClass t2 = t1; 132 | // } 133 | 134 | // { 135 | // TestClass t1; 136 | // TestClass t2 = {t1}; 137 | // } 138 | 139 | // { 140 | // TestClass *t1 {new TestClass}; 141 | // TestClass *t2 {new TestClass}; 142 | // t1 = t2; 143 | // } 144 | 145 | /// Ownership unique_ptr and resource management 146 | 147 | // { 148 | // TestClass *t1 { new TestClass }; 149 | // } 150 | 151 | // { 152 | // // #include 153 | // std::unique_ptr t1{new TestClass }; 154 | // } 155 | 156 | // { 157 | // std::unique_ptr t1 = std::make_unique(); 158 | // } 159 | 160 | // { 161 | // auto t1 = std::make_unique(); 162 | // } 163 | 164 | // { 165 | // auto t1 = std::make_unique(); 166 | // auto t2 = std::make_unique(); 167 | // // t2 = t1; 168 | // // TestClass *t3 = t1; 169 | // // TestClass *t4; 170 | // // t4 = t1; 171 | // } 172 | 173 | // { 174 | // auto t1 = std::make_unique(); 175 | // auto func = [](TestClass *t1) { /*do somth*/}; 176 | // // func(t1); 177 | // // func(t1.get()); 178 | // } 179 | 180 | // { 181 | // auto func = []() 182 | // { return std::make_unique(); }; 183 | // auto t1 = func(); 184 | // } 185 | 186 | return 0; 187 | } 188 | 189 | -------------------------------------------------------------------------------- /QtBasics/QtBasics.pro: -------------------------------------------------------------------------------- 1 | QT += core 2 | QT -= gui 3 | 4 | TARGET = QtBasics 5 | CONFIG += console c++14 6 | 7 | TEMPLATE = app 8 | 9 | SOURCES += main.cpp 10 | 11 | HEADERS += 12 | 13 | DISTFILES += \ 14 | someCoolFile.txt 15 | 16 | -------------------------------------------------------------------------------- /QtBasics/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | QCoreApplication a(argc, argv); 18 | 19 | // //need to include 20 | // qDebug() << "Hello, from Qt!"; 21 | 22 | // //use this insted of "const char* " in Qt application 23 | // const char* chr {"Hello, from Qt! Again!"}; 24 | // QByteArray ba{chr}; 25 | // qDebug() << ba << "This string from QByteArray!"; 26 | 27 | // //use this insted of "string" but in Qt application 28 | // QString str{"Hello, from Qt! And Again!"}; 29 | // QString strWithArg{"String with %1 and %2 arguments."}; 30 | // qDebug() << str << "This string from QString!" 31 | // << QString::number(12) << "Number as string" 32 | // << strWithArg.arg("first").arg("second"); 33 | 34 | // QString additionalStr {"And some random string, for check!"}; 35 | // std::string concatStrStd{"Concat strings"}; 36 | // additionalStr += QString::fromStdString(concatStrStd); 37 | 38 | // QStringList strList{str}; 39 | // strList << strWithArg.arg(1).arg(2) << additionalStr; 40 | // qDebug() << strList << strList.count(); 41 | 42 | // //use this if you want to know current date and time 43 | // QDate date{QDate::currentDate()}; 44 | // QDateTime dateTime{QDateTime::currentDateTime()}; 45 | // qDebug() << date.toString(Qt::DefaultLocaleShortDate) << "Date, from QDate." 46 | // << dateTime.time().toString(Qt::ISODate)<< "Time, from QDateTime."; 47 | 48 | // //use this if you want to read from file 49 | // QFile file{"someCoolFile.txt"}; 50 | // if (file.open(QIODevice::ReadOnly | QIODevice::Text)) 51 | // { 52 | // qDebug() << file.readAll()<< "This line readed from file with QFile."; 53 | // } 54 | 55 | // //Qt and std containers 56 | // //Vector 57 | // std::vector vectStd {0, 9, 8, 7, 5, 6}; 58 | // QVector vectQt {1, 2, 3, 5, 4, 6}; 59 | // qDebug() << vectQt; 60 | 61 | // vectQt = QVector::fromStdVector(vectStd); 62 | // qDebug() << vectQt; 63 | 64 | // //List 65 | // QList listQt {2.4, 1.2, 6.7, 2, 8.1, 0.4}; 66 | // qDebug() << listQt; 67 | // std::sort(std::begin(listQt), std::end(listQt)); 68 | 69 | // std::list listStd {listQt.toStdList()}; 70 | // std::for_each(std::begin(listStd), std::end(listStd), [](double item){std::cout << item << " ";}); 71 | // std::cout << std::endl; 72 | 73 | // //Map and Hash 74 | // QMap mapQt {{"one", 1}, 75 | // {"two", 2}, 76 | // {"three", 3}}; 77 | // qDebug() << mapQt["one"] << mapQt.value("two") << mapQt.key(3); 78 | 79 | // QHash hashQt{{1,"one"}, 80 | // {2,"two"}, 81 | // {3,"three"}}; 82 | 83 | // for(const auto& value : hashQt.values()) 84 | // { 85 | // std::cout << value << " "; 86 | // } 87 | // std::cout << std::endl; 88 | 89 | // //pair 90 | // QPair piNumber{"PI", 3.14159265358979323846}; 91 | // qDebug() << piNumber << piNumber.first << piNumber.second; 92 | 93 | // //Variant 94 | 95 | // QVariant variant; 96 | // variant = ba; 97 | // qDebug() << variant.toString(); 98 | 99 | return a.exec(); 100 | } 101 | 102 | -------------------------------------------------------------------------------- /QtBasics/someCoolFile.txt: -------------------------------------------------------------------------------- 1 | Hello, from someCoolFile.txt! 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cpp_qt_examples 2 | Examples and mini projects for C++/Qt course 3 | 4 | ## Usefull links and resourses 5 | * [CPLUSPLUS] - Site dedicated to c++ (Forums, tutorials, references) 6 | * [CppReference] - Another site dedicated to c++ (including new standards) 7 | * [Computer Science Videos] - Free video lessons on YouTube. Simple, clearly and funny. 8 | * [C++ Fundamentals] - PLURALSIGHT video lessons about C++ fundamentals. 9 | * [Introduction to Qt: A C++ Cross Platform Application Framework ] - This course will get you up to speed quickly on the C++ Qt Framework. 10 | * [Qt Quick Fundamentals] - Learn to use Qt Quick to create a modern, fluid, user interface suitable for both mobile and desktop devices. 11 | * [Design Patterns] - SourceMaking will tell you a lot of stories about good software architecture and teach you how to create it with design patterns. 12 | 13 | [CPLUSPLUS]:http://www.cplusplus.com/ 14 | [CppReference]:http://en.cppreference.com/w/ 15 | [Design Patterns]:https://sourcemaking.com/design_patterns 16 | [Computer Science Videos]:http://computersciencevideos.org/Playlists#C%2B%2B 17 | [Introduction to Qt: A C++ Cross Platform Application Framework ]:https://www.dropbox.com/sh/xtmuagzutwx58f2/AADTcxUF0UR-lP4l4ExojfVXa?dl=0 18 | [Qt Quick Fundamentals]: https://www.dropbox.com/sh/cl9jij6jb1hyvjs/AAB486k5LeCTkqzQCk2BAcr_a?dl=0 19 | [C++ Fundamentals]:https://www.dropbox.com/sh/nzxn87myhduwt43/AABEUujlrQt_wR7vOJ3-lXVJa?dl=0 20 | -------------------------------------------------------------------------------- /WidgetExample/WidgetExample.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2015-11-23T22:25:52 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui widgets 8 | CONFIG += c++14 9 | TARGET = WidgetExample 10 | TEMPLATE = app 11 | 12 | 13 | SOURCES += main.cpp\ 14 | mainwindow.cpp \ 15 | analogclock.cpp 16 | 17 | HEADERS += mainwindow.h \ 18 | analogclock.h 19 | -------------------------------------------------------------------------------- /WidgetExample/analogclock.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of The Qt Company Ltd nor the names of its 21 | ** contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #include 42 | 43 | #include "analogclock.h" 44 | 45 | AnalogClock::AnalogClock(QWidget *parent) 46 | : QWidget(parent) 47 | { 48 | QTimer *timer = new QTimer(this); 49 | connect(timer, SIGNAL(timeout()), this, SLOT(update())); 50 | timer->start(1000); 51 | 52 | setWindowTitle(tr("Analog Clock")); 53 | resize(200, 200); 54 | } 55 | 56 | void AnalogClock::paintEvent(QPaintEvent *) 57 | { 58 | static const QPoint hourHand[3] = { 59 | QPoint(7, 8), 60 | QPoint(-7, 8), 61 | QPoint(0, -40) 62 | }; 63 | static const QPoint minuteHand[3] = { 64 | QPoint(7, 8), 65 | QPoint(-7, 8), 66 | QPoint(0, -70) 67 | }; 68 | 69 | QColor hourColor(127, 0, 127); 70 | QColor minuteColor(0, 127, 127, 191); 71 | 72 | int side = qMin(width(), height()); 73 | QTime time = QTime::currentTime(); 74 | 75 | QPainter painter(this); 76 | painter.setRenderHint(QPainter::Antialiasing); 77 | painter.translate(width() / 2, height() / 2); 78 | painter.scale(side / 200.0, side / 200.0); 79 | 80 | painter.setPen(Qt::NoPen); 81 | painter.setBrush(hourColor); 82 | 83 | painter.save(); 84 | painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0))); 85 | painter.drawConvexPolygon(hourHand, 3); 86 | painter.restore(); 87 | 88 | painter.setPen(hourColor); 89 | 90 | for (int i = 0; i < 12; ++i) { 91 | painter.drawLine(88, 0, 96, 0); 92 | painter.rotate(30.0); 93 | } 94 | 95 | painter.setPen(Qt::NoPen); 96 | painter.setBrush(minuteColor); 97 | 98 | painter.save(); 99 | painter.rotate(6.0 * (time.minute() + time.second() / 60.0)); 100 | painter.drawConvexPolygon(minuteHand, 3); 101 | painter.restore(); 102 | 103 | painter.setPen(minuteColor); 104 | 105 | for (int j = 0; j < 60; ++j) { 106 | if ((j % 5) != 0) 107 | painter.drawLine(92, 0, 96, 0); 108 | painter.rotate(6.0); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /WidgetExample/analogclock.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of The Qt Company Ltd nor the names of its 21 | ** contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #ifndef ANALOGCLOCK_H 42 | #define ANALOGCLOCK_H 43 | 44 | #include 45 | 46 | class AnalogClock : public QWidget 47 | { 48 | Q_OBJECT 49 | 50 | public: 51 | AnalogClock(QWidget *parent = 0); 52 | 53 | protected: 54 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 55 | }; 56 | #endif 57 | -------------------------------------------------------------------------------- /WidgetExample/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /WidgetExample/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "analogclock.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | const QString backroundColorStyle {"%1{" 13 | "background-color: %2;" 14 | "}"}; 15 | 16 | MainWindow::MainWindow(QWidget *parent) 17 | : QWidget(parent), 18 | mPushButton(new QPushButton(tr("Danger button!!! Don't push!!!!"))), 19 | mCheckBox(new QCheckBox("Bring me back my red button")), 20 | mLineEdit(new QLineEdit(tr("Enter new button name here..."))), 21 | mComboBox(new QComboBox()) 22 | { 23 | mPushButton->setStyleSheet(backroundColorStyle.arg("QPushButton").arg("red")); 24 | connect(mPushButton, &QPushButton::clicked, 25 | this, &MainWindow::slotKaboom, Qt::UniqueConnection); 26 | 27 | mCheckBox->setDisabled(true); 28 | connect(mCheckBox, &QCheckBox::clicked, 29 | this, &MainWindow::slotReturnControl, Qt::UniqueConnection); 30 | 31 | connect(mLineEdit, &QLineEdit::textEdited, 32 | this, &MainWindow::slotChangeButtonText, Qt::UniqueConnection); 33 | 34 | mComboBox->insertItem(0, "skyblue"); 35 | mComboBox->insertItem(1, "yellow"); 36 | mComboBox->insertItem(2, "green"); 37 | mComboBox->insertItem(3, "pink"); 38 | mComboBox->insertItem(4, "orange"); 39 | setStyleSheet(backroundColorStyle.arg("MainWindow").arg(mComboBox->currentText())); 40 | connect(mComboBox, &QComboBox::currentTextChanged, 41 | this, &MainWindow::slotChangeBackgroundColor, Qt::UniqueConnection); 42 | 43 | 44 | 45 | QHBoxLayout *horizontalLayout = new QHBoxLayout; 46 | horizontalLayout->addWidget(mPushButton); 47 | horizontalLayout->addWidget(mCheckBox); 48 | horizontalLayout->addStretch(); 49 | 50 | QHBoxLayout *horizontalLayout2 = new QHBoxLayout; 51 | horizontalLayout2->addWidget(new QLabel("Window background:")); 52 | horizontalLayout2->addWidget(mComboBox); 53 | 54 | QVBoxLayout *verticalLayout = new QVBoxLayout; 55 | verticalLayout->addLayout(horizontalLayout); 56 | verticalLayout->addWidget(mLineEdit); 57 | verticalLayout->addLayout(horizontalLayout2); 58 | verticalLayout->addWidget(new AnalogClock()); 59 | 60 | setLayout(verticalLayout); 61 | } 62 | 63 | void MainWindow::slotKaboom() 64 | { 65 | setStyleSheet(backroundColorStyle.arg("MainWindow").arg("red")); 66 | 67 | mPushButton->setDisabled(true); 68 | mPushButton->setText(tr("Oh, NOOOOOOOOOOOOOOOOO!")); 69 | mPushButton->setStyleSheet(backroundColorStyle.arg("QPushButton").arg("white")); 70 | 71 | mLineEdit->setDisabled(true); 72 | 73 | mCheckBox->setEnabled(true); 74 | } 75 | 76 | void MainWindow::slotReturnControl() 77 | { 78 | if(!mPushButton->isEnabled() && mCheckBox->isChecked()) 79 | { 80 | setStyleSheet(backroundColorStyle.arg("MainWindow").arg("white")); 81 | 82 | 83 | mPushButton->setText(tr("Danger button is back!!! Don't push!!!!")); 84 | mPushButton->setStyleSheet(backroundColorStyle.arg("QPushButton").arg("red")); 85 | mPushButton->setEnabled(true); 86 | 87 | mLineEdit->setEnabled(true); 88 | 89 | mCheckBox->setChecked(false); 90 | mCheckBox->setDisabled(true); 91 | } 92 | } 93 | 94 | void MainWindow::slotChangeButtonText(const QString& newText) 95 | { 96 | if(mPushButton->isEnabled()) 97 | { 98 | mPushButton->setText(newText); 99 | } 100 | } 101 | 102 | void MainWindow::slotChangeBackgroundColor(const QString &newColor) 103 | { 104 | setStyleSheet(backroundColorStyle.arg("MainWindow").arg(newColor)); 105 | } 106 | -------------------------------------------------------------------------------- /WidgetExample/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | class QCheckBox; 6 | class QLineEdit; 7 | class QComboBox; 8 | class QPushButton; 9 | 10 | class MainWindow : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | MainWindow(QWidget *parent = 0); 16 | 17 | public slots: 18 | void slotKaboom(); 19 | void slotReturnControl(); 20 | void slotChangeButtonText(const QString &newText); 21 | void slotChangeBackgroundColor(const QString &newColor); 22 | 23 | private: 24 | QPushButton *mPushButton; 25 | QCheckBox *mCheckBox; 26 | QLineEdit *mLineEdit; 27 | QComboBox *mComboBox; 28 | }; 29 | 30 | #endif // MAINWINDOW_H 31 | -------------------------------------------------------------------------------- /WidgetsAppliction/WidgetsAppliction.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (3.0) Tue Apr 14 19:01:35 2015 3 | ###################################################################### 4 | 5 | TEMPLATE = app 6 | TARGET = WidgetsAppliction 7 | INCLUDEPATH += . 8 | QT += widgets 9 | 10 | # Input 11 | HEADERS += mainwindow.h 12 | #FORMS += mainwindow.ui 13 | SOURCES += main.cpp mainwindow.cpp 14 | -------------------------------------------------------------------------------- /WidgetsAppliction/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication application(argc, argv); 7 | 8 | MainWindow window; 9 | window.show(); 10 | 11 | return application.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /WidgetsAppliction/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | #include 5 | #include 6 | 7 | MainWindow::MainWindow(QWidget *parent) : 8 | QMainWindow(parent) 9 | { 10 | this->setGeometry(200, 200, 225, 200); 11 | 12 | mButton = new QPushButton(this); 13 | mButton->setGeometry(QRect(0, 0, 101, 112)); 14 | mButton->setText("Chek right checkbox!"); 15 | mButton->setCheckable(true); 16 | mButton->setStyleSheet("background-color: red"); 17 | 18 | mCheckbox = new QCheckBox(this); 19 | mCheckbox->setGeometry(QRect(110, 0, 101, 112)); 20 | mCheckbox->setText("Push left button!"); 21 | 22 | QCheckBox *checkboxConnect = new QCheckBox(this); 23 | checkboxConnect->setGeometry(QRect(0, 110, 101, 112)); 24 | checkboxConnect->setText("Connect!"); 25 | checkboxConnect->setChecked(true); 26 | 27 | connect(checkboxConnect, SIGNAL(toggled(bool)), 28 | this, SLOT(connectButtonAndCheckbox(bool))); 29 | 30 | connectButtonAndCheckbox(true); 31 | } 32 | /* 33 | **************************************************************************************************** 34 | */ 35 | void MainWindow::connectButtonAndCheckbox(bool connect) 36 | { 37 | if (connect) 38 | { 39 | QObject::connect(mButton, SIGNAL(toggled(bool)), 40 | mCheckbox, SLOT(setChecked(bool))); 41 | QObject::connect(mCheckbox, SIGNAL(toggled(bool)), 42 | mButton, SLOT(setChecked(bool))); 43 | } 44 | else 45 | { 46 | QObject::disconnect(mButton, SIGNAL(toggled(bool)), 47 | mCheckbox, SLOT(setChecked(bool))); 48 | QObject::disconnect(mCheckbox, SIGNAL(toggled(bool)), 49 | mButton, SLOT(setChecked(bool))); 50 | } 51 | } 52 | /* 53 | **************************************************************************************************** 54 | */ 55 | -------------------------------------------------------------------------------- /WidgetsAppliction/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | class QPushButton; 7 | class QCheckBox; 8 | 9 | class MainWindow : public QMainWindow 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit MainWindow(QWidget *parent = 0); 14 | 15 | public slots: 16 | void connectButtonAndCheckbox(bool); 17 | 18 | private: 19 | QPushButton *mButton; 20 | QCheckBox *mCheckbox; 21 | }; 22 | 23 | #endif // MAINWINDOW_H 24 | -------------------------------------------------------------------------------- /WidgetsAppliction/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 0 21 | 0 22 | 400 23 | 19 24 | 25 | 26 | 27 | 28 | 29 | TopToolBarArea 30 | 31 | 32 | false 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /WidgetsAppliction/myclass.cpp: -------------------------------------------------------------------------------- 1 | #include "myclass.h" 2 | 3 | MyClass::MyClass(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | 8 | MyClass::~MyClass() 9 | { 10 | 11 | } 12 | 13 | -------------------------------------------------------------------------------- /WidgetsAppliction/myclass.h: -------------------------------------------------------------------------------- 1 | #ifndef MYCLASS_H 2 | #define MYCLASS_H 3 | 4 | #include 5 | 6 | class MyClass : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit MyClass(QObject *parent = 0); 11 | ~MyClass(); 12 | 13 | signals: 14 | 15 | public slots: 16 | }; 17 | 18 | #endif // MYCLASS_H 19 | -------------------------------------------------------------------------------- /Zoo/Zoo.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console 3 | CONFIG -= app_bundle 4 | CONFIG -= qt 5 | CONFIG += c++11 6 | 7 | SOURCES += main.cpp 8 | 9 | include(deployment.pri) 10 | qtcAddDeployment() 11 | 12 | -------------------------------------------------------------------------------- /Zoo/deployment.pri: -------------------------------------------------------------------------------- 1 | # This file was generated by an application wizard of Qt Creator. 2 | # The code below handles deployment to Android and Maemo, aswell as copying 3 | # of the application data to shadow build directories on desktop. 4 | # It is recommended not to modify this file, since newer versions of Qt Creator 5 | # may offer an updated version of it. 6 | 7 | defineTest(qtcAddDeployment) { 8 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 9 | item = item$${deploymentfolder} 10 | greaterThan(QT_MAJOR_VERSION, 4) { 11 | itemsources = $${item}.files 12 | } else { 13 | itemsources = $${item}.sources 14 | } 15 | $$itemsources = $$eval($${deploymentfolder}.source) 16 | itempath = $${item}.path 17 | $$itempath= $$eval($${deploymentfolder}.target) 18 | export($$itemsources) 19 | export($$itempath) 20 | DEPLOYMENT += $$item 21 | } 22 | 23 | MAINPROFILEPWD = $$PWD 24 | 25 | android-no-sdk { 26 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 27 | item = item$${deploymentfolder} 28 | itemfiles = $${item}.files 29 | $$itemfiles = $$eval($${deploymentfolder}.source) 30 | itempath = $${item}.path 31 | $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) 32 | export($$itemfiles) 33 | export($$itempath) 34 | INSTALLS += $$item 35 | } 36 | 37 | target.path = /data/user/qt 38 | 39 | export(target.path) 40 | INSTALLS += target 41 | } else:android { 42 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 43 | item = item$${deploymentfolder} 44 | itemfiles = $${item}.files 45 | $$itemfiles = $$eval($${deploymentfolder}.source) 46 | itempath = $${item}.path 47 | $$itempath = /assets/$$eval($${deploymentfolder}.target) 48 | export($$itemfiles) 49 | export($$itempath) 50 | INSTALLS += $$item 51 | } 52 | 53 | x86 { 54 | target.path = /libs/x86 55 | } else: armeabi-v7a { 56 | target.path = /libs/armeabi-v7a 57 | } else { 58 | target.path = /libs/armeabi 59 | } 60 | 61 | export(target.path) 62 | INSTALLS += target 63 | } else:win32 { 64 | copyCommand = 65 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 66 | source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) 67 | source = $$replace(source, /, \\) 68 | sourcePathSegments = $$split(source, \\) 69 | target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) 70 | target = $$replace(target, /, \\) 71 | target ~= s,\\\\\\.?\\\\,\\, 72 | !isEqual(source,$$target) { 73 | !isEmpty(copyCommand):copyCommand += && 74 | isEqual(QMAKE_DIR_SEP, \\) { 75 | copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" 76 | } else { 77 | source = $$replace(source, \\\\, /) 78 | target = $$OUT_PWD/$$eval($${deploymentfolder}.target) 79 | target = $$replace(target, \\\\, /) 80 | copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" 81 | } 82 | } 83 | } 84 | !isEmpty(copyCommand) { 85 | copyCommand = @echo Copying application data... && $$copyCommand 86 | copydeploymentfolders.commands = $$copyCommand 87 | first.depends = $(first) copydeploymentfolders 88 | export(first.depends) 89 | export(copydeploymentfolders.commands) 90 | QMAKE_EXTRA_TARGETS += first copydeploymentfolders 91 | } 92 | } else:ios { 93 | copyCommand = 94 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 95 | source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) 96 | source = $$replace(source, \\\\, /) 97 | target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target) 98 | target = $$replace(target, \\\\, /) 99 | sourcePathSegments = $$split(source, /) 100 | targetFullPath = $$target/$$last(sourcePathSegments) 101 | targetFullPath ~= s,/\\.?/,/, 102 | !isEqual(source,$$targetFullPath) { 103 | !isEmpty(copyCommand):copyCommand += && 104 | copyCommand += mkdir -p \"$$target\" 105 | copyCommand += && cp -r \"$$source\" \"$$target\" 106 | } 107 | } 108 | !isEmpty(copyCommand) { 109 | copyCommand = echo Copying application data... && $$copyCommand 110 | !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";" 111 | QMAKE_POST_LINK += "$$copyCommand" 112 | export(QMAKE_POST_LINK) 113 | } 114 | } else:unix { 115 | maemo5 { 116 | desktopfile.files = $${TARGET}.desktop 117 | desktopfile.path = /usr/share/applications/hildon 118 | icon.files = $${TARGET}64.png 119 | icon.path = /usr/share/icons/hicolor/64x64/apps 120 | } else:!isEmpty(MEEGO_VERSION_MAJOR) { 121 | desktopfile.files = $${TARGET}_harmattan.desktop 122 | desktopfile.path = /usr/share/applications 123 | icon.files = $${TARGET}80.png 124 | icon.path = /usr/share/icons/hicolor/80x80/apps 125 | } else { # Assumed to be a Desktop Unix 126 | copyCommand = 127 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 128 | source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) 129 | source = $$replace(source, \\\\, /) 130 | macx { 131 | target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) 132 | } else { 133 | target = $$OUT_PWD/$$eval($${deploymentfolder}.target) 134 | } 135 | target = $$replace(target, \\\\, /) 136 | sourcePathSegments = $$split(source, /) 137 | targetFullPath = $$target/$$last(sourcePathSegments) 138 | targetFullPath ~= s,/\\.?/,/, 139 | !isEqual(source,$$targetFullPath) { 140 | !isEmpty(copyCommand):copyCommand += && 141 | copyCommand += $(MKDIR) \"$$target\" 142 | copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" 143 | } 144 | } 145 | !isEmpty(copyCommand) { 146 | copyCommand = @echo Copying application data... && $$copyCommand 147 | copydeploymentfolders.commands = $$copyCommand 148 | first.depends = $(first) copydeploymentfolders 149 | export(first.depends) 150 | export(copydeploymentfolders.commands) 151 | QMAKE_EXTRA_TARGETS += first copydeploymentfolders 152 | } 153 | } 154 | !isEmpty(target.path) { 155 | installPrefix = $${target.path} 156 | } else { 157 | installPrefix = /opt/$${TARGET} 158 | } 159 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 160 | item = item$${deploymentfolder} 161 | itemfiles = $${item}.files 162 | $$itemfiles = $$eval($${deploymentfolder}.source) 163 | itempath = $${item}.path 164 | $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) 165 | export($$itemfiles) 166 | export($$itempath) 167 | INSTALLS += $$item 168 | } 169 | 170 | !isEmpty(desktopfile.path) { 171 | export(icon.files) 172 | export(icon.path) 173 | export(desktopfile.files) 174 | export(desktopfile.path) 175 | INSTALLS += icon desktopfile 176 | } 177 | 178 | isEmpty(target.path) { 179 | target.path = $${installPrefix}/bin 180 | export(target.path) 181 | } 182 | INSTALLS += target 183 | } 184 | 185 | export (ICON) 186 | export (INSTALLS) 187 | export (DEPLOYMENT) 188 | export (LIBS) 189 | export (QMAKE_EXTRA_TARGETS) 190 | } 191 | 192 | -------------------------------------------------------------------------------- /Zoo/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //Interface or Abstract class 4 | class IAnimal 5 | { 6 | public: 7 | //pure virtual function 8 | virtual void Say() = 0; 9 | }; 10 | 11 | //classes, derived from IAnimal, and realize pure virtual function Say 12 | class Donkey: public IAnimal 13 | { 14 | public: 15 | //implementation of Say from IAnimal for Donkey 16 | void Say() 17 | { 18 | std::cout << "Ia-Ia" <Say(); 39 | } 40 | 41 | }; 42 | 43 | //Template class 44 | template 45 | class SuperVasya 46 | { 47 | public: 48 | //Method can take different types, and try to call method Say 49 | void Beat(T *animal) 50 | { 51 | std::cout << "Beat animal." << std::endl; 52 | animal->Say(); 53 | } 54 | 55 | void Say() 56 | { 57 | std::cout << "!!!$#%%#$#%$#!" < 63 | void beatEveryone(T *smth) 64 | { 65 | std::cout << "Beat." << std::endl; 66 | smth->Say(); 67 | } 68 | 69 | int main() 70 | { 71 | IAnimal* donkey = new Donkey(); 72 | 73 | SuperVasya vasyaSuper; 74 | vasyaSuper.Beat(donkey); 75 | 76 | SuperVasya vasyaSuper1; 77 | Human vasa; 78 | vasyaSuper1.Beat(&vasa); 79 | 80 | beatEveryone(&vasyaSuper); 81 | return 0; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /compile_test_2/class1.cpp: -------------------------------------------------------------------------------- 1 | #include "class1.h" 2 | #include 3 | 4 | int Class1::mStaticMem = 1234; 5 | 6 | Class1::Class1(): 7 | cmMem2 {0} 8 | ,mMem {0} 9 | ,mMem3 {0} 10 | { 11 | std::cout << "Class1()" < 3 | 4 | void Class2::print() 5 | { 6 | std::cout << "Class2 mMem: " << mMem << std::endl; 7 | } 8 | -------------------------------------------------------------------------------- /compile_test_2/class2.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASS2_H 2 | #define CLASS2_H 3 | 4 | #include "class1.h" 5 | 6 | class Class2 : public Class1 7 | { 8 | public: 9 | void print(); 10 | 11 | private: 12 | int b; 13 | }; 14 | 15 | #endif // CLASS2_H 16 | -------------------------------------------------------------------------------- /compile_test_2/class3.cpp: -------------------------------------------------------------------------------- 1 | #include "class3.h" 2 | #include 3 | 4 | void Class3::print() 5 | { 6 | Class2::print(); 7 | std::cout << "Class3 " << std::endl; 8 | } 9 | -------------------------------------------------------------------------------- /compile_test_2/class3.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASS3_H 2 | #define CLASS3_H 3 | 4 | #include "class2.h" 5 | 6 | class Class3 : public Class2 7 | { 8 | public: 9 | void print(); 10 | 11 | private: 12 | int b; 13 | }; 14 | 15 | #endif // CLASS3_H 16 | -------------------------------------------------------------------------------- /compile_test_2/compile_test_2.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console 3 | CONFIG -= app_bundle 4 | CONFIG -= qt 5 | CONFIG += c++11 6 | 7 | SOURCES += main.cpp \ 8 | class1.cpp \ 9 | class2.cpp \ 10 | class3.cpp \ 11 | personalinformation.cpp 12 | 13 | include(deployment.pri) 14 | qtcAddDeployment() 15 | 16 | HEADERS += \ 17 | class1.h \ 18 | class2.h \ 19 | class3.h \ 20 | personalinformation.h \ 21 | cplusplustypes.h 22 | 23 | -------------------------------------------------------------------------------- /compile_test_2/cplusplustypes.h: -------------------------------------------------------------------------------- 1 | #ifndef CPLUSPLUSTYPES_H 2 | #define CPLUSPLUSTYPES_H 3 | 4 | bool a = true; // true/false 5 | 6 | //Integer numbers types 7 | short b1; 8 | int b2; 9 | long b3; 10 | long long b4; 11 | 12 | //Character type 13 | char c; 14 | 15 | //Fractional numbers types 16 | float d1; 17 | double d2; 18 | long double d3; 19 | 20 | //Class, struct and union 21 | class e; 22 | struct f; 23 | union n { 24 | char a[8]; 25 | int *b; 26 | }; 27 | 28 | //Const types 29 | const int i = -1; 30 | 31 | const int* c11 = 0; 32 | int* const c12 = 0; 33 | const int* const c13 = 0; 34 | 35 | enum g {c1=0, c2=100, c3=200}; 36 | enum class h {c1=0, c2=100, c3=200}; 37 | 38 | //Pointer and Reference 39 | int i2; 40 | int &j = i2; 41 | int *k = &i2; 42 | 43 | //Array 44 | int l[20]; 45 | 46 | //Pointer for various types 47 | void *z = l; 48 | 49 | //Function pointer 50 | 51 | void f(int a) 52 | { 53 | } 54 | 55 | typedef void (*ftype)(int a) ; 56 | ftype x = &f; 57 | 58 | #endif // CPLUSPLUSTYPES_H 59 | -------------------------------------------------------------------------------- /compile_test_2/deployment.pri: -------------------------------------------------------------------------------- 1 | # This file was generated by an application wizard of Qt Creator. 2 | # The code below handles deployment to Android and Maemo, aswell as copying 3 | # of the application data to shadow build directories on desktop. 4 | # It is recommended not to modify this file, since newer versions of Qt Creator 5 | # may offer an updated version of it. 6 | 7 | defineTest(qtcAddDeployment) { 8 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 9 | item = item$${deploymentfolder} 10 | greaterThan(QT_MAJOR_VERSION, 4) { 11 | itemsources = $${item}.files 12 | } else { 13 | itemsources = $${item}.sources 14 | } 15 | $$itemsources = $$eval($${deploymentfolder}.source) 16 | itempath = $${item}.path 17 | $$itempath= $$eval($${deploymentfolder}.target) 18 | export($$itemsources) 19 | export($$itempath) 20 | DEPLOYMENT += $$item 21 | } 22 | 23 | MAINPROFILEPWD = $$PWD 24 | 25 | android-no-sdk { 26 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 27 | item = item$${deploymentfolder} 28 | itemfiles = $${item}.files 29 | $$itemfiles = $$eval($${deploymentfolder}.source) 30 | itempath = $${item}.path 31 | $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) 32 | export($$itemfiles) 33 | export($$itempath) 34 | INSTALLS += $$item 35 | } 36 | 37 | target.path = /data/user/qt 38 | 39 | export(target.path) 40 | INSTALLS += target 41 | } else:android { 42 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 43 | item = item$${deploymentfolder} 44 | itemfiles = $${item}.files 45 | $$itemfiles = $$eval($${deploymentfolder}.source) 46 | itempath = $${item}.path 47 | $$itempath = /assets/$$eval($${deploymentfolder}.target) 48 | export($$itemfiles) 49 | export($$itempath) 50 | INSTALLS += $$item 51 | } 52 | 53 | x86 { 54 | target.path = /libs/x86 55 | } else: armeabi-v7a { 56 | target.path = /libs/armeabi-v7a 57 | } else { 58 | target.path = /libs/armeabi 59 | } 60 | 61 | export(target.path) 62 | INSTALLS += target 63 | } else:win32 { 64 | copyCommand = 65 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 66 | source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) 67 | source = $$replace(source, /, \\) 68 | sourcePathSegments = $$split(source, \\) 69 | target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) 70 | target = $$replace(target, /, \\) 71 | target ~= s,\\\\\\.?\\\\,\\, 72 | !isEqual(source,$$target) { 73 | !isEmpty(copyCommand):copyCommand += && 74 | isEqual(QMAKE_DIR_SEP, \\) { 75 | copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" 76 | } else { 77 | source = $$replace(source, \\\\, /) 78 | target = $$OUT_PWD/$$eval($${deploymentfolder}.target) 79 | target = $$replace(target, \\\\, /) 80 | copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" 81 | } 82 | } 83 | } 84 | !isEmpty(copyCommand) { 85 | copyCommand = @echo Copying application data... && $$copyCommand 86 | copydeploymentfolders.commands = $$copyCommand 87 | first.depends = $(first) copydeploymentfolders 88 | export(first.depends) 89 | export(copydeploymentfolders.commands) 90 | QMAKE_EXTRA_TARGETS += first copydeploymentfolders 91 | } 92 | } else:ios { 93 | copyCommand = 94 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 95 | source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) 96 | source = $$replace(source, \\\\, /) 97 | target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target) 98 | target = $$replace(target, \\\\, /) 99 | sourcePathSegments = $$split(source, /) 100 | targetFullPath = $$target/$$last(sourcePathSegments) 101 | targetFullPath ~= s,/\\.?/,/, 102 | !isEqual(source,$$targetFullPath) { 103 | !isEmpty(copyCommand):copyCommand += && 104 | copyCommand += mkdir -p \"$$target\" 105 | copyCommand += && cp -r \"$$source\" \"$$target\" 106 | } 107 | } 108 | !isEmpty(copyCommand) { 109 | copyCommand = echo Copying application data... && $$copyCommand 110 | !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";" 111 | QMAKE_POST_LINK += "$$copyCommand" 112 | export(QMAKE_POST_LINK) 113 | } 114 | } else:unix { 115 | maemo5 { 116 | desktopfile.files = $${TARGET}.desktop 117 | desktopfile.path = /usr/share/applications/hildon 118 | icon.files = $${TARGET}64.png 119 | icon.path = /usr/share/icons/hicolor/64x64/apps 120 | } else:!isEmpty(MEEGO_VERSION_MAJOR) { 121 | desktopfile.files = $${TARGET}_harmattan.desktop 122 | desktopfile.path = /usr/share/applications 123 | icon.files = $${TARGET}80.png 124 | icon.path = /usr/share/icons/hicolor/80x80/apps 125 | } else { # Assumed to be a Desktop Unix 126 | copyCommand = 127 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 128 | source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) 129 | source = $$replace(source, \\\\, /) 130 | macx { 131 | target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) 132 | } else { 133 | target = $$OUT_PWD/$$eval($${deploymentfolder}.target) 134 | } 135 | target = $$replace(target, \\\\, /) 136 | sourcePathSegments = $$split(source, /) 137 | targetFullPath = $$target/$$last(sourcePathSegments) 138 | targetFullPath ~= s,/\\.?/,/, 139 | !isEqual(source,$$targetFullPath) { 140 | !isEmpty(copyCommand):copyCommand += && 141 | copyCommand += $(MKDIR) \"$$target\" 142 | copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" 143 | } 144 | } 145 | !isEmpty(copyCommand) { 146 | copyCommand = @echo Copying application data... && $$copyCommand 147 | copydeploymentfolders.commands = $$copyCommand 148 | first.depends = $(first) copydeploymentfolders 149 | export(first.depends) 150 | export(copydeploymentfolders.commands) 151 | QMAKE_EXTRA_TARGETS += first copydeploymentfolders 152 | } 153 | } 154 | !isEmpty(target.path) { 155 | installPrefix = $${target.path} 156 | } else { 157 | installPrefix = /opt/$${TARGET} 158 | } 159 | for(deploymentfolder, DEPLOYMENTFOLDERS) { 160 | item = item$${deploymentfolder} 161 | itemfiles = $${item}.files 162 | $$itemfiles = $$eval($${deploymentfolder}.source) 163 | itempath = $${item}.path 164 | $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) 165 | export($$itemfiles) 166 | export($$itempath) 167 | INSTALLS += $$item 168 | } 169 | 170 | !isEmpty(desktopfile.path) { 171 | export(icon.files) 172 | export(icon.path) 173 | export(desktopfile.files) 174 | export(desktopfile.path) 175 | INSTALLS += icon desktopfile 176 | } 177 | 178 | isEmpty(target.path) { 179 | target.path = $${installPrefix}/bin 180 | export(target.path) 181 | } 182 | INSTALLS += target 183 | } 184 | 185 | export (ICON) 186 | export (INSTALLS) 187 | export (DEPLOYMENT) 188 | export (LIBS) 189 | export (QMAKE_EXTRA_TARGETS) 190 | } 191 | 192 | -------------------------------------------------------------------------------- /compile_test_2/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "class1.h" 4 | #include "class2.h" 5 | #include "class3.h" 6 | #include "cplusplustypes.h" 7 | #include "personalinformation.h" 8 | 9 | // Class1 *param = ... 10 | void func(Class1 *param) 11 | { 12 | param->setMem(13); 13 | } 14 | 15 | // Class1 ¶m = ... 16 | void func(Class1 ¶m) 17 | { 18 | param.setMem(13); 19 | } 20 | 21 | // Class1 param = ... 22 | void func_no_modify(Class1 param) 23 | { 24 | param.setMem(13); 25 | } 26 | 27 | static Class1 aaa; 28 | 29 | int main() 30 | { 31 | int array[3] = {1,2,3}; 32 | std::cout << array[2] << std::endl; 33 | std::cout << 2[array] << std::endl; 34 | 35 | Class1 classObj1; 36 | func_no_modify(classObj1); 37 | 38 | Class1* classObj2 = new Class1(); 39 | classObj2 = 0; 40 | func(classObj2); 41 | delete classObj2; 42 | 43 | Class2 classObj3; 44 | classObj3.setMem(12); 45 | classObj3.print(); 46 | std::cout << classObj3.mem() << std::endl; 47 | 48 | Class3 classObj4; 49 | classObj4.print(); 50 | 51 | std::cout << Class1::staticMem(); 52 | 53 | PersonalInformation info; 54 | info.setBirthYear(2000); 55 | if (info.error().empty()) 56 | { 57 | std::cout << info.birthYear(); 58 | } 59 | else 60 | { 61 | std::cout << info.error(); 62 | } 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /compile_test_2/personalinformation.cpp: -------------------------------------------------------------------------------- 1 | #include "personalinformation.h" 2 | 3 | PersonalInformation::PersonalInformation() 4 | { 5 | //Initialization of mBirthYear member of the class by zero. 6 | mBirthYear = 0; 7 | } 8 | /* 9 | *************************************************************************************************** 10 | */ 11 | void PersonalInformation::setBirthYear(unsigned int year) 12 | { 13 | if ((1900 < year) && (year < 2016)) 14 | { 15 | mBirthYear = year; 16 | } 17 | else 18 | { 19 | mError = "Incorrect year"; 20 | } 21 | } 22 | /* 23 | *************************************************************************************************** 24 | */ 25 | unsigned int PersonalInformation::birthYear() 26 | { 27 | return mBirthYear; 28 | } 29 | /* 30 | *************************************************************************************************** 31 | */ 32 | std::string PersonalInformation::error() 33 | { 34 | return mError; 35 | } 36 | /* 37 | *************************************************************************************************** 38 | */ 39 | -------------------------------------------------------------------------------- /compile_test_2/personalinformation.h: -------------------------------------------------------------------------------- 1 | #ifndef PERSONALINFORMATION_H 2 | #define PERSONALINFORMATION_H 3 | 4 | #include 5 | 6 | //Type PersonalInformation 7 | class PersonalInformation 8 | { 9 | public: 10 | //Constructor. Always runs, when object of class is created. 11 | PersonalInformation(); 12 | 13 | //Method. Function incapsulated in class. Can be used from object of the class, or inside the 14 | //class. 15 | //setBirthYear - set mBirthYear by user input year. If condition is incorect - set error. 16 | void setBirthYear(unsigned int year); 17 | 18 | //birthYear - returns current year for user. 19 | unsigned int birthYear(); 20 | 21 | //error - returns last error for user. 22 | std::string error(); 23 | 24 | private: 25 | // private(available only inside current class) class members(fields of class). 26 | int mBirthYear; 27 | std::string mError; 28 | }; 29 | 30 | #endif // PERSONALINFORMATION_H 31 | -------------------------------------------------------------------------------- /datatypes/datatypes.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console c++11 3 | CONFIG -= app_bundle 4 | CONFIG -= qt 5 | 6 | SOURCES += main.cpp 7 | 8 | -------------------------------------------------------------------------------- /datatypes/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void old_style_function(int arr[], size_t size) 4 | { 5 | for (int index = 0; index < size; ++index) 6 | { 7 | std::cout << arr[index] << std::endl; 8 | } 9 | std::cout << std::endl; 10 | } 11 | 12 | int main() 13 | { 14 | // Some fundamental types that we will use 15 | // ============================== 16 | 17 | std::cout << "Some fundamental types: " << std::endl; 18 | std::cout << std::endl; 19 | 20 | int integerValue{42}; 21 | std::cout << "integerValue = " << integerValue << std::endl; 22 | 23 | double floatingPointValue{42.0}; 24 | std::cout << "floatingPointValue = " << floatingPointValue << std::endl; 25 | 26 | bool boolValue{true}; 27 | std::cout << "boolValue = " << boolValue << std::endl; 28 | 29 | char singleCharacter{'c'}; 30 | std::cout << "singleCharacter = " << singleCharacter << std::endl; 31 | 32 | std::cout << std::endl; 33 | 34 | // Example of some compound types 35 | // ============================== 36 | 37 | std::cout << "Example of some compound types: " << std::endl; 38 | std::cout << std::endl; 39 | 40 | int &integerValueRef{integerValue}; // Reference to integer 41 | integerValueRef = 43; // integerValue also modified!!! 42 | 43 | std::cout << "integerValueRef = " << integerValueRef << std::endl; 44 | std::cout << "integerValue = " << integerValue << std::endl; 45 | std::cout << std::endl; 46 | 47 | // --- 48 | 49 | int *poinerToIntegerValue{&integerValue}; // Take integerValue address and assign to poiner 50 | *poinerToIntegerValue = 44; // integerValue also modified!!! 51 | 52 | std::cout << "poinerToIntegerValue = " << poinerToIntegerValue << std::endl; 53 | std::cout << "*poinerToIntegerValue = " << *poinerToIntegerValue << std::endl; 54 | std::cout << "integerValue = " << integerValue << std::endl; 55 | std::cout << std::endl; 56 | 57 | // --- 58 | 59 | int plainArray[] {1, 2, 3, 4, 5}; // You should know exact size or it could be calculated 60 | // during initialization 61 | std::cout << "plainArray = " << plainArray << std::endl; 62 | 63 | // Iterating through 64 | for (auto elem: plainArray) 65 | { 66 | std::cout << elem << std::endl; 67 | } 68 | std::cout << std::endl; 69 | 70 | size_t plainArraySize = sizeof(plainArray) / sizeof(plainArray[0]); 71 | std::cout << "plainArraySize = " << plainArraySize << std::endl; 72 | // Old style passing array to function 73 | old_style_function(plainArray, plainArraySize); 74 | 75 | // --- 76 | 77 | // Enumerations 78 | enum class TrafficLight{Red, Yellow, Green}; 79 | TrafficLight currentLight{TrafficLight::Green}; 80 | 81 | return 0; 82 | } 83 | 84 | --------------------------------------------------------------------------------