From c21659cb4d82b71b91eac38a375cd03253ec13a8 Mon Sep 17 00:00:00 2001 From: Hajdu Csaba Date: Sat, 14 Sep 2019 19:08:20 +0200 Subject: [PATCH 01/14] Recitation No.1 exercises based on Hegyhati --- SZE/OODB/kyberszittya/Rec1/.gitignore | 1 + SZE/OODB/kyberszittya/Rec1/CMakeLists.txt.in | 15 ++ .../easy/triangle_area_calculator/.gitignore | 1 + .../triangle_area_calculator/CMakeLists.txt | 29 ++++ .../triangle_area_calculator/src/main.cpp | 28 +++ .../triangle_area_calculator/src/triangle.cpp | 33 ++++ .../triangle_area_calculator/src/triangle.h | 10 ++ .../test/test_triangle.cpp | 33 ++++ .../simple_temp_monitor_memory/.gitignore | 1 + .../simple_temp_monitor_memory/CMakeLists.txt | 4 + .../hard/simple_temp_monitor_memory/Readme.md | 28 +++ .../simple_temp_monitor_memory/src/main.cpp | 159 ++++++++++++++++++ .../Rec1/medium/brakedistance_calc/.gitignore | 1 + .../medium/brakedistance_calc/CMakeLists.txt | 31 ++++ .../medium/brakedistance_calc/data/sim1.dat | 3 + .../src/BrakeDistanceCalc.h | 44 +++++ .../brakedistance_calc/src/brake_distance.cpp | 16 ++ .../medium/brakedistance_calc/src/main.cpp | 44 +++++ .../brakedistance_calc/src/main_file.cpp | 59 +++++++ .../test/test_vehicle_brake_distance.cpp | 21 +++ .../medium/simple_temp_monitor/.gitignore | 1 + .../medium/simple_temp_monitor/CMakeLists.txt | 4 + .../medium/simple_temp_monitor/src/main.cpp | 61 +++++++ 23 files changed, 627 insertions(+) create mode 100644 SZE/OODB/kyberszittya/Rec1/.gitignore create mode 100644 SZE/OODB/kyberszittya/Rec1/CMakeLists.txt.in create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/.gitignore create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/CMakeLists.txt create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/main.cpp create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/triangle.cpp create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/triangle.h create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/test/test_triangle.cpp create mode 100644 SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/.gitignore create mode 100644 SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/CMakeLists.txt create mode 100644 SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/Readme.md create mode 100644 SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/src/main.cpp create mode 100644 SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/.gitignore create mode 100644 SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/CMakeLists.txt create mode 100644 SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/data/sim1.dat create mode 100644 SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/BrakeDistanceCalc.h create mode 100644 SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/brake_distance.cpp create mode 100644 SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/main.cpp create mode 100644 SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/main_file.cpp create mode 100644 SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/test/test_vehicle_brake_distance.cpp create mode 100644 SZE/OODB/kyberszittya/Rec1/medium/simple_temp_monitor/.gitignore create mode 100644 SZE/OODB/kyberszittya/Rec1/medium/simple_temp_monitor/CMakeLists.txt create mode 100644 SZE/OODB/kyberszittya/Rec1/medium/simple_temp_monitor/src/main.cpp diff --git a/SZE/OODB/kyberszittya/Rec1/.gitignore b/SZE/OODB/kyberszittya/Rec1/.gitignore new file mode 100644 index 00000000..dbe9c82b --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/.gitignore @@ -0,0 +1 @@ +.vscode/ \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/CMakeLists.txt.in b/SZE/OODB/kyberszittya/Rec1/CMakeLists.txt.in new file mode 100644 index 00000000..f98ccb4a --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(googletest-download NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/.gitignore b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/.gitignore new file mode 100644 index 00000000..d1638636 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/CMakeLists.txt b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/CMakeLists.txt new file mode 100644 index 00000000..630410c2 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.5) +project(TriangleCalc) + +add_executable(TriangleAreaCalc src/main.cpp src/triangle.cpp) + +# If you want to test, then go ahead with it +configure_file(./../../CMakeLists.txt.in googletest-download/CMakeLists.txt) +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) + +set(PROJECT_TEST_NAME ${PROJECT_NAME}_test) +include_directories(${GTEST_INCLUDE_DIRS}) +add_executable(${PROJECT_TEST_NAME} test/test_triangle.cpp src/triangle.cpp) + + +target_link_libraries(${PROJECT_TEST_NAME} gtest_main pthread) diff --git a/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/main.cpp b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/main.cpp new file mode 100644 index 00000000..3f6ffb6b --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/main.cpp @@ -0,0 +1,28 @@ + +#include + +#include "triangle.h" + + +int main(int argc, char** argv) +{ + double a,b,c; + std::cout << "Give me some traingle parameters" << '\n'; + std::cout << "Side a [cm]: "; + std::cin >> a; + std::cout << "Side b [cm]: "; + std::cin >> b; + std::cout << "Side c [cm]: "; + std::cin >> c; + Triangle triangle({a,b,c}); + if (validTriangle(triangle)) + { + std::cout << "Area [cm^2]: " << calcTriangleArea(triangle) << '\n'; + } + else + { + std::cerr << "Invalid triangle\n"; + } + + return 0; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/triangle.cpp b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/triangle.cpp new file mode 100644 index 00000000..e5374510 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/triangle.cpp @@ -0,0 +1,33 @@ +#include "triangle.h" + + +inline double calcSemiperimeter(const Triangle& triangle) +{ + return (triangle.a+triangle.b+triangle.c)/2.0; +} + +/** + * Check if triangle is correct using triangle equations + * */ +bool validTriangle(const Triangle& triangle) +{ + if (std::abs(triangle.a - triangle.b) < triangle.c && triangle.c < triangle.a + triangle.b) + { + return true; + } + else + { + return false; + } + +} + +/** + * Use Heron's formula. It's cool. + * A = sqrt() + * */ +double calcTriangleArea(const Triangle& triangle) +{ + double s = calcSemiperimeter(triangle); + return std::sqrt(s*(s-triangle.a)*(s-triangle.b)*(s-triangle.c)); +} diff --git a/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/triangle.h b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/triangle.h new file mode 100644 index 00000000..7dc75b9d --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/triangle.h @@ -0,0 +1,10 @@ +#include + +struct Triangle +{ + double a,b,c; +}; + +inline double calcSemiperimeter(const Triangle& triangle); +bool validTriangle(const Triangle& triangle); +double calcTriangleArea(const Triangle& triangle); \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/test/test_triangle.cpp b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/test/test_triangle.cpp new file mode 100644 index 00000000..e99a638d --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/test/test_triangle.cpp @@ -0,0 +1,33 @@ +#include "../src/triangle.h" + +#include "gtest/gtest.h" + +TEST(TriangleTestSuite, triangleEquationCorrect1) +{ + Triangle triangle({3,4,5}); + ASSERT_TRUE(validTriangle(triangle)); +} + +TEST(TriangleTestSuite, triangleEquationCorrect2) +{ + Triangle triangle({13,12,17}); + ASSERT_TRUE(validTriangle(triangle)); +} + +TEST(TriangleTestSuite, triangleEquationIncorrect1) +{ + Triangle triangle({13,12,34}); + ASSERT_FALSE(validTriangle(triangle)); +} + +TEST(TriangleTestSuite, triangleArea) +{ + Triangle triangle({3,4,5}); + ASSERT_DOUBLE_EQ(6.0, calcTriangleArea(triangle)); +} + +int main(int argc, char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/.gitignore b/SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/.gitignore new file mode 100644 index 00000000..d1638636 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/CMakeLists.txt b/SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/CMakeLists.txt new file mode 100644 index 00000000..67052670 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.5) +project(SimpleTempMonitorMemory) + +add_executable(SimpleTempMonitorMemory src/main.cpp) \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/Readme.md b/SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/Readme.md new file mode 100644 index 00000000..de427921 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/Readme.md @@ -0,0 +1,28 @@ +# Build with CMake +Create a folder: +```bash +mkdir build && cd build +cmake .. +make +``` +Then run: +```bash +./SimpleTempMonitorMemory +``` + +# Debug +To debug with cmake, run the following: +```bash +mkdir build && cd build +cmake .. -DCMAKE_BUILD_TYPE=Debug +make +``` +Then, you can use a debugger (gdb): +``` +gdb ./SimpleTempMonitorMemory +``` + +To check memory leaks with Valgrind, use the following: +``` +valgrind --leak-check=yes ./SimpleTempMonitorMemory +``` \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/src/main.cpp b/SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/src/main.cpp new file mode 100644 index 00000000..b1391984 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/hard/simple_temp_monitor_memory/src/main.cpp @@ -0,0 +1,159 @@ +#include +#include + +struct TemperatureElement +{ + double temp; + double humidity; + TemperatureElement* next; +}; + +struct TemperatureChain +{ + unsigned int cnt; + TemperatureElement* first; + TemperatureElement* last; +}; + +void reset(TemperatureChain*& chain) +{ + if (chain!=NULL) + { + TemperatureElement* elem = chain->first; + while (elem != NULL) + { + TemperatureElement* tmp = elem; + elem = elem->next; + delete tmp; + } + delete chain; + chain = NULL; + } +} + +void appendLast(TemperatureChain*& chain, const double temp, const double humidity) +{ + TemperatureElement* elem = new TemperatureElement(); + elem->next = NULL; + if (chain==NULL) + { + chain = new TemperatureChain(); + chain->first = elem; + chain->last = elem; + chain->cnt = 1; + } + else + { + chain->last->next = elem; + chain->last = elem; + chain->cnt++; + } + elem->temp = temp; + elem->humidity = humidity; +} + +bool temperatureComfortable(const TemperatureElement& temp) +{ + if (temp.temp < 15) + { + return false; + } + else if (temp.temp > 28) + { + return false; + } + return true; +} + +void addTemperatureElement(TemperatureChain*& chain) +{ + static std::random_device rd; + static std::mt19937 gen(rd()); + static std::uniform_real_distribution dis_temp(14.7, 28.3); + static std::uniform_real_distribution dis_humidity(0.0, 1.0); + appendLast(chain, dis_temp(gen), dis_humidity(gen)); +} + +void print(TemperatureChain*& chain) +{ + TemperatureElement* elem = chain->first; + while (elem->next != NULL) + { + std::cout << "Temperature: " << elem->temp << "\t" << elem->humidity << '\n'; + elem = elem->next; + } +} + +bool checkTemperature(TemperatureChain*& chain) +{ + TemperatureElement* elem = chain->first; + while (elem->next != NULL) + { + if (!temperatureComfortable(*elem)) + { + std::cerr << "Uncomfortable temperature reached" << '\n'; + return false; + } + elem = elem->next; + } + return true; +} + +double avgTemperature(TemperatureChain*& chain) +{ + TemperatureElement* elem = chain->first; + double temp = 0.0; + while (elem->next != NULL) + { + if (!temperatureComfortable(*elem)) + { + temp += elem->temp; + } + elem = elem->next; + } + return temp/((double)chain->cnt); +} + +double maxTemperature(TemperatureChain*& chain) +{ + TemperatureElement* elem = chain->first; + double max = 0.0; + while (elem->next != NULL) + { + if (!temperatureComfortable(*elem)) + { + if (elem->temp > max) + { + max = elem->temp; + } + } + elem = elem->next; + } + return max; +} + +constexpr int CHAIN_LENGTH = 10000; + +int main(int argc, char** argv) +{ + TemperatureChain* chain = NULL; + // Construct temperature chain + for (int i = 0; i < CHAIN_LENGTH - 1; i++) + { + addTemperatureElement(chain); + } + print(chain); + if (checkTemperature(chain)) + { + std::cout << "Temperature OK\n"; + } + else + { + std::cout << "Temperature is uncomfortable\n"; + } + std::cout << "Average temperature: " << avgTemperature(chain) << '\n'; + std::cout << "Max temperature: " << maxTemperature(chain) << '\n'; + // Delete chain + reset(chain); + return 0; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/.gitignore b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/.gitignore new file mode 100644 index 00000000..d1638636 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/CMakeLists.txt b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/CMakeLists.txt new file mode 100644 index 00000000..7dc76a8e --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.5) +project(BrakeDistanceCalc) + +add_executable(BrakeDistanceCalc src/brake_distance.cpp src/main.cpp) +add_executable(BrakeDistanceCalcFile src/brake_distance.cpp src/main_file.cpp) + +# If you want to test, then go ahead with it +configure_file(./../../CMakeLists.txt.in googletest-download/CMakeLists.txt) +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) + +set(PROJECT_TEST_NAME ${PROJECT_NAME}_test) +include_directories(${GTEST_INCLUDE_DIRS}) +add_executable(${PROJECT_TEST_NAME} test/test_vehicle_brake_distance.cpp src/brake_distance.cpp) + + + +target_link_libraries(${PROJECT_TEST_NAME} gtest_main pthread) diff --git a/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/data/sim1.dat b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/data/sim1.dat new file mode 100644 index 00000000..e433659d --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/data/sim1.dat @@ -0,0 +1,3 @@ +10 100 1200 1.0 +10 1000 1200 1.0 +10 100 1400 1.0 \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/BrakeDistanceCalc.h b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/BrakeDistanceCalc.h new file mode 100644 index 00000000..6e025ce1 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/BrakeDistanceCalc.h @@ -0,0 +1,44 @@ +#ifndef BRAKE_DISTANCE_CALC_H +#define BRAKE_DISTANCE_CALC_H + +/** + * + * + * d = v^2/(2*mu*g) + * + * More information on the topic here: + * https://en.wikipedia.org/wiki/Braking_distance + * + * */ + +namespace szechenyi_programming +{ + +constexpr double ACC_GRAVITY = 9.81; + +constexpr double COEFFICIENT_FRICTION = 0.6; + +struct Vehicle +{ + const double friction_coeff; + const double mass; + // Dynamic parameters + double velocity; + double acceleration; +}; + +/** + * Calculate instantaneous braking distance of a vehicle + * */ +double calcBrakeDistance(const Vehicle& vehicle); + +/** + * Accelerate vehicle + * */ +void accelerateVehicle(Vehicle& vehicle, const double acc, const double t); + +double calcDistance(const Vehicle& vehicle, const double t); + +} + +#endif \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/brake_distance.cpp b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/brake_distance.cpp new file mode 100644 index 00000000..f9be875c --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/brake_distance.cpp @@ -0,0 +1,16 @@ +#include "BrakeDistanceCalc.h" + +double szechenyi_programming::calcBrakeDistance(const Vehicle& vehicle) +{ + return (vehicle.velocity*vehicle.velocity)/(2*vehicle.friction_coeff*szechenyi_programming::ACC_GRAVITY); +} + +void szechenyi_programming::accelerateVehicle(Vehicle& vehicle, const double acc, const double t) +{ + vehicle.velocity += acc * t; +} + +double szechenyi_programming::calcDistance(const Vehicle& vehicle, const double t) +{ + return vehicle.velocity * t + vehicle.acceleration/2.0 * t * t; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/main.cpp b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/main.cpp new file mode 100644 index 00000000..ca81e58f --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/main.cpp @@ -0,0 +1,44 @@ +#include "BrakeDistanceCalc.h" + +#include + +using namespace szechenyi_programming; +using namespace std; + +int main(int argc, char** argv) +{ + // Vehicle parameters + double acc; + double mass; + // Simulation parameters + double t_end; + unsigned int steps; + cout << "Brake distance calculation\n" << "----------" << '\n'; + cout << "Simulation parameters" << '\n' << "----------" << '\n'; + cout << "Simulation duration [s]: "; + cin >> t_end; + cout << "Simulation steps: "; + cin >> steps; + const double dt = t_end/steps; + cout << "Granularity: " << dt; + cout << "\nVehicle parameters" << '\n' << "----------" << '\n'; + cout << "Vehicle mass [kg]: "; + cin >> mass; + cout << "Vehicle acceleration [m/s^2]: "; + cin >> acc; + // Start our simulation + double t = 0.0; + double s = 0.0; + Vehicle vehicle({COEFFICIENT_FRICTION, mass, 0.0, 0.0}); + // Run our simulation + for (int i = 0.0; i < steps; i++) + { + accelerateVehicle(vehicle, acc, dt); + t += dt; + s += calcDistance(vehicle, dt); + cout << "Vehicle speed at time [" << t << " secs]: " << vehicle.velocity << " [m/s]" << '\n'; + cout << "Distance so far [m]: " << calcDistance(vehicle, t) << '\n'; + cout << "Braking distance [m]: " << calcBrakeDistance(vehicle) << '\n'; + } + return 0; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/main_file.cpp b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/main_file.cpp new file mode 100644 index 00000000..6e0eeb1a --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/src/main_file.cpp @@ -0,0 +1,59 @@ +#include "BrakeDistanceCalc.h" + +#include +#include +#include +#include + +using namespace szechenyi_programming; +using namespace std; + +int main(int argc, char** argv) +{ + ifstream vehicle_files(argv[1]); + if (vehicle_files.is_open()) + { + string line; + while(getline(vehicle_files, line)) + { + // Vehicle parameters + double acc; + double mass; + // Simulation parameters + double t_end; + unsigned int steps; + stringstream ss(line); + ss >> t_end; + ss >> steps; + const double dt = t_end/steps; + ss >> mass; + ss >> acc; + cout << "Read vehicle from file" << '\n'; + cout << "Brake distance calculation\n" << "----------" << '\n'; + cout << "Simulation parameters" << '\n' << "----------" << '\n'; + cout << "Simulation duration [s]: " << t_end << '\n'; + cout << "Simulation steps: " << steps << '\n'; + cout << "Granularity: " << dt << '\n'; + cout << "\nVehicle parameters" << '\n' << "----------" << '\n'; + cout << "Vehicle mass [kg]: " << mass << '\n'; + cout << "Vehicle acceleration [m/s^2]: " << acc << '\n'; + // Start our simulation + double t = 0.0; + double s = 0.0; + Vehicle vehicle({COEFFICIENT_FRICTION, mass, 0.0, 0.0}); + // Run our simulation + for (int i = 0.0; i < steps; i++) + { + accelerateVehicle(vehicle, acc, dt); + t += dt; + s += calcDistance(vehicle, dt); + cout << "Vehicle speed at time [" << t << " secs]: " << vehicle.velocity << " [m/s]" << '\n'; + cout << "Distance so far [m]: " << calcDistance(vehicle, t) << '\n'; + cout << "Braking distance [m]: " << calcBrakeDistance(vehicle) << '\n'; + } + cout << '\n'; + } + } + return 0; + +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/test/test_vehicle_brake_distance.cpp b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/test/test_vehicle_brake_distance.cpp new file mode 100644 index 00000000..86b7a2fd --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/medium/brakedistance_calc/test/test_vehicle_brake_distance.cpp @@ -0,0 +1,21 @@ +#include + +#include "../src/BrakeDistanceCalc.h" + +TEST(VehicleTestSuite, basicBrakeDistance) +{ + szechenyi_programming::Vehicle vehicle({szechenyi_programming::COEFFICIENT_FRICTION, 1200, 10, 1.0}); + ASSERT_NEAR(8.494733, szechenyi_programming::calcBrakeDistance(vehicle), 0.0001); +} + +TEST(VehicleTestSuite, basicAverageDistance) +{ + szechenyi_programming::Vehicle vehicle({szechenyi_programming::COEFFICIENT_FRICTION, 1200, 10, 1.0}); + ASSERT_DOUBLE_EQ(150, szechenyi_programming::calcDistance(vehicle, 10)); +} + +int main(int argc, char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/medium/simple_temp_monitor/.gitignore b/SZE/OODB/kyberszittya/Rec1/medium/simple_temp_monitor/.gitignore new file mode 100644 index 00000000..d1638636 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/medium/simple_temp_monitor/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/medium/simple_temp_monitor/CMakeLists.txt b/SZE/OODB/kyberszittya/Rec1/medium/simple_temp_monitor/CMakeLists.txt new file mode 100644 index 00000000..2ea869d7 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/medium/simple_temp_monitor/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.5) +project(SimpleTempMonitor) + +add_executable(SimpleTempMonitor src/main.cpp) \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/medium/simple_temp_monitor/src/main.cpp b/SZE/OODB/kyberszittya/Rec1/medium/simple_temp_monitor/src/main.cpp new file mode 100644 index 00000000..821f23ea --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/medium/simple_temp_monitor/src/main.cpp @@ -0,0 +1,61 @@ +#include +#include + +constexpr int CHAIN_LENGTH = 100; + +struct TemperatureChain +{ + double temp; + double humidity; + TemperatureChain* next; +}; + +bool temperatureComfortable(const TemperatureChain& temp) +{ + if (temp.temp < 15) + { + return false; + } + else if (temp.temp > 28) + { + return false; + } + return true; +} + +void initTemperatureElement(TemperatureChain& temperature) +{ + // Random number generation + static std::random_device rd; + static std::mt19937 gen(rd()); + static std::uniform_real_distribution dis_temp(10, 34); + static std::uniform_real_distribution dis_humidity(0.0, 1.0); + temperature.temp = dis_temp(gen); + temperature.humidity = dis_humidity(gen); +} + +int main(int argc, char** argv) +{ + TemperatureChain chain[CHAIN_LENGTH]; + // Construct temperature chain + for (int i = 0; i < CHAIN_LENGTH - 1; i++) + { + initTemperatureElement(chain[i]); + chain[i].next = &chain[i+1]; + } + initTemperatureElement(chain[CHAIN_LENGTH - 1]); + chain[CHAIN_LENGTH - 1].next = NULL; + // Check temperature chain + TemperatureChain* current_chain = &chain[0]; + while (current_chain->next != NULL) + { + std::cout << "Temperature: " << current_chain->temp << "\t" << current_chain->humidity << '\n'; + if (!temperatureComfortable(*current_chain)) + { + std::cerr << "Uncomfortable temperature reached" << '\n'; + break; + } + current_chain = current_chain->next; + } + return 0; +} \ No newline at end of file From 6ae158caa5cfc224476772701ec89c9cf4d51aec Mon Sep 17 00:00:00 2001 From: Hajdu Csaba Date: Mon, 16 Sep 2019 00:19:12 +0200 Subject: [PATCH 02/14] Compund interest --- .../Rec1/easy/comp_interest/.gitignore | 1 + .../Rec1/easy/comp_interest/CMakeLists.txt | 5 +++ .../easy/comp_interest/data/interests.dat | 4 +++ .../easy/comp_interest/src/comp_interest.h | 6 ++++ .../Rec1/easy/comp_interest/src/main.cpp | 20 +++++++++++ .../Rec1/easy/comp_interest/src/main_file.cpp | 33 +++++++++++++++++ .../triangle_area_calculator/CMakeLists.txt | 1 + .../data/triangles.dat | 5 +++ .../src/main_file.cpp | 35 +++++++++++++++++++ 9 files changed, 110 insertions(+) create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/comp_interest/.gitignore create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/comp_interest/CMakeLists.txt create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/comp_interest/data/interests.dat create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/comp_interest/src/comp_interest.h create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/comp_interest/src/main.cpp create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/comp_interest/src/main_file.cpp create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/data/triangles.dat create mode 100644 SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/main_file.cpp diff --git a/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/.gitignore b/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/.gitignore new file mode 100644 index 00000000..d1638636 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/CMakeLists.txt b/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/CMakeLists.txt new file mode 100644 index 00000000..2455fdb6 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.5) +project(CompoundInterest) + +add_executable(CompoundInterest src/main.cpp) +add_executable(CompoundInterestFile src/main_file.cpp) \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/data/interests.dat b/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/data/interests.dat new file mode 100644 index 00000000..e23aa4af --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/data/interests.dat @@ -0,0 +1,4 @@ +50 7.7 90 +666 8 1000 +700 5 1500 +40 10 230 \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/src/comp_interest.h b/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/src/comp_interest.h new file mode 100644 index 00000000..b374af69 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/src/comp_interest.h @@ -0,0 +1,6 @@ +#include + +const inline double yearsToTargetCash(const double& cash, const double& interest, const double& target_cash) +{ + return std::log(target_cash/cash)/std::log(1.0+interest); +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/src/main.cpp b/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/src/main.cpp new file mode 100644 index 00000000..029fdf7b --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/src/main.cpp @@ -0,0 +1,20 @@ +#include + +#include "comp_interest.h" + +using namespace std; + +int main(int argc, char** argv) +{ + double cash, interest, target_cash; + cout << "Starting cash [EUR]: "; + cin >> cash; + cout << "Compound interest [%]: "; + cin >> interest; + interest /= 100.0; + cout << "Desired cash [EUR]: "; + cin >> target_cash; + cout << "Years to get cash: " << ceil(yearsToTargetCash(cash, interest, target_cash)) << '\n'; + + return 0; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/src/main_file.cpp b/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/src/main_file.cpp new file mode 100644 index 00000000..37e55bc4 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/comp_interest/src/main_file.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +#include "comp_interest.h" + + +using namespace std; + + +int main(int argc, char** argv) +{ + ifstream file("../data/interests.dat"); + if (file.is_open()) + { + string line; + while(getline(file, line)) + { + stringstream ss(line); + double cash, interest, target_cash; + ss >> cash; + ss >> interest; + interest /= 100.0; + ss >> target_cash; + cout << "Starting cash [EUR]: " << cash << '\n'; + cout << "Compound interest [%]: " << interest << '\n'; + cout << "Desired cash [EUR]: " << target_cash << '\n'; + cout << "Years to get cash: " << ceil(yearsToTargetCash(cash, interest, target_cash)) << '\n'; + cout << '\n'; + } + } + return 0; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/CMakeLists.txt b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/CMakeLists.txt index 630410c2..0e564baa 100644 --- a/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/CMakeLists.txt +++ b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.5) project(TriangleCalc) add_executable(TriangleAreaCalc src/main.cpp src/triangle.cpp) +add_executable(TriangleAreaCalcFile src/main_file.cpp src/triangle.cpp) # If you want to test, then go ahead with it configure_file(./../../CMakeLists.txt.in googletest-download/CMakeLists.txt) diff --git a/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/data/triangles.dat b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/data/triangles.dat new file mode 100644 index 00000000..24be838d --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/data/triangles.dat @@ -0,0 +1,5 @@ +3 4 5 +15 16 19 +6 4 7 +5 6 2 +4 7 19 \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/main_file.cpp b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/main_file.cpp new file mode 100644 index 00000000..23a98df8 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec1/easy/triangle_area_calculator/src/main_file.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +#include "triangle.h" + +int main(int argc, char** argv) +{ + std::ifstream triangle_input_file(argv[1]); + if (triangle_input_file.is_open()) + { + std::string line; + while(getline(triangle_input_file, line)) + { + std::stringstream ss(line); + double a,b,c; + ss >> a; + ss >> b; + ss >> c; + std::cout << "Sides [cm]: " << a << '\t' << b << '\t' << c << '\n'; + Triangle triangle({a,b,c}); + if (validTriangle(triangle)) + { + std::cout << "Area [cm^2]: " << calcTriangleArea(triangle) << '\n'; + } + else + { + std::cerr << "Invalid triangle\n"; + } + } + } + + + return 0; +} \ No newline at end of file From f1b29e667bc26af0cdef61ff1342915dff6a74f0 Mon Sep 17 00:00:00 2001 From: kyberszittya Date: Sun, 29 Sep 2019 19:11:53 +0200 Subject: [PATCH 03/14] Recitation with a working labyrinth --- .../kyberszittya/Rec2/CubeVolume/Cube.cpp | 21 ++++ SZE/OODB/kyberszittya/Rec2/CubeVolume/Cube.h | 16 +++ .../Rec2/CubeVolume/CubeVolume.cpp | Bin 0 -> 956 bytes .../kyberszittya/Rec2/CubeVolume/Sphere.cpp | 10 ++ .../kyberszittya/Rec2/CubeVolume/Sphere.h | 13 +++ SZE/OODB/kyberszittya/Rec2/Labirintus/Fal.h | 6 ++ SZE/OODB/kyberszittya/Rec2/Labirintus/Hero.h | 29 ++++++ .../kyberszittya/Rec2/Labirintus/Labirintus.h | 28 +++++ .../kyberszittya/Rec2/Labirintus/Padloelem.h | 30 ++++++ .../kyberszittya/Rec2/Labirintus/common.cpp | 7 ++ .../kyberszittya/Rec2/Labirintus/common.h | 13 +++ .../kyberszittya/Rec2/Labirintus/hero.cpp | 47 +++++++++ .../Rec2/Labirintus/labirintus.cpp | 98 ++++++++++++++++++ .../kyberszittya/Rec2/Labirintus/main.cpp | Bin 0 -> 3248 bytes .../Rec2/Labirintus/padloelem.cpp | 48 +++++++++ 15 files changed, 366 insertions(+) create mode 100644 SZE/OODB/kyberszittya/Rec2/CubeVolume/Cube.cpp create mode 100644 SZE/OODB/kyberszittya/Rec2/CubeVolume/Cube.h create mode 100644 SZE/OODB/kyberszittya/Rec2/CubeVolume/CubeVolume.cpp create mode 100644 SZE/OODB/kyberszittya/Rec2/CubeVolume/Sphere.cpp create mode 100644 SZE/OODB/kyberszittya/Rec2/CubeVolume/Sphere.h create mode 100644 SZE/OODB/kyberszittya/Rec2/Labirintus/Fal.h create mode 100644 SZE/OODB/kyberszittya/Rec2/Labirintus/Hero.h create mode 100644 SZE/OODB/kyberszittya/Rec2/Labirintus/Labirintus.h create mode 100644 SZE/OODB/kyberszittya/Rec2/Labirintus/Padloelem.h create mode 100644 SZE/OODB/kyberszittya/Rec2/Labirintus/common.cpp create mode 100644 SZE/OODB/kyberszittya/Rec2/Labirintus/common.h create mode 100644 SZE/OODB/kyberszittya/Rec2/Labirintus/hero.cpp create mode 100644 SZE/OODB/kyberszittya/Rec2/Labirintus/labirintus.cpp create mode 100644 SZE/OODB/kyberszittya/Rec2/Labirintus/main.cpp create mode 100644 SZE/OODB/kyberszittya/Rec2/Labirintus/padloelem.cpp diff --git a/SZE/OODB/kyberszittya/Rec2/CubeVolume/Cube.cpp b/SZE/OODB/kyberszittya/Rec2/CubeVolume/Cube.cpp new file mode 100644 index 00000000..c16aebf1 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/CubeVolume/Cube.cpp @@ -0,0 +1,21 @@ +#include "Cube.h" + +bool Cube::validCube() const +{ + if (a > 0.0 && b > 0.0 && c > 0.0) + { + return true; + } + return false; +} + +double Cube::volume() const +{ + return a * b * c; +} + +Cube::Cube(const double a, const double b, const double c) : + a(a), b(b), c(c) +{ + +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec2/CubeVolume/Cube.h b/SZE/OODB/kyberszittya/Rec2/CubeVolume/Cube.h new file mode 100644 index 00000000..a12f21e0 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/CubeVolume/Cube.h @@ -0,0 +1,16 @@ +#pragma once + +// Kiszámítjuk a kocka térfogatát +class Cube +{ +private: + const double a, b, c; +public: + + Cube(const double a, const double b, const double c); + + // Számoljunk térfogatot! + double volume() const; + // Ellenőrizzük, jó-e a kocka + bool validCube() const; +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec2/CubeVolume/CubeVolume.cpp b/SZE/OODB/kyberszittya/Rec2/CubeVolume/CubeVolume.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5b51e5493362661a5427aaa474cca97c2603cdf0 GIT binary patch literal 956 zcma))Pfx-?5XI+O6Ticz9>ByD&q_!X&mKK_fu$hQ7E+3dA$(xZ-qqhs|HcqPHoKi| z-@JMAI=?>y8Hkgy>|`pjyvSM-;*>ZNFB_JVJN6TA=CYKG=azdRZ$yrr5$Ezrydhf= z1@W9X@8CT5j7;U%yoqrq;5~7{Q@=-YDHkXj*i+*xWAvtKW|>37ZmnueZYrY_=&duhmQ1ig4j?7?9%;&I!);f;vMx2w*`~NJDXR}OCu#C@UX*;UtM!PI0s4sg{+wI@U z0k=vo1KgW~=rN-bSYF%@;v>wo$TD&_tz-<+zdRoE&yUPswo TwQ_h0T+M9?ZYxEl9>x6uk&T7X literal 0 HcmV?d00001 diff --git a/SZE/OODB/kyberszittya/Rec2/CubeVolume/Sphere.cpp b/SZE/OODB/kyberszittya/Rec2/CubeVolume/Sphere.cpp new file mode 100644 index 00000000..dcf24de4 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/CubeVolume/Sphere.cpp @@ -0,0 +1,10 @@ +#include "Sphere.h" + +Sphere::Sphere(const double r) : r(r) {}; +const double Sphere::volume() { + return 4 / 3 * pi*r*r*r; +}; + +const bool Sphere::isValid() { + return r > 0 ? true : false; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec2/CubeVolume/Sphere.h b/SZE/OODB/kyberszittya/Rec2/CubeVolume/Sphere.h new file mode 100644 index 00000000..347ab302 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/CubeVolume/Sphere.h @@ -0,0 +1,13 @@ +#pragma once + +constexpr double pi = 3.14; + +class Sphere +{ +private: + double r; +public: + Sphere(const double r); + const double volume(); + const bool isValid(); +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec2/Labirintus/Fal.h b/SZE/OODB/kyberszittya/Rec2/Labirintus/Fal.h new file mode 100644 index 00000000..8023e746 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/Labirintus/Fal.h @@ -0,0 +1,6 @@ +#pragma once +class Fal +{ +private: +public: +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec2/Labirintus/Hero.h b/SZE/OODB/kyberszittya/Rec2/Labirintus/Hero.h new file mode 100644 index 00000000..5c87288b --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/Labirintus/Hero.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include "common.h" +#include "PadloElem.h" + + + +class Hero +{ +private: + const std::string name; + PadloElem* current_padloelem; +public: + Hero(const std::string name); + + ~Hero(); + + void setCurrentPadloelem(PadloElem* padloelem); + + bool move(const MovingDirection& mozgasirany); + + + void tamad(); + + friend std::ostream& operator<<(std::ostream& os, const Hero& hero); +}; + +std::ostream& operator<<(std::ostream& os, const Hero& hero); \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec2/Labirintus/Labirintus.h b/SZE/OODB/kyberszittya/Rec2/Labirintus/Labirintus.h new file mode 100644 index 00000000..99c31639 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/Labirintus/Labirintus.h @@ -0,0 +1,28 @@ +#pragma once + +#include "Hero.h" +#include "Padloelem.h" + +#include + +constexpr unsigned int LABIRINTUS_SIZE_X = 10; +constexpr unsigned int LABIRINTUS_SIZE_Y = 5; +constexpr unsigned int LABIRINTUS_PADLOELEMEK { LABIRINTUS_SIZE_X * LABIRINTUS_SIZE_Y }; + +class Labirintus +{ +private: + PadloElem elems[LABIRINTUS_PADLOELEMEK]; + Hero& hero; +public: + Labirintus(Hero& hero); + + void print() const; + + /** + Initialize neighbors of the labyrinth + */ + void initializeNeighbors(); + + void initHeroPosition(const unsigned int x, const unsigned int y); +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec2/Labirintus/Padloelem.h b/SZE/OODB/kyberszittya/Rec2/Labirintus/Padloelem.h new file mode 100644 index 00000000..0972e436 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/Labirintus/Padloelem.h @@ -0,0 +1,30 @@ +#pragma once + +#include "common.h" + +class PadloElem +{ +private: + Coordinate coord; + bool foglalt; + + PadloElem* neighbors[4]; +public: + PadloElem(unsigned int x, unsigned int y); + + PadloElem(); + + PadloElem* getNeighborElem(const MovingDirection& dir) const; + + void setCoordinate(unsigned int x, unsigned int y); + + void setNeighborElem(const MovingDirection& dir, PadloElem* p); + + void setFoglalt(); + + void setFree(); + + bool isFoglalt() const; + + Coordinate getCoord() const; +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec2/Labirintus/common.cpp b/SZE/OODB/kyberszittya/Rec2/Labirintus/common.cpp new file mode 100644 index 00000000..c6195949 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/Labirintus/common.cpp @@ -0,0 +1,7 @@ +#include "common.h" + +std::ostream& operator<<(std::ostream& file, const Coordinate& coord) +{ + file << '(' << coord.x << ',' << coord.y << ')'; + return file; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec2/Labirintus/common.h b/SZE/OODB/kyberszittya/Rec2/Labirintus/common.h new file mode 100644 index 00000000..481024ea --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/Labirintus/common.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +enum MovingDirection { ESZAK, KELET, NYUGAT, DEL }; + +struct Coordinate +{ + unsigned int x; + unsigned int y; +}; + +std::ostream& operator<<(std::ostream& file, const Coordinate& coord); \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec2/Labirintus/hero.cpp b/SZE/OODB/kyberszittya/Rec2/Labirintus/hero.cpp new file mode 100644 index 00000000..59802251 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/Labirintus/hero.cpp @@ -0,0 +1,47 @@ +#include "Hero.h" + +Hero::Hero(const std::string name) + : + name(name), + current_padloelem(NULL) +{} + +Hero::~Hero() +{ + current_padloelem = NULL; +} + +void Hero::setCurrentPadloelem(PadloElem* padloelem) +{ + current_padloelem = padloelem; +} + +bool Hero::move(const MovingDirection& mozgasirany) +{ + + PadloElem* p = current_padloelem->getNeighborElem(mozgasirany); + if (p != NULL) + { + current_padloelem->setFree(); + setCurrentPadloelem(current_padloelem->getNeighborElem(mozgasirany)); + current_padloelem->setFoglalt(); + return true; + } + else + { + return false; + } + + +} + +void Hero::tamad() +{ + +} + +std::ostream& operator<<(std::ostream& os, const Hero& hero) +{ + //os << hero.name << hero.current_padloelem->getCoord(); + return os; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec2/Labirintus/labirintus.cpp b/SZE/OODB/kyberszittya/Rec2/Labirintus/labirintus.cpp new file mode 100644 index 00000000..58630c84 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/Labirintus/labirintus.cpp @@ -0,0 +1,98 @@ +#include "Labirintus.h" + +Labirintus::Labirintus(Hero& hero) : hero(hero) +{ + +} + +void Labirintus::print() const +{ + for (unsigned int x = 0; x < LABIRINTUS_SIZE_X; x++) + { + std::cout << "-"; + } + std::cout << "\n"; + for (unsigned int y = 0; y < LABIRINTUS_SIZE_Y; y++) + { + for (unsigned int x = 0; x < LABIRINTUS_SIZE_X; x++) + { + if (elems[y * LABIRINTUS_SIZE_X + x].isFoglalt()) + { + std::cout << "O"; + } + else + { + std::cout << " "; + } + } + std::cout << '\n'; + } + for (unsigned int x = 0; x < LABIRINTUS_SIZE_X; x++) + { + std::cout << "-"; + } + std::cout << "\n"; +} + +void Labirintus::initializeNeighbors() +{ + // Y coord + for (unsigned int y = 0; y < LABIRINTUS_SIZE_Y; y++) + { + // X coord + for (unsigned int x = 0; x < LABIRINTUS_SIZE_X; x++) + { + elems[y * LABIRINTUS_SIZE_X + x].setCoordinate(x, y); + // Left boundary + if (x == 0) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(KELET, &elems[y * LABIRINTUS_SIZE_X + x + 1]); // Point to east + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(DEL, &elems[(y + 1) * LABIRINTUS_SIZE_X + x]); // Point to south + // Not in left-upper corner + if (y > 0) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(ESZAK, &elems[(y - 1) * LABIRINTUS_SIZE_X + x]); // Point to north + } + } + // Right boundary + else if (x == LABIRINTUS_SIZE_X - 1) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(NYUGAT, &elems[y * LABIRINTUS_SIZE_X + x - 1]); // Point to west + if (y < LABIRINTUS_SIZE_Y - 1) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(DEL, &elems[(y + 1) * LABIRINTUS_SIZE_X + x]); // Point to south + } + // Not in right-upper corner + if (y > 0) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(ESZAK, &elems[(y - 1) * LABIRINTUS_SIZE_X + x]); // Point to north + } + } + else if (y == 0) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(KELET, &elems[y * LABIRINTUS_SIZE_X + x + 1]); // Point to east + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(NYUGAT, &elems[y * LABIRINTUS_SIZE_X + x - 1]); // Point to west + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(DEL, &elems[(y + 1) * LABIRINTUS_SIZE_X + x]); // Point to south + } + else if (y == LABIRINTUS_SIZE_Y - 1) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(KELET, &elems[y * LABIRINTUS_SIZE_X + x + 1]); // Point to east + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(NYUGAT, &elems[y * LABIRINTUS_SIZE_X + x - 1]); // Point to west + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(ESZAK, &elems[(y - 1) * LABIRINTUS_SIZE_X + x]); // Point to north + } + else + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(KELET, &elems[y * LABIRINTUS_SIZE_X + x + 1]); + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(NYUGAT, &elems[y * LABIRINTUS_SIZE_X + x - 1]); + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(ESZAK, &elems[(y - 1) * LABIRINTUS_SIZE_X + x]); + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(DEL, &elems[(y + 1) * LABIRINTUS_SIZE_X + x]); + } + } + } +} + +void Labirintus::initHeroPosition(const unsigned int x, const unsigned int y) +{ + elems[y * LABIRINTUS_SIZE_X + x].setFoglalt(); + hero.setCurrentPadloelem(&elems[y * LABIRINTUS_SIZE_X + x]); +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec2/Labirintus/main.cpp b/SZE/OODB/kyberszittya/Rec2/Labirintus/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..162c9f430c72b2d2b172cd2fec5d86b9e463e505 GIT binary patch literal 3248 zcmb`JYflqF6o${&HSs@;C6St#Li8IV2}1G4#h}J$Oh|7?BeYGqDd=BUpLeFy*|xh7 zOtabUcIRB)b3cFoEZLGd+qQ-^t!qQ>o}Jmbom$OWHsEr$!o6u7JM^a=&KxvHd~w{O zAKFje2i70)J81iSO>`~(_u%Z?vFB@e*~ieg(0#^J=QX=;_dvAdpL$>L5?gScTibK4 zdfHR3wFB>ot$FGq%0MNXzKy7gWmfDJvWH-(VOOO@Ud7&_uML(y)UxB`7W!hp-lRc( zI^hc5h?Eiaq4&Wdem$^H_S$yssXZB?m3LxyVx%_9*g>ucu(?+XZim$_DSUx8ZrJ zUhwp9Bq5#R9?C%S$Mtt@-$Ov960GW!n|Fce%S* zapW^*2sT*~WMzdqlbmSdJFGiJO6)0BD&#R1J{e02b`@t=%z&sfpR1clRTj0zvYpTK z;e@r9pznfJ-LVSgkQjDG@yP6Yl&xjf44@A^IB$98Gp|i0toV#pRybSbN)e6!7wsz* zusHVGO}v#+eZ=}xr>~T73YDW9tnnM_FZw70v3gRK=WW#;>NaF&Ms_8CBq>39Q4JQ? zZjv@BFB?TiRqiIb&TJ&**|%0F+v{}AWLajR&V)51j>lN2$VQ9Hu@?7>d12kP&-RfD zUY`@%vMx0*ymfnTUqJhIF1{`6jPpXf=`*1$3u5dajQd@UuB(}*&a25cq~6Q1q|T%1 zl&|FqGrfnL&=J+qgS33lsqi&a{%ob^vo+=IU9wi#8fNRxGytcdO=-3Z@ z6ejSrLI+T9Om`tRr>}@bvtwk<4IYHZe^D z4(*ubJ6PtoF3tK)qN=T92kpuX?Z?}^%c9Adraes@?>QBpcBw5t>ArzydW%cjn>M;S z_W?XxWQ2B?X=?Q{Rh+)R;(f!vi$2ZNN&Wkv&=xO5nta+R6N&?5>~rmLYobo;+u=l& gBTRMnPW7j#X#q)bD|CLtpWR`ncev$I^i#zC0eGO&C;$Ke literal 0 HcmV?d00001 diff --git a/SZE/OODB/kyberszittya/Rec2/Labirintus/padloelem.cpp b/SZE/OODB/kyberszittya/Rec2/Labirintus/padloelem.cpp new file mode 100644 index 00000000..f47ee161 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec2/Labirintus/padloelem.cpp @@ -0,0 +1,48 @@ +#include "Padloelem.h" + +PadloElem::PadloElem() : PadloElem(0, 0) +{} + +PadloElem::PadloElem(unsigned int x, unsigned int y) : coord({ x, y }), foglalt(false) +{ + neighbors[MovingDirection::ESZAK] = NULL; + neighbors[MovingDirection::KELET] = NULL; + neighbors[MovingDirection::NYUGAT] = NULL; + neighbors[MovingDirection::DEL] = NULL; +} + +PadloElem* PadloElem::getNeighborElem(const MovingDirection& dir) const +{ + return neighbors[dir]; +} + +void PadloElem::setCoordinate(unsigned int x, unsigned int y) +{ + coord.x = x; + coord.y = y; +} + +void PadloElem::setNeighborElem(const MovingDirection& dir, PadloElem* p) +{ + neighbors[dir] = p; +} + +void PadloElem::setFoglalt() +{ + foglalt = true; +} + +void PadloElem::setFree() +{ + foglalt = false; +} + +bool PadloElem::isFoglalt() const +{ + return foglalt; +} + +Coordinate PadloElem::getCoord() const +{ + return coord; +} \ No newline at end of file From 6c64b3b9a41d08b671452a91c5afa878f86a5037 Mon Sep 17 00:00:00 2001 From: Hajdu Csaba Date: Thu, 3 Oct 2019 17:49:09 +0200 Subject: [PATCH 04/14] Recitation 3 uploaded Recitation 3 uploaded --- .../BookOperatorOverloading.cpp | Bin 0 -> 2618 bytes .../Rec3/Recitation3/Labirintus/Fal.h | 9 + .../Rec3/Recitation3/Labirintus/Hero.h | 24 +++ .../Rec3/Recitation3/Labirintus/Labirintus.h | 35 ++++ .../Rec3/Recitation3/Labirintus/Padloelem.h | 31 ++++ .../Rec3/Recitation3/Labirintus/Szorny.h | 19 +++ .../Rec3/Recitation3/Labirintus/Unit.h | 34 ++++ .../Rec3/Recitation3/Labirintus/common.cpp | 7 + .../Rec3/Recitation3/Labirintus/common.h | 15 ++ .../Rec3/Recitation3/Labirintus/hero.cpp | 24 +++ .../Recitation3/Labirintus/labirintus.cpp | 115 +++++++++++++ .../Rec3/Recitation3/Labirintus/main.cpp | Bin 0 -> 3718 bytes .../Rec3/Recitation3/Labirintus/padloelem.cpp | 44 +++++ .../Rec3/Recitation3/Labirintus/unit.cpp | 23 +++ .../Recitation3/LinkedList/LinkedList.cpp | 25 +++ .../Rec3/Recitation3/LinkedList/LinkedList.h | 116 +++++++++++++ .../SphereCalculation/SphereCalculation.cpp | Bin 0 -> 2652 bytes .../SphereCalculation.vcxproj | 156 ++++++++++++++++++ 18 files changed, 677 insertions(+) create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/BookOperatorOverloading/BookOperatorOverloading.cpp create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Fal.h create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Hero.h create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Labirintus.h create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Padloelem.h create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Szorny.h create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Unit.h create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/common.cpp create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/common.h create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/hero.cpp create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/labirintus.cpp create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/main.cpp create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/padloelem.cpp create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/unit.cpp create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.cpp create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.h create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/SphereCalculation/SphereCalculation.cpp create mode 100644 SZE/OODB/kyberszittya/Rec3/Recitation3/SphereCalculation/SphereCalculation.vcxproj diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/BookOperatorOverloading/BookOperatorOverloading.cpp b/SZE/OODB/kyberszittya/Rec3/Recitation3/BookOperatorOverloading/BookOperatorOverloading.cpp new file mode 100644 index 0000000000000000000000000000000000000000..54f7388120333cbdbd16be5dbde8c189532528e0 GIT binary patch literal 2618 zcmbtWYm3uR5S_0T{0||5ONzvL$!*fu z7Aa}(&AiT>nYp)r9!}*{0(mJJKG*V5Rx*{fBvN3%#{P%y7uY2-kyMs4m%falw}Ra{ zo>$PAsbnfS_Jw@In*h%e>$UvGdIfvh7Ff^JbEP-NehJG=7HXHM?*;V7iX&BdUmnXN zU_I4euAivKF|2NZj1h-;lfe_CPGNf^FI0P%rfFF|?OL-P-WZ!v6Udmaa=_>lNX|F@4MzYTh3wst1>vyHTyT<*OMpLcSvE2~Ib z73N^AkPn+$L_%~`reVOJGK=6NvmH2Ro> zW?fAuM2xW2qFEWU>cXnqYE|diF}B?=L~4?%Vs0Lre4T);b|waUn2KvGRdGgg2G1iI z;B0TQ#M$#@bw29ydgg(gsE4@pUf1ZAC)YMR#8qdp}faL=Rld` z^i9=&fbY-nX>YC}`-vxz*N}fNbz=4Z?+C0{2z++ezJbqMa4~_m0)BYY7}`+YDux7o z6UYVDDQ=hyx0B0;x%jcF`DLf^ZmCa_+jr#);&jW}?YE3eU&q^?{f8~%S`S)B9O8?8 z!i?O13I1~#DC;Be!ZRmFpA_;7Pv~_+s{IwIb{}l#@)g=V_pDc|yU1>mj%qqioo~0V X^R!#Lo!8y^?fKg&RKL{*jVb&K57dUj literal 0 HcmV?d00001 diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Fal.h b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Fal.h new file mode 100644 index 00000000..a99a176c --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Fal.h @@ -0,0 +1,9 @@ +#pragma once + +#include "Padloelem.h" + +class Fal: public PadloElem +{ +private: +public: +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Hero.h b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Hero.h new file mode 100644 index 00000000..47fbb851 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Hero.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include "common.h" +#include "Unit.h" + + + + +class Hero: public Unit +{ +private: + const std::string name; +public: + Hero(const std::string name, unsigned int health, unsigned int attack, unsigned int damage, unsigned int defense); + + ~Hero(); + + + + friend std::ostream& operator<<(std::ostream& os, const Hero& hero); +}; + +std::ostream& operator<<(std::ostream& os, const Hero& hero); \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Labirintus.h b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Labirintus.h new file mode 100644 index 00000000..ef464bb8 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Labirintus.h @@ -0,0 +1,35 @@ +#pragma once + +#include "Hero.h" +#include "Padloelem.h" +#include "Szorny.h" +#include + +constexpr unsigned int LABIRINTUS_SIZE_X = 10; +constexpr unsigned int LABIRINTUS_SIZE_Y = 5; +constexpr unsigned int LABIRINTUS_PADLOELEMEK { LABIRINTUS_SIZE_X * LABIRINTUS_SIZE_Y }; + +class Labirintus +{ +private: + const int max_monster_cnt; + Monster* monsters; + PadloElem elems[LABIRINTUS_PADLOELEMEK]; + Hero& hero; +public: + Labirintus(Hero& hero); + Labirintus(Hero& hero, const int monster_cnt); + ~Labirintus(); + + void print() const; + + /** + Initialize neighbors of the labyrinth + */ + void initializeNeighbors(); + + void initHeroPosition(const unsigned int x, const unsigned int y); + + void initMonsterPosition(const int monster_id, + const unsigned int x, const unsigned int y); +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Padloelem.h b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Padloelem.h new file mode 100644 index 00000000..a973dcb9 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Padloelem.h @@ -0,0 +1,31 @@ +#pragma once + +#include "common.h" +#include "Unit.h" + +class PadloElem +{ +private: + Coordinate coord; + Unit* occupyingunit; + + PadloElem* neighbors[4]; +protected: + +public: + PadloElem(unsigned int x, unsigned int y); + + PadloElem(); + + PadloElem* getNeighborElem(const MovingDirection& dir) const; + + void setCoordinate(unsigned int x, unsigned int y); + + void setNeighborElem(const MovingDirection& dir, PadloElem* p); + + void setOccupyingUnit(Unit* unit); + + bool isFoglalt() const; + + Coordinate getCoord() const; +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Szorny.h b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Szorny.h new file mode 100644 index 00000000..d82e115e --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Szorny.h @@ -0,0 +1,19 @@ +#pragma once + +#include "Unit.h" + +class Monster : public Unit +{ +private: +public: + Monster() : Unit({100, 10, 12, 5}) + {} + + void damage(unsigned int attack, unsigned int damage) + { + unitstat.health -= ((double)(unitstat.defense) / (double)(unitstat.attack)) * damage; + } + + + +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Unit.h b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Unit.h new file mode 100644 index 00000000..2297b110 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/Unit.h @@ -0,0 +1,34 @@ +#pragma once + +#include "common.h" + +class PadloElem; + +struct UnitStat +{ + unsigned int health; + unsigned int attack; + unsigned int damage; + unsigned int defense; +}; + +class Unit +{ +protected: + UnitStat unitstat; + PadloElem* current_padloelem; +public: + Unit(unsigned int health, unsigned int attack, unsigned int damage, unsigned int defense): + unitstat({health, attack, damage, defense}), + current_padloelem(NULL) + {} + + bool isDead() + { + return unitstat.health == 0; + } + + bool move(MovingDirection movedir); + + void setCurrentPadloelem(PadloElem* padloelem); +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/common.cpp b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/common.cpp new file mode 100644 index 00000000..c6195949 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/common.cpp @@ -0,0 +1,7 @@ +#include "common.h" + +std::ostream& operator<<(std::ostream& file, const Coordinate& coord) +{ + file << '(' << coord.x << ',' << coord.y << ')'; + return file; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/common.h b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/common.h new file mode 100644 index 00000000..e1a99ae6 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/common.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +enum MovingDirection { ESZAK, KELET, NYUGAT, DEL }; +enum UnitType {MONSTER, HERO, WALL}; + +struct Coordinate +{ + unsigned int x; + unsigned int y; +}; + +std::ostream& operator<<(std::ostream& file, const Coordinate& coord); + diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/hero.cpp b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/hero.cpp new file mode 100644 index 00000000..c5707a52 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/hero.cpp @@ -0,0 +1,24 @@ +#include "Hero.h" +#include "Padloelem.h" + +Hero::Hero(const std::string name, unsigned int health, unsigned int attack, unsigned int damage, unsigned int defense) + : + Unit(health, attack, damage, defense), + name(name) +{} + +Hero::~Hero() +{ + current_padloelem = NULL; +} + + + + + + +std::ostream& operator<<(std::ostream& os, const Hero& hero) +{ + os << hero.name << hero.current_padloelem->getCoord(); + return os; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/labirintus.cpp b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/labirintus.cpp new file mode 100644 index 00000000..d4f560b5 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/labirintus.cpp @@ -0,0 +1,115 @@ +#include "Labirintus.h" + +Labirintus::Labirintus(Hero& hero) : Labirintus(hero, 0) +{ + +} + +Labirintus::Labirintus(Hero& hero, const int monster_cnt) : + max_monster_cnt(monster_cnt), hero(hero) +{ + monsters = new Monster[monster_cnt]; +} + +Labirintus::~Labirintus() +{ + delete[] monsters; +} + +void Labirintus::print() const +{ + for (unsigned int x = 0; x < LABIRINTUS_SIZE_X; x++) + { + std::cout << "-"; + } + std::cout << "\n"; + for (unsigned int y = 0; y < LABIRINTUS_SIZE_Y; y++) + { + for (unsigned int x = 0; x < LABIRINTUS_SIZE_X; x++) + { + if (elems[y * LABIRINTUS_SIZE_X + x].isFoglalt()) + { + std::cout << "O"; + } + else + { + std::cout << " "; + } + } + std::cout << '\n'; + } + for (unsigned int x = 0; x < LABIRINTUS_SIZE_X; x++) + { + std::cout << "-"; + } + std::cout << "\n"; +} + +void Labirintus::initializeNeighbors() +{ + // Y coord + for (unsigned int y = 0; y < LABIRINTUS_SIZE_Y; y++) + { + // X coord + for (unsigned int x = 0; x < LABIRINTUS_SIZE_X; x++) + { + elems[y * LABIRINTUS_SIZE_X + x].setCoordinate(x, y); + // Left boundary + if (x == 0) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(KELET, &elems[y * LABIRINTUS_SIZE_X + x + 1]); // Point to east + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(DEL, &elems[(y + 1) * LABIRINTUS_SIZE_X + x]); // Point to south + // Not in left-upper corner + if (y > 0) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(ESZAK, &elems[(y - 1) * LABIRINTUS_SIZE_X + x]); // Point to north + } + } + // Right boundary + else if (x == LABIRINTUS_SIZE_X - 1) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(NYUGAT, &elems[y * LABIRINTUS_SIZE_X + x - 1]); // Point to west + if (y < LABIRINTUS_SIZE_Y - 1) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(DEL, &elems[(y + 1) * LABIRINTUS_SIZE_X + x]); // Point to south + } + // Not in right-upper corner + if (y > 0) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(ESZAK, &elems[(y - 1) * LABIRINTUS_SIZE_X + x]); // Point to north + } + } + else if (y == 0) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(KELET, &elems[y * LABIRINTUS_SIZE_X + x + 1]); // Point to east + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(NYUGAT, &elems[y * LABIRINTUS_SIZE_X + x - 1]); // Point to west + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(DEL, &elems[(y + 1) * LABIRINTUS_SIZE_X + x]); // Point to south + } + else if (y == LABIRINTUS_SIZE_Y - 1) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(KELET, &elems[y * LABIRINTUS_SIZE_X + x + 1]); // Point to east + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(NYUGAT, &elems[y * LABIRINTUS_SIZE_X + x - 1]); // Point to west + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(ESZAK, &elems[(y - 1) * LABIRINTUS_SIZE_X + x]); // Point to north + } + else + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(KELET, &elems[y * LABIRINTUS_SIZE_X + x + 1]); + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(NYUGAT, &elems[y * LABIRINTUS_SIZE_X + x - 1]); + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(ESZAK, &elems[(y - 1) * LABIRINTUS_SIZE_X + x]); + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(DEL, &elems[(y + 1) * LABIRINTUS_SIZE_X + x]); + } + } + } +} + +void Labirintus::initHeroPosition(const unsigned int x, const unsigned int y) +{ + elems[y * LABIRINTUS_SIZE_X + x].setOccupyingUnit(&hero); + hero.setCurrentPadloelem(&elems[y * LABIRINTUS_SIZE_X + x]); +} + +void Labirintus::initMonsterPosition(const int monster_id, const unsigned int x, const unsigned int y) +{ + elems[y * LABIRINTUS_SIZE_X + x].setOccupyingUnit(&hero); + monsters[monster_id].setCurrentPadloelem(&elems[y * LABIRINTUS_SIZE_X + x]); +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/main.cpp b/SZE/OODB/kyberszittya/Rec3/Recitation3/Labirintus/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9950af791c8b0f0551dee85273785b1e0b090b32 GIT binary patch literal 3718 zcmb_fX-^YT6un=^#Q*RZ5-Eu(yGBG3qy>~UpfMVgrYkf;+jId1{p;#E_s#2@X=gyp zWHRf!%em{j^XK=1EQpZNy#CFtwWJ;a^sMR_VufM`MQe4bT_b#RTOp`05^ zJ5a4n@LtKLQm0W`D%x}&QKicaWe>9Zz)*x;VTQa=PN1&=EL~93j;jag)BSp%2Kwm= zhxLY|bf{bEgBJW+kx%kYj$}oaBee96ixAhh*Uoa8jV8*u&)Uk3>2C&uz|8d)u)6wcRb@vpIWuR+&_KMefIdZ3+2-?;2HTD8n` zdSVw`J=k;$&iCN_hO>t6&+)zlpDadCE75&zyfQBq17jPcb`OJSPxq9z0I&|)hqNY(7+IA5H=3j;`Ty{CXmBC6$omc%?} zPa6VFAJsJ}&-%}LZzVUWON#P^Uh|V`ZMU+Qa>HtEf2mkkbCbHN@?PoHW3{=+Xf)6< zl0C!Kwabur2Pz>4*c2;1yOX^yG>#*nT{m$U|-7UP-X0e-m*Y!_YBaz z0>tqW7BaHV;%uzxyFgx8kL0s_L|@*@32oNilNa8yoXHoU-Ot6hS^HgHXiJ(2Sy|v> zKQrE=ir7mzsc=8#Jkv+LXJhf5XR?+b3%Nzl|NnS@oe>Z`Q z^))ZY_F042Re`6YlL2K~8-v7*WO4A%A$zh8be84>S3-y8EO`j+%nbhZ9N?K2B_|M0 z-{d&MD)~4e@911|4m^{yxu3~7rNb?+w`BwgetNeighborElem(movedir); + if (p != NULL) + { + current_padloelem->setOccupyingUnit(NULL); + setCurrentPadloelem(current_padloelem->getNeighborElem(movedir)); + return true; + } + else + { + return false; + } +} + +void Unit::setCurrentPadloelem(PadloElem* padloelem) +{ + current_padloelem = padloelem; + current_padloelem->setOccupyingUnit(this); +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.cpp b/SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.cpp new file mode 100644 index 00000000..322472f5 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.cpp @@ -0,0 +1,25 @@ +// LinkedList.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include + +#define _CRTDBG_MAP_ALLOC +#include +#include + +#include "LinkedList.h" + +void linkedlisttest() +{ + Robot robot; + robot.addPositionMeasurement(10, 10, 10); + robot.addPositionMeasurement(10, 10, 15); + robot.addPositionMeasurement(10, 7, 6); + robot.stationaryMeasurment(); +} + +int main() +{ + linkedlisttest(); + _CrtDumpMemoryLeaks(); +} diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.h b/SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.h new file mode 100644 index 00000000..7195a13d --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.h @@ -0,0 +1,116 @@ +#pragma once + +#include + +class Position +{ +private: + double x; + double y; + double z; +public: + Position(double x, double y, double z): x(x), y(y), z(z) + {} + Position(const Position& other) + { + x = other.x; + y = other.y; + z = other.z; + } + + friend std::ostream& operator<<(std::ostream& os, const Position& pos); +}; + +std::ostream& operator<<(std::ostream& os, const Position& pos) +{ + os << '(' << pos.x << ',' << pos.y << ',' << pos.z << ')'; + return os; +} + +struct LinkedListElement +{ + Position element; + LinkedListElement* next_element; + LinkedListElement* prev_element; + +}; + +class LinkedList +{ +private: + LinkedListElement* first_elem; + LinkedListElement* last_elem; +public: + LinkedList(): first_elem(NULL), last_elem(NULL) + {} + + ~LinkedList() + { + LinkedListElement* current_element = first_elem; + while (current_element != NULL) + { + LinkedListElement* tmp = current_element; + current_element = current_element->next_element; + delete tmp; + } + } + + void addElement(Position& position) + { + if (first_elem == NULL) + { + first_elem = new LinkedListElement({ position, NULL, NULL }); + last_elem = first_elem; + } + else + { + last_elem->next_element = new LinkedListElement({ position, last_elem, NULL }); + last_elem = last_elem->next_element; + } + } + + Position& last() + { + return last_elem->element; + } + + Position& first() + { + return first_elem->element; + } +}; + +LinkedList& operator+(LinkedList& list, Position& elem) +{ + list.addElement(elem); + return list; +} + +class Robot +{ +private: + LinkedList* measurements; +public: + Robot() + { + measurements = new LinkedList(); + } + + ~Robot() + { + delete measurements; + } + + void addPositionMeasurement(double x, double y, double z) + { + Position p(x, y, z); + measurements->addElement(p); + } + + void stationaryMeasurment() + { + Position p0(measurements->last()); + measurements->addElement(p0); + } +}; + diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/SphereCalculation/SphereCalculation.cpp b/SZE/OODB/kyberszittya/Rec3/Recitation3/SphereCalculation/SphereCalculation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce08263060c4a6566ec498bb1fbd514a3e9fc4e5 GIT binary patch literal 2652 zcmb7G+iuf95S>>e@efujp-`cwDdMFRq!71&NC2fpJd`R*oTQD&O}Qad%BKV8%zEox zU!ow(_S!p_GiPRJ_wS#oR3(%PnaiyVWP!UOT^UO(YdpKMl99}0Du?(p#}?g(;2 z%uMlK;(MjqA-<*;{_mKG2*1E2Cnqo#F~*581dxPTClc@P8%Wz~EjI zW3UCEtxei;kw3xr40g;q`9CbQIoDOO#M`d4Vq}3Ab11JozlYwe$(SF_Zx1!IWplC% zYtas@-6t&4URf135HZ(&7wof3EEL7Ix^%e?=o`Sxkd~{JO=0krY9Az9T$6? z%Ov~1SzATe-RjstcZB}J9bh9Cuc?B-tJ8x7sjXlZWb&M|Gj}+_FRyj2Y5y}!`*?ebJWQ% z+*#=+B5}p`N_*r=k!xdGWlp0)q=^gjgent2Af-0N^f=L;wH) literal 0 HcmV?d00001 diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/SphereCalculation/SphereCalculation.vcxproj b/SZE/OODB/kyberszittya/Rec3/Recitation3/SphereCalculation/SphereCalculation.vcxproj new file mode 100644 index 00000000..223551b0 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/SphereCalculation/SphereCalculation.vcxproj @@ -0,0 +1,156 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {C8F343F9-710F-476D-84E3-2700BCC7B37D} + Win32Proj + SphereCalculation + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + + Console + true + + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file From 5782b4552087cf1b133438a0ff50b785fc11cfce Mon Sep 17 00:00:00 2001 From: kyberszittya Date: Mon, 7 Oct 2019 01:59:34 +0200 Subject: [PATCH 05/14] =?UTF-8?q?Little=20ben=C3=A9z=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.h b/SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.h index 7195a13d..e5d25ff3 100644 --- a/SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.h +++ b/SZE/OODB/kyberszittya/Rec3/Recitation3/LinkedList/LinkedList.h @@ -30,9 +30,8 @@ std::ostream& operator<<(std::ostream& os, const Position& pos) struct LinkedListElement { Position element; - LinkedListElement* next_element; LinkedListElement* prev_element; - + LinkedListElement* next_element; }; class LinkedList From 74742a91d18be7abfd6350d25c92b9bacc8d2e77 Mon Sep 17 00:00:00 2001 From: Hajdu Csaba Date: Mon, 7 Oct 2019 13:30:34 +0200 Subject: [PATCH 06/14] Recitation 4 examples added Recitation 4 --- .../Rec4/Recitation4/Aquarium/Aquarium.cpp | Bin 0 -> 3044 bytes .../Recitation4/Aquarium/Aquarium.vcxproj | 159 ++++++++++++++++ .../InheritanceExample/InheritanceExample.cpp | 141 +++++++++++++++ .../InheritanceExample.vcxproj | 159 ++++++++++++++++ .../Rec4/Recitation4/Labirintus/Fal.h | 13 ++ .../Rec4/Recitation4/Labirintus/Hero.h | 23 +++ .../Rec4/Recitation4/Labirintus/Labirintus.h | 43 +++++ .../Recitation4/Labirintus/Labirintus.vcxproj | 171 ++++++++++++++++++ .../Rec4/Recitation4/Labirintus/Padloelem.h | 36 ++++ .../Rec4/Recitation4/Labirintus/Szorny.h | 12 ++ .../Rec4/Recitation4/Labirintus/Unit.h | 48 +++++ .../Rec4/Recitation4/Labirintus/common.cpp | 7 + .../Rec4/Recitation4/Labirintus/common.h | 15 ++ .../Rec4/Recitation4/Labirintus/hero.cpp | 25 +++ .../Recitation4/Labirintus/labirintus.cpp | 153 ++++++++++++++++ .../Rec4/Recitation4/Labirintus/main.cpp | Bin 0 -> 4156 bytes .../Rec4/Recitation4/Labirintus/padloelem.cpp | 44 +++++ .../Rec4/Recitation4/Labirintus/szorny.cpp | 6 + .../Rec4/Recitation4/Labirintus/unit.cpp | 66 +++++++ .../LinkedListTemplate/LinkedList.cpp | 26 +++ .../LinkedListTemplate/LinkedList.h | 135 ++++++++++++++ .../Rec4/Recitation4/Recitation4.sln | 81 +++++++++ .../TemplateVeryEasy/TemplateVeryEasy.cpp | Bin 0 -> 3734 bytes .../VectorExample/VectorExample.cpp | Bin 0 -> 1866 bytes .../VectorExample/VectorExample.vcxproj | 158 ++++++++++++++++ 25 files changed, 1521 insertions(+) create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Aquarium/Aquarium.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Aquarium/Aquarium.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceExample/InheritanceExample.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceExample/InheritanceExample.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Fal.h create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Hero.h create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Labirintus.h create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Labirintus.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Padloelem.h create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Szorny.h create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Unit.h create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/common.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/common.h create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/hero.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/labirintus.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/main.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/padloelem.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/szorny.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/unit.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/LinkedListTemplate/LinkedList.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/LinkedListTemplate/LinkedList.h create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/Recitation4.sln create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/TemplateVeryEasy/TemplateVeryEasy.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/VectorExample/VectorExample.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/VectorExample/VectorExample.vcxproj diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Aquarium/Aquarium.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/Aquarium/Aquarium.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2bdc0f60ec583af58954eda56259d3bb2a1b7cae GIT binary patch literal 3044 zcmcImO>fgc5S^=$_zzZ*s7p~24qQq>LVTRKafAvP*P(_a4t5egs`mf!GdS`GI0EnO zdc14LO`J$5O1#eQ%zHEQc6R^%8Ol&Xc`Bb}DX|oi;W?FoBr?Y*loNcPODbc`%2pg|{xj`wW)3OpIM@d{3}G0pwzC||{{g7i&@eeR! z+~jxyWb$LKPw@%mKwil&ycdY#qx{B*b1}Xb_?=*0S02h+S(WZ0l+n8MW+E{b%wM`C`2%YdY8# zsn)*9YCrT8`1|SLf7IQtx7`g%m8WevxvBc?KIzw)y|dY0+%6C09%{oL%C5vNs{4;! zm3uXTjtaAX`Th>?_St3Q_Cg4c)}B4;>qa|YsaA=$#_gD*+GiIB?QcG>2pm%R;_3fQ zC;v03{XSM%+@M#?k=YBh+7w~biP!957S;A&J9gcMSu7C)dy(thI=TyVjkoEOT{**C zh%VKqg6zVNx5T0de&-Krd}@c;-L951;1ElhtK!JHkNvS6*DBR>g0|e_%#~Kr_BqZp zPbg-Sw*Wn%+B&0l?QJ4QM`p)og(vv%ggWTJ_G`zp(B2&q*t$x(b3?1g%Gmn{_nH2? zxu%-40a*Fxkmk^5;;?xNke6bxR_yRLQ!Y<>KXN-Q12fiYgs7PpX02~e;Cj|dahkeu z{FPNyE5d3i6Yfim%vIXoFMdDd|NQ!$hhvRY<5WB<(7y#Kk~?o$d;Pbq65e*YV{n}N z+LT_LZ5y5s%{y=;554v6*@20Fy=RQ~u + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {D786173A-2ABC-484D-8AE7-D14550AB4DAD} + Win32Proj + Aquarium + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + + Console + true + + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceExample/InheritanceExample.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceExample/InheritanceExample.cpp new file mode 100644 index 00000000..eb21bdd0 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceExample/InheritanceExample.cpp @@ -0,0 +1,141 @@ +// InheritanceExample.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include +#include +#include + +constexpr double PI = 3.14; + +struct Position +{ + double x; + double y; + + Position(double x, double y) : x(x), y(y) {} +}; + +std::ostream& operator<<(std::ostream& os, const Position& pos) +{ + os << '(' << pos.x << pos.y << ')'; + return os; +} + +class Shape +{ +private: + +protected: + Position position; +public: + Shape(Position position): position(position) + { + + } + + double getCircumfere() const + { + return 0.0; + } + + double getArea() const + { + return 0.0; + } + + Position getPosition() const + { + return position; + } +}; + +std::ostream& operator<<(std::ostream& os, const Shape& shape) +{ + os << shape.getPosition() << ' ' << shape.getArea() << ' ' << shape.getCircumfere(); + return os; +} + +class Circle : public Shape +{ +private: + const double radius; +public: + Circle(const Position position, const double radius): Shape(position), radius(radius) + { + + } + + double getArea() const + { + return radius * radius * PI; + } + + double getCircumfere() const + { + return 2 * radius * PI; + } +}; + +class Rectangle : public Shape +{ +private: + double a; + double b; +public: + Rectangle(const Position position, const double a, const double b) : Shape(position), a(a), b(b) + { + + } + + double getArea() const + { + return a * b; + } + + double getCircumfere() const + { + return 2 * (a + b); + } +}; + +class Triangle : public Shape +{ +private: + double a; + double b; + double c; +public: + Triangle(const Position position, const double a, const double b, const double c) : Shape(position), a(a), b(b), c(c) + { + + } + + double getArea() const + { + double s = (a + b + c) / 2.0; + return sqrt(s*(s - a) * (s - b) * (s - c)); + } + + double getCircumfere() const + { + return a + b + c; + } +}; + +int main() +{ + Position p0({ 1.0, 2.0 }); + Circle c(p0, 1.0); + std::cout << c << '\n'; +} + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceExample/InheritanceExample.vcxproj b/SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceExample/InheritanceExample.vcxproj new file mode 100644 index 00000000..1b473dfc --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceExample/InheritanceExample.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {9E6F7934-5C47-4118-A373-573A537E08C1} + Win32Proj + InheritanceExample + 8.1 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Fal.h b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Fal.h new file mode 100644 index 00000000..1e03d86e --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Fal.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Padloelem.h" + +class Fal: public Unit +{ +private: +public: + Fal() : Unit({0, 0, 0, 0, OBSTACLE}) + {} + + +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Hero.h b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Hero.h new file mode 100644 index 00000000..10e7811c --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Hero.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include "common.h" +#include "Unit.h" + + + + +class Hero: public Unit +{ +private: + const std::string name; +public: + Hero(const std::string name, unsigned int health, unsigned int attack, unsigned int damage, unsigned int defense); + + ~Hero(); + + + friend std::ostream& operator<<(std::ostream& os, const Hero& hero); +}; + +std::ostream& operator<<(std::ostream& os, const Hero& hero); \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Labirintus.h b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Labirintus.h new file mode 100644 index 00000000..cfc8e8a7 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Labirintus.h @@ -0,0 +1,43 @@ +#pragma once + +#include "Hero.h" +#include "Padloelem.h" +#include "Szorny.h" +#include "Fal.h" +#include + +constexpr unsigned int LABIRINTUS_SIZE_X = 10; +constexpr unsigned int LABIRINTUS_SIZE_Y = 5; +constexpr unsigned int LABIRINTUS_PADLOELEMEK { LABIRINTUS_SIZE_X * LABIRINTUS_SIZE_Y }; + +class Labirintus +{ +private: + const int max_monster_cnt; + int current_monster_cnt; + Monster* monsters; + Fal* wallelems; + PadloElem elems[LABIRINTUS_PADLOELEMEK]; + Hero& hero; +public: + Labirintus(Hero& hero); + Labirintus(Hero& hero, const int monster_cnt, const int obstacle_cnt); + ~Labirintus(); + + void print() const; + + /** + Initialize neighbors of the labyrinth + */ + void initializeNeighbors(); + + void initHeroPosition(const unsigned int x, const unsigned int y); + + void initMonsterPosition(const int monster_id, + const unsigned int x, const unsigned int y); + + void initWallPosition(const int wall_id, + const unsigned int x, const unsigned int y); + + bool noLivingMonsters(); +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Labirintus.vcxproj b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Labirintus.vcxproj new file mode 100644 index 00000000..68222988 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Labirintus.vcxproj @@ -0,0 +1,171 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {A9DB730D-19FD-4F75-874F-5D65D9556AD1} + Win32Proj + Labirintus + 8.1 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + + Console + true + + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Padloelem.h b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Padloelem.h new file mode 100644 index 00000000..93620fb7 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Padloelem.h @@ -0,0 +1,36 @@ +#pragma once + +#include "common.h" +#include "Unit.h" + +class PadloElem +{ +private: + Coordinate coord; + Unit* occupyingunit; + + PadloElem* neighbors[4]; +protected: + +public: + PadloElem(unsigned int x, unsigned int y); + + PadloElem(); + + PadloElem* getNeighborElem(const MovingDirection& dir) const; + + void setCoordinate(unsigned int x, unsigned int y); + + void setNeighborElem(const MovingDirection& dir, PadloElem* p); + + void setOccupyingUnit(Unit* unit); + + Unit* getOccupyingUnit() const + { + return occupyingunit; + } + + bool isFoglalt() const; + + Coordinate getCoord() const; +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Szorny.h b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Szorny.h new file mode 100644 index 00000000..c463af8b --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Szorny.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Unit.h" + +class Monster : public Unit +{ +private: +public: + Monster(); + + +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Unit.h b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Unit.h new file mode 100644 index 00000000..0134c7fc --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/Unit.h @@ -0,0 +1,48 @@ +#pragma once + +#include "common.h" +#include + +class PadloElem; + +struct UnitStat +{ + unsigned int health; + unsigned int attack; + unsigned int damage; + unsigned int defense; +}; + +class Unit +{ +protected: + bool dead; + UnitStat unitstat; + PadloElem* current_padloelem; + const UnitType unittype; +public: + Unit(unsigned int health, unsigned int attack, unsigned int damage, unsigned int defense, const UnitType unittype): + unitstat({health, attack, damage, defense}), + dead(false), + current_padloelem(NULL), + unittype(unittype) + {} + + bool isKilled() + { + return unitstat.health == 0; + } + + bool kill(); + + + bool move(MovingDirection movedir); + void damage(unsigned int attack, unsigned int damage); + + void setCurrentPadloelem(PadloElem* padloelem); + + UnitType getUnitType() const + { + return unittype; + } +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/common.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/common.cpp new file mode 100644 index 00000000..c6195949 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/common.cpp @@ -0,0 +1,7 @@ +#include "common.h" + +std::ostream& operator<<(std::ostream& file, const Coordinate& coord) +{ + file << '(' << coord.x << ',' << coord.y << ')'; + return file; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/common.h b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/common.h new file mode 100644 index 00000000..0a72f6eb --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/common.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +enum MovingDirection { ESZAK, KELET, NYUGAT, DEL }; +enum UnitType {MONSTER, HERO, OBSTACLE}; + +struct Coordinate +{ + unsigned int x; + unsigned int y; +}; + +std::ostream& operator<<(std::ostream& file, const Coordinate& coord); + diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/hero.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/hero.cpp new file mode 100644 index 00000000..5428df51 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/hero.cpp @@ -0,0 +1,25 @@ +#include "Hero.h" +#include "Padloelem.h" + +Hero::Hero(const std::string name, unsigned int health, unsigned int attack, unsigned int damage, unsigned int defense) + : + Unit(health, attack, damage, defense, HERO), + name(name) +{ +} + +Hero::~Hero() +{ + current_padloelem = NULL; +} + + + + + + +std::ostream& operator<<(std::ostream& os, const Hero& hero) +{ + os << hero.name << hero.current_padloelem->getCoord(); + return os; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/labirintus.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/labirintus.cpp new file mode 100644 index 00000000..5ffd159a --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/labirintus.cpp @@ -0,0 +1,153 @@ +ďťż#include "Labirintus.h" + +Labirintus::Labirintus(Hero& hero) : Labirintus(hero, 0, 0) +{ + +} + +Labirintus::Labirintus(Hero& hero, const int monster_cnt, const int obstacle_cnt) : + max_monster_cnt(monster_cnt), hero(hero) +{ + monsters = new Monster[monster_cnt]; + wallelems = new Fal[obstacle_cnt]; + current_monster_cnt = max_monster_cnt; +} + +Labirintus::~Labirintus() +{ + delete[] monsters; + delete[] wallelems; +} + +void Labirintus::print() const +{ + for (unsigned int x = 0; x < LABIRINTUS_SIZE_X; x++) + { + std::cout << "-"; + } + std::cout << "\n"; + for (unsigned int y = 0; y < LABIRINTUS_SIZE_Y; y++) + { + for (unsigned int x = 0; x < LABIRINTUS_SIZE_X; x++) + { + if (elems[y * LABIRINTUS_SIZE_X + x].isFoglalt()) + { + switch (elems[y * LABIRINTUS_SIZE_X + x].getOccupyingUnit()->getUnitType()) + { + case UnitType::HERO: { + std::cout << 'O'; + break; + } + case UnitType::MONSTER: { + std::cout << 'X'; + break; + } + case UnitType::OBSTACLE: { + std::cout << 'H'; + break; + } + } + } + else + { + std::cout << " "; + } + } + std::cout << '\n'; + } + for (unsigned int x = 0; x < LABIRINTUS_SIZE_X; x++) + { + std::cout << "-"; + } + std::cout << "\n"; +} + + + +void Labirintus::initializeNeighbors() +{ + // Y coord + for (unsigned int y = 0; y < LABIRINTUS_SIZE_Y; y++) + { + // X coord + for (unsigned int x = 0; x < LABIRINTUS_SIZE_X; x++) + { + elems[y * LABIRINTUS_SIZE_X + x].setCoordinate(x, y); + // Left boundary + if (x == 0) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(KELET, &elems[y * LABIRINTUS_SIZE_X + x + 1]); // Point to east + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(DEL, &elems[(y + 1) * LABIRINTUS_SIZE_X + x]); // Point to south + // Not in left-upper corner + if (y > 0) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(ESZAK, &elems[(y - 1) * LABIRINTUS_SIZE_X + x]); // Point to north + } + } + // Right boundary + else if (x == LABIRINTUS_SIZE_X - 1) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(NYUGAT, &elems[y * LABIRINTUS_SIZE_X + x - 1]); // Point to west + if (y < LABIRINTUS_SIZE_Y - 1) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(DEL, &elems[(y + 1) * LABIRINTUS_SIZE_X + x]); // Point to south + } + // Not in right-upper corner + if (y > 0) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(ESZAK, &elems[(y - 1) * LABIRINTUS_SIZE_X + x]); // Point to north + } + } + else if (y == 0) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(KELET, &elems[y * LABIRINTUS_SIZE_X + x + 1]); // Point to east + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(NYUGAT, &elems[y * LABIRINTUS_SIZE_X + x - 1]); // Point to west + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(DEL, &elems[(y + 1) * LABIRINTUS_SIZE_X + x]); // Point to south + } + else if (y == LABIRINTUS_SIZE_Y - 1) + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(KELET, &elems[y * LABIRINTUS_SIZE_X + x + 1]); // Point to east + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(NYUGAT, &elems[y * LABIRINTUS_SIZE_X + x - 1]); // Point to west + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(ESZAK, &elems[(y - 1) * LABIRINTUS_SIZE_X + x]); // Point to north + } + else + { + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(KELET, &elems[y * LABIRINTUS_SIZE_X + x + 1]); + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(NYUGAT, &elems[y * LABIRINTUS_SIZE_X + x - 1]); + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(ESZAK, &elems[(y - 1) * LABIRINTUS_SIZE_X + x]); + elems[y * LABIRINTUS_SIZE_X + x].setNeighborElem(DEL, &elems[(y + 1) * LABIRINTUS_SIZE_X + x]); + } + } + } +} + +bool Labirintus::noLivingMonsters() +{ + unsigned int living_monsters = 0; + for (int i = 0; i < max_monster_cnt; i++) + { + if (!monsters[i].isKilled()) + { + living_monsters++; + } + } + return living_monsters==0; +} + +void Labirintus::initHeroPosition(const unsigned int x, const unsigned int y) +{ + elems[y * LABIRINTUS_SIZE_X + x].setOccupyingUnit(&hero); + hero.setCurrentPadloelem(&elems[y * LABIRINTUS_SIZE_X + x]); +} + +void Labirintus::initMonsterPosition(const int monster_id, const unsigned int x, const unsigned int y) +{ + elems[y * LABIRINTUS_SIZE_X + x].setOccupyingUnit(&monsters[monster_id]); + monsters[monster_id].setCurrentPadloelem(&elems[y * LABIRINTUS_SIZE_X + x]); +} + +void Labirintus::initWallPosition(const int wall_id, const unsigned int x, const unsigned int y) +{ + elems[y * LABIRINTUS_SIZE_X + x].setOccupyingUnit(&wallelems[wall_id]); + wallelems[wall_id].setCurrentPadloelem(&elems[y * LABIRINTUS_SIZE_X + x]); +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/main.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5c12d72c4b3e8cf6a2d02dc17823d345e4dc7265 GIT binary patch literal 4156 zcmb_fX>Zd&5S_0^;y-MIL{kZ+7dHi|G--hzpcaHcNKsCRNRueNIR85E-i$YEyLJy` zS&kj=%-gwV_V1rXSrjKb(vr3eWQuzv$8sV^Qj?BMa5;I5yDmNH>uL{c4m4lz#o;FX zRKDYVBIB6ffp(0qfv$u9BXEvosC+HO9)iAuy^rzadQEQ14M?=8Prlz$#16Plq^q23 zN_(Wc_P~26&y+fk(x|A@=a?!Vvm!5mJ%tQ4=v67etH>Md*M%%&P*ab?OX&0MdeIKF z(;+UihNtvW_tge{*tIF|<)!S&s;tD)(mLKlT;Gs=c?-Wimo5C;m32tp#P1HS*I4zK zBX}TbUD}K~4iFKvMzM7}uo!9Eux^r)G0_EoU-#fXZRkVKJA6HYEMqyv8@;lDck0_x zo+@OqI5`HbN%9!+m-ORptaQN9l?BEBslO3q=|P$kJV!GM#xU_Gz~_1uzGci1uL6E2 zPjNX}!u<=EN6zCr1LyznjUWN-L|Pckq81Hd%__R^#Wr*~)^L4D@Z3TRj}SeZHntXZv#x z!&`-{Nwhq^nnue2wip1FvH1g9?%^Il=Pw#xQ)oiH4J*psKj3(ayn!u_fZ{7q75PNj zR<4Z1Xl7+QhBQ;;SQgK$Xf_PGUMAmVsLLwlef=#D)pR%P<qLzVC9(Nrv-k4r{p@VI3lqpyoPnXZ(+n)!@K*4;W{o)xh( zi+rawdz#9{Gvw9)nZ!e+S}*Z7iXbujYZcGSI+gVxZ;eQTJpziM z=k=5PJ`~W>cv0*fb}X0bpyxfwIM|j3>T&}UK+r4_>lqPhb_72Tp&>o%H7=GlzxS0T z>z;g&cj!jzB}rSsCbHvUyhBiM2^jj65@u;{dDVU?=SGaq3@&*6Ki_^eMrF*H6^0odAosmp1lj#|vBJ!!Obwg? cSzrB5w}9kNXiiVt=g*Vb^VCuty}@Ju0L^}1iU0rr literal 0 HcmV?d00001 diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/padloelem.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/padloelem.cpp new file mode 100644 index 00000000..336f5155 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/padloelem.cpp @@ -0,0 +1,44 @@ +#include "Padloelem.h" + +PadloElem::PadloElem() : PadloElem(0, 0) +{} + +PadloElem::PadloElem(unsigned int x, unsigned int y) : coord({ x, y }), occupyingunit(NULL) +{ + neighbors[MovingDirection::ESZAK] = NULL; + neighbors[MovingDirection::KELET] = NULL; + neighbors[MovingDirection::NYUGAT] = NULL; + neighbors[MovingDirection::DEL] = NULL; +} + +PadloElem* PadloElem::getNeighborElem(const MovingDirection& dir) const +{ + return neighbors[dir]; +} + +void PadloElem::setCoordinate(unsigned int x, unsigned int y) +{ + coord.x = x; + coord.y = y; +} + +void PadloElem::setNeighborElem(const MovingDirection& dir, PadloElem* p) +{ + neighbors[dir] = p; +} + + +bool PadloElem::isFoglalt() const +{ + return occupyingunit != NULL; +} + +void PadloElem::setOccupyingUnit(Unit* unit) +{ + occupyingunit = unit; +} + +Coordinate PadloElem::getCoord() const +{ + return coord; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/szorny.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/szorny.cpp new file mode 100644 index 00000000..b1f6bc33 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/szorny.cpp @@ -0,0 +1,6 @@ +#include "Szorny.h" + +Monster::Monster() : Unit(20, 10, 12, 5, MONSTER) +{ +} + diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/unit.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/unit.cpp new file mode 100644 index 00000000..3eb8c6b2 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Labirintus/unit.cpp @@ -0,0 +1,66 @@ +#include "Unit.h" +#include "Padloelem.h" + +#include + +bool Unit::move(MovingDirection movedir) +{ + PadloElem* p = current_padloelem->getNeighborElem(movedir); + if (p != NULL) + { + if (!p->isFoglalt()) + { + current_padloelem->setOccupyingUnit(NULL); + setCurrentPadloelem(current_padloelem->getNeighborElem(movedir)); + return true; + } + else if (p->getOccupyingUnit()->getUnitType() != UnitType::OBSTACLE) + { + p->getOccupyingUnit()->damage(this->unitstat.attack, this->unitstat.damage); + std::cout << "Attacking monster" << std::endl; + return true; + } + } + else + { + return false; + } +} + +void Unit::damage(unsigned int attack, unsigned int damage) +{ + unsigned int dmg = (unsigned int)(((double)(unitstat.defense) / (double)(unitstat.attack)) * damage); + if (unitstat.health <= dmg) + { + unitstat.health = 0; + kill(); + } + else + { + unitstat.health -= (unsigned int)(((double)(unitstat.defense) / (double)(unitstat.attack)) * damage); + } + std::cout << unitstat.health << std::endl; +} + +void Unit::setCurrentPadloelem(PadloElem* padloelem) +{ + current_padloelem = padloelem; + current_padloelem->setOccupyingUnit(this); +} + +bool Unit::kill() +{ + if (isKilled()) + { + std::cout << "DEAD" << std::endl; + if (!dead) + { + + current_padloelem->setOccupyingUnit(NULL); + current_padloelem = NULL; + dead = true; + } + return true; + } + return false; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/LinkedListTemplate/LinkedList.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/LinkedListTemplate/LinkedList.cpp new file mode 100644 index 00000000..7f2bcecc --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/LinkedListTemplate/LinkedList.cpp @@ -0,0 +1,26 @@ +// LinkedList.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include + +#define _CRTDBG_MAP_ALLOC +#include +#include + +#include "LinkedList.h" + +void linkedlisttest() +{ + Robot robot; + robot.addPositionMeasurement(10, 10, 10); + robot.addPositionMeasurement(10, 10, 15); + robot.addPositionMeasurement(10, 7, 6); + robot.stationaryMeasurment(); + robot.print(); +} + +int main() +{ + linkedlisttest(); + _CrtDumpMemoryLeaks(); +} diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/LinkedListTemplate/LinkedList.h b/SZE/OODB/kyberszittya/Rec4/Recitation4/LinkedListTemplate/LinkedList.h new file mode 100644 index 00000000..972cbe06 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/LinkedListTemplate/LinkedList.h @@ -0,0 +1,135 @@ +#pragma once + +#include + +class Position +{ +private: + double x; + double y; + double z; +public: + Position(double x, double y, double z): x(x), y(y), z(z) + {} + Position(const Position& other) + { + x = other.x; + y = other.y; + z = other.z; + } + + friend std::ostream& operator<<(std::ostream& os, const Position& pos); +}; + +std::ostream& operator<<(std::ostream& os, const Position& pos) +{ + os << '(' << pos.x << ',' << pos.y << ',' << pos.z << ')'; + return os; +} + +template struct LinkedListElement +{ + T element; + LinkedListElement* prev_element; + LinkedListElement* next_element; +}; + +template class LinkedList +{ +private: + LinkedListElement* first_elem; + LinkedListElement* last_elem; +public: + LinkedList(): first_elem(NULL), last_elem(NULL) + {} + + ~LinkedList() + { + LinkedListElement* current_element = first_elem; + while (current_element != NULL) + { + LinkedListElement* tmp = current_element; + current_element = current_element->next_element; + delete tmp; + } + } + + + + T& last() + { + return last_elem->element; + } + + T& first() + { + return first_elem->element; + } + + void print() + { + LinkedListElement* current_element = first_elem; + while (current_element != NULL) + { + std::cout << current_element->element << std::endl; + current_element = current_element->next_element; + } + } + + void addElement(T& position) + { + if (first_elem == NULL) + { + first_elem = new LinkedListElement({ position, NULL, NULL }); + last_elem = first_elem; + } + else + { + last_elem->next_element = new LinkedListElement({ position, last_elem, NULL }); + last_elem = last_elem->next_element; + } + } +}; + + +template LinkedList& operator+(LinkedList& list, Position& elem) +{ + list.addElement(elem); + return list; +} + +class Robot +{ +private: + LinkedList* measurements; +public: + Robot() + { + measurements = new LinkedList(); + } + + ~Robot() + { + delete measurements; + } + + void addPositionMeasurement(double x, double y, double z) + { + Position p(x, y, z); + measurements->addElement(p); + } + + + + void stationaryMeasurment() + { + Position p0(measurements->last()); + measurements->addElement(p0); + } + + void print() + { + measurements->print(); + } +}; + diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Recitation4.sln b/SZE/OODB/kyberszittya/Rec4/Recitation4/Recitation4.sln new file mode 100644 index 00000000..1a76e0aa --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/Recitation4.sln @@ -0,0 +1,81 @@ +ďťż +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27428.2027 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InheritanceExample", "InheritanceExample\InheritanceExample.vcxproj", "{9E6F7934-5C47-4118-A373-573A537E08C1}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Labirintus", "Labirintus\Labirintus.vcxproj", "{A9DB730D-19FD-4F75-874F-5D65D9556AD1}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LinkedListTemplate", "LinkedListTemplate\LinkedListTemplate.vcxproj", "{86EDF3C5-2C5F-4BFF-B55A-0CD2D4267115}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Aquarium", "Aquarium\Aquarium.vcxproj", "{D786173A-2ABC-484D-8AE7-D14550AB4DAD}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VectorExample", "VectorExample\VectorExample.vcxproj", "{056402F3-72FB-43F9-B100-F70B0EA9433D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TemplateVeryEasy", "TemplateVeryEasy\TemplateVeryEasy.vcxproj", "{DEB90F72-ADB3-4074-8E59-8BA3A49A727C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9E6F7934-5C47-4118-A373-573A537E08C1}.Debug|x64.ActiveCfg = Debug|x64 + {9E6F7934-5C47-4118-A373-573A537E08C1}.Debug|x64.Build.0 = Debug|x64 + {9E6F7934-5C47-4118-A373-573A537E08C1}.Debug|x86.ActiveCfg = Debug|Win32 + {9E6F7934-5C47-4118-A373-573A537E08C1}.Debug|x86.Build.0 = Debug|Win32 + {9E6F7934-5C47-4118-A373-573A537E08C1}.Release|x64.ActiveCfg = Release|x64 + {9E6F7934-5C47-4118-A373-573A537E08C1}.Release|x64.Build.0 = Release|x64 + {9E6F7934-5C47-4118-A373-573A537E08C1}.Release|x86.ActiveCfg = Release|Win32 + {9E6F7934-5C47-4118-A373-573A537E08C1}.Release|x86.Build.0 = Release|Win32 + {A9DB730D-19FD-4F75-874F-5D65D9556AD1}.Debug|x64.ActiveCfg = Debug|x64 + {A9DB730D-19FD-4F75-874F-5D65D9556AD1}.Debug|x64.Build.0 = Debug|x64 + {A9DB730D-19FD-4F75-874F-5D65D9556AD1}.Debug|x86.ActiveCfg = Debug|Win32 + {A9DB730D-19FD-4F75-874F-5D65D9556AD1}.Debug|x86.Build.0 = Debug|Win32 + {A9DB730D-19FD-4F75-874F-5D65D9556AD1}.Release|x64.ActiveCfg = Release|x64 + {A9DB730D-19FD-4F75-874F-5D65D9556AD1}.Release|x64.Build.0 = Release|x64 + {A9DB730D-19FD-4F75-874F-5D65D9556AD1}.Release|x86.ActiveCfg = Release|Win32 + {A9DB730D-19FD-4F75-874F-5D65D9556AD1}.Release|x86.Build.0 = Release|Win32 + {86EDF3C5-2C5F-4BFF-B55A-0CD2D4267115}.Debug|x64.ActiveCfg = Debug|x64 + {86EDF3C5-2C5F-4BFF-B55A-0CD2D4267115}.Debug|x64.Build.0 = Debug|x64 + {86EDF3C5-2C5F-4BFF-B55A-0CD2D4267115}.Debug|x86.ActiveCfg = Debug|Win32 + {86EDF3C5-2C5F-4BFF-B55A-0CD2D4267115}.Debug|x86.Build.0 = Debug|Win32 + {86EDF3C5-2C5F-4BFF-B55A-0CD2D4267115}.Release|x64.ActiveCfg = Release|x64 + {86EDF3C5-2C5F-4BFF-B55A-0CD2D4267115}.Release|x64.Build.0 = Release|x64 + {86EDF3C5-2C5F-4BFF-B55A-0CD2D4267115}.Release|x86.ActiveCfg = Release|Win32 + {86EDF3C5-2C5F-4BFF-B55A-0CD2D4267115}.Release|x86.Build.0 = Release|Win32 + {D786173A-2ABC-484D-8AE7-D14550AB4DAD}.Debug|x64.ActiveCfg = Debug|x64 + {D786173A-2ABC-484D-8AE7-D14550AB4DAD}.Debug|x64.Build.0 = Debug|x64 + {D786173A-2ABC-484D-8AE7-D14550AB4DAD}.Debug|x86.ActiveCfg = Debug|Win32 + {D786173A-2ABC-484D-8AE7-D14550AB4DAD}.Debug|x86.Build.0 = Debug|Win32 + {D786173A-2ABC-484D-8AE7-D14550AB4DAD}.Release|x64.ActiveCfg = Release|x64 + {D786173A-2ABC-484D-8AE7-D14550AB4DAD}.Release|x64.Build.0 = Release|x64 + {D786173A-2ABC-484D-8AE7-D14550AB4DAD}.Release|x86.ActiveCfg = Release|Win32 + {D786173A-2ABC-484D-8AE7-D14550AB4DAD}.Release|x86.Build.0 = Release|Win32 + {056402F3-72FB-43F9-B100-F70B0EA9433D}.Debug|x64.ActiveCfg = Debug|x64 + {056402F3-72FB-43F9-B100-F70B0EA9433D}.Debug|x64.Build.0 = Debug|x64 + {056402F3-72FB-43F9-B100-F70B0EA9433D}.Debug|x86.ActiveCfg = Debug|Win32 + {056402F3-72FB-43F9-B100-F70B0EA9433D}.Debug|x86.Build.0 = Debug|Win32 + {056402F3-72FB-43F9-B100-F70B0EA9433D}.Release|x64.ActiveCfg = Release|x64 + {056402F3-72FB-43F9-B100-F70B0EA9433D}.Release|x64.Build.0 = Release|x64 + {056402F3-72FB-43F9-B100-F70B0EA9433D}.Release|x86.ActiveCfg = Release|Win32 + {056402F3-72FB-43F9-B100-F70B0EA9433D}.Release|x86.Build.0 = Release|Win32 + {DEB90F72-ADB3-4074-8E59-8BA3A49A727C}.Debug|x64.ActiveCfg = Debug|x64 + {DEB90F72-ADB3-4074-8E59-8BA3A49A727C}.Debug|x64.Build.0 = Debug|x64 + {DEB90F72-ADB3-4074-8E59-8BA3A49A727C}.Debug|x86.ActiveCfg = Debug|Win32 + {DEB90F72-ADB3-4074-8E59-8BA3A49A727C}.Debug|x86.Build.0 = Debug|Win32 + {DEB90F72-ADB3-4074-8E59-8BA3A49A727C}.Release|x64.ActiveCfg = Release|x64 + {DEB90F72-ADB3-4074-8E59-8BA3A49A727C}.Release|x64.Build.0 = Release|x64 + {DEB90F72-ADB3-4074-8E59-8BA3A49A727C}.Release|x86.ActiveCfg = Release|Win32 + {DEB90F72-ADB3-4074-8E59-8BA3A49A727C}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CFA6B596-FDD1-401B-8D3A-527388679888} + EndGlobalSection +EndGlobal diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/TemplateVeryEasy/TemplateVeryEasy.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/TemplateVeryEasy/TemplateVeryEasy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..52405fca050cd0e080316c928be4af033a03945c GIT binary patch literal 3734 zcmc&%T~8BH5S`bW_#ZYkkpfzzk62AWjGBNFL?1*#+HI*Tls0Wa8-hPwJ!kID-o5Q^ zi^jw>?S9SYnKLunUq3fwLn1knuJmOn7t)dm&OhQilBvAJ^%%#x#CSS{vCW2A-WAc z^8A5XjG=WU9o1~&&H$F^wF}+8JXh%=Nhigqd#RMONlTVZB&YI14uQw6?8qxz?aQ_t z;J7V&_`Ji@vPfvZgV+*j1FtU&B8d?#W!s3vOVTcLBjQAL2bm4zT>ahX?+|*4Tq{Oh zRDv26&Ax-HtrQ2BVT3%1M^~Pvx>xY$Fg8u|P?J^oyOG;ewvzd-EwxTfa>BgTvNN;k zqV&G3`ecUPeTee`Fd>gd8ck@^KdUdX?<@_~4!KO`J(C)cb)1{^+QxmNyqcovkgfn% zMw1}_$Ec)b7r|Bp9G#Aj#bHb>@^Auvj-V6CT4u#0Zq?7?%JtO7+q8bJIzE1<>*EYP zTBM;rt1NZ%9NR{m6J*JIU5(7y{ntzj{dm5)TxOrTPAX^g-8lC@G4>gR)2WD^O=*Ik zi#5jb2yF5k2s_94=s0Z5pyvp-n*n3zxn)cVc|>jZ#4~nrjA76HT~;9zh*m3LXnBUA zTpg2@eVFf|yXWa~?#g%UCho2)^z#^<(!;Tf*&X4W+b)v#@h2IV;kw>D2c*rA*blzWr?H}oeAae6avWI+?O}~PD=_2RUH|t|WT!tDm z$!`ziBlXL4)@420$(A+cS?w`?ErNV3zDr|B5NVqN)g1EVFXzJ0 z-ljNJT3UJI*iQP!!ak@W);(O0v}Xp&etUyIRBt`hwhEMsv^Q1%b!wk)`UkKz!G~Nc z(`u*|V{IXuDP;SIWLCq)T!&0iAGdQ6EtA~*1KCD_>>_>}D$K^s>ZbOUe~>Ny@O{WndQ+~oX4cnJKs^11SEmZ&j literal 0 HcmV?d00001 diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/VectorExample/VectorExample.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/VectorExample/VectorExample.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6b043080b1bd757c8defe0f5457e80c9e0c9248d GIT binary patch literal 1866 zcmc&!T~ES55S&*`{0~h`1cCu1qJrp?{sp6nFQtHzK--jJAcViJ&ThZBwo!~4)3n{& zo7+3nPoS%Q(QA zvCk@k2pLbbVuo`#cDd5i+7@}F_KbLkamcsKH*tsq>T2m*;v=o-5V^!i83&48DC=1D z-lS;3*<=xgyF2Spzf{}k)2H4kUX^#u-N{Ua)je_yV|^=JmFCxR-jA`OKdF#stQBgW zP?yQGMx8lvc!e78Is~(39L;R7RUMJWB17VJ6`oBTG zY!~Hz+Il`;p@wusSQ8KO?3Q}6AfL^iH+^i-qhT&9J&_?3Urc0_t*3o!x-O$dJeT>N z*A;clZ@6Nf=g<8pbKo!bdd)K_bESCh|G7iEaFWS?cg{YMSiZ^6JJ2TPlzrCLj_zob zIhyxCda{OYia%%6B}ej?EaDxl-;V2F;1WG!h5W%s{PXqon_F^ZVZh7cI-5`F?jFv# ircIvwR}vwsc;a5GsfvASN-yqH%_6^C=6BRCIR63V?+l&* literal 0 HcmV?d00001 diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/VectorExample/VectorExample.vcxproj b/SZE/OODB/kyberszittya/Rec4/Recitation4/VectorExample/VectorExample.vcxproj new file mode 100644 index 00000000..1936a9d7 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/VectorExample/VectorExample.vcxproj @@ -0,0 +1,158 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {056402F3-72FB-43F9-B100-F70B0EA9433D} + Win32Proj + VectorExample + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file From f55d96f79309aa6bfa721463d00f33367b9aa6ba Mon Sep 17 00:00:00 2001 From: Hajdu Csaba Date: Sat, 19 Oct 2019 13:10:06 +0200 Subject: [PATCH 07/14] Recitation 5 added Recitation 5 added --- .gitignore | 21 ++ .../Rec4/Recitation4/Aquarium/Aquarium.cpp | Bin 3044 -> 3124 bytes .../InheritanceAnotherExample.cpp | Bin 0 -> 2824 bytes .../InheritanceAnotherExample.vcxproj | 166 +++++++++++++ .../InheritanceExample/InheritanceExample.cpp | 5 +- .../AquariumDynamicCast.vcxproj | 159 ++++++++++++ .../Recitation5/AquariumDynamicCast/main.cpp | 135 +++++++++++ .../ForestExample/ForestExample.cpp | 228 ++++++++++++++++++ .../ForestExample/ForestExample.vcxproj | 159 ++++++++++++ .../Recitation5/HouseSensors/HouseSensors.cpp | 17 ++ .../HouseSensors/HouseSensors.vcxproj | 159 ++++++++++++ .../Rec5/Recitation5/Recitation5.sln | 91 +++++++ .../SensorNetwork/SensorNetwork.cpp | 128 ++++++++++ .../SensorNetwork/SensorNetwork.vcxproj | 159 ++++++++++++ .../Recitation5/SphereList/SphereList.cpp | Bin 0 -> 2938 bytes .../Recitation5/SphereList/SphereList.vcxproj | 165 +++++++++++++ .../StlListExample/StlListExample.cpp | Bin 0 -> 1650 bytes .../StlListExample/StlListExample.vcxproj | 166 +++++++++++++ 18 files changed, 1756 insertions(+), 2 deletions(-) create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceAnotherExample/InheritanceAnotherExample.cpp create mode 100644 SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceAnotherExample/InheritanceAnotherExample.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/AquariumDynamicCast/AquariumDynamicCast.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/AquariumDynamicCast/main.cpp create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/ForestExample/ForestExample.cpp create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/ForestExample/ForestExample.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/HouseSensors/HouseSensors.cpp create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/HouseSensors/HouseSensors.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/Recitation5.sln create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/SensorNetwork/SensorNetwork.cpp create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/SensorNetwork/SensorNetwork.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/SphereList/SphereList.cpp create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/SphereList/SphereList.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/StlListExample/StlListExample.cpp create mode 100644 SZE/OODB/kyberszittya/Rec5/Recitation5/StlListExample/StlListExample.vcxproj diff --git a/.gitignore b/.gitignore index 70fa4c1c..7e1535a8 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,24 @@ *.exe *.out *.app +*.filters +*.user +*.log +*.pdb +*.idb +*.tlog +*.ilk +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/.suo +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/Browse.VC.db +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/Browse.VC.opendb +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/ipch/720e8647fbac6ed7.ipch +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/ipch/AutoPCH/6bfa9ec59ac6f7db/LINKEDLIST.ipch +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/ipch/AutoPCH/abb60791adcf511b/LABIRINTUS.ipch +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/ipch/AutoPCH/cdab13bb4a56a2ec/UNIT.ipch +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/ipch/AutoPCH/cea2f45df4cc64ab/SPHERECALCULATION.ipch +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/ipch/AutoPCH/dee12e2fe46a3cab/BOOKOPERATOROVERLOADING.ipch +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/ipch/AutoPCH/e7590d024f13c469/MAIN.ipch +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/ipch/f1b21f5d4784671e.ipch +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/Solution.VC.db +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/Solution.VC.db-shm +SZE/OODB/kyberszittya/Rec3/Recitation3/.vs/Recitation3/v15/Solution.VC.db-wal diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/Aquarium/Aquarium.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/Aquarium/Aquarium.cpp index 2bdc0f60ec583af58954eda56259d3bb2a1b7cae..6264080e0984f0425885349685dfc9655558bd13 100644 GIT binary patch delta 66 zcmaDNzC~g~7t7=(rj*V1SXfw@^%?XhKjbu?yn_je8u&Rk%nv>sgeFFfGgc5N8 delta 52 zcmdlY@kD$>7t3S;c8aPRm?CfTDeW~Ii zWZB;J&gIPPnOXn&J(Qs&@=Xf4lw7v5kWwa?WtffeUSqB+U*#88Rw`m=zdr?&ob$BgFi!so0-cL&MbtgE)#zlQDtI?PXoD>t6D z7DZa|KasxmteAU1=A_Q?h?!@mv$c!;|x`gc& z?kRSK{9uF|%K+xDD}OvzW~4OiI5i{IC0UvPEo*9queaFul||PJ;%wKQLYuWcvs!Iz z3}bK{Xo~kCOyF)mB+g^?e2mIDWlFD7$)0~P`;?8<9H+IctDN_hf&(tM^t+dkr@n64 z7qtVFhB4%*BJ?%dT-zgbzt{2#@-aVEyNxYc6W=SG=~fxlY;^bk`H-7#o_$VZpY1id zfG3_CWI0cRf33*4pRvYSh1^9&)UASIbjMdu=+|}9YEO2Zm3$^wMqmoZp>7(@?&Ikk zk~eZZJKxuM8SW7|>P~**&n}hrcC_;^ z4;`Q>vVmb|wZ|NTsh*_)xXv@Rxqm3Sr-+BQi|l_}sh;om=O_U(UhH8d_CU}2k + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {2B90F8A3-96D6-445E-B5EB-DA32D25E8624} + Win32Proj + InheritanceAnotherExample + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + + Console + true + + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + Create + Create + Create + Create + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceExample/InheritanceExample.cpp b/SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceExample/InheritanceExample.cpp index eb21bdd0..5eb6a6dc 100644 --- a/SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceExample/InheritanceExample.cpp +++ b/SZE/OODB/kyberszittya/Rec4/Recitation4/InheritanceExample/InheritanceExample.cpp @@ -33,12 +33,12 @@ class Shape } - double getCircumfere() const + virtual double getCircumfere() const { return 0.0; } - double getArea() const + virtual double getArea() const { return 0.0; } @@ -98,6 +98,7 @@ class Rectangle : public Shape } }; + class Triangle : public Shape { private: diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/AquariumDynamicCast/AquariumDynamicCast.vcxproj b/SZE/OODB/kyberszittya/Rec5/Recitation5/AquariumDynamicCast/AquariumDynamicCast.vcxproj new file mode 100644 index 00000000..a39c1ab1 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec5/Recitation5/AquariumDynamicCast/AquariumDynamicCast.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {6F52EC43-15C7-4776-852D-094A336E42BA} + Win32Proj + AquariumDynamicCast + 8.1 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/AquariumDynamicCast/main.cpp b/SZE/OODB/kyberszittya/Rec5/Recitation5/AquariumDynamicCast/main.cpp new file mode 100644 index 00000000..120bf37d --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec5/Recitation5/AquariumDynamicCast/main.cpp @@ -0,0 +1,135 @@ +// AquariumDynamicCast.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include +#include + +#define _CRTDBG_MAP_ALLOC +#include +#include + +class Fish +{ +private: + double mass; +public: + Fish(double mass): mass(mass){} + + virtual void speak() + { + std::cout << "I am a fish" << std::endl; + } + + virtual void swim() + { + std::cout << "Fish swimming" << std::endl; + } +}; + +class Trout: public Fish +{ +public: + Trout() : Fish(10) {}; + + virtual void speak() + { + std::cout << "I am a trout" << std::endl; + } +}; + +class Carp : public Fish +{ +public: + Carp() : Fish(20) {}; + + void floating() + { + std::cout << "Carp floats\n"; + } + + virtual void speak() + { + floating(); + std::cout << "I am a carp" << std::endl; + } +}; + +class Shark: public Fish +{ +public: + Shark() : Fish(1000) {} + + virtual void speak() + { + std::cout << "I am a shark" << std::endl; + } +}; + +class Aquarium +{ +private: + Fish** fishes; + unsigned int current_fishes; + const unsigned int max_fishes; +public: + Aquarium(const unsigned int max_fishes): + current_fishes(0), + max_fishes(max_fishes), + fishes(new Fish*[max_fishes]) {} + + ~Aquarium() + { + for (unsigned int i = 0; i < current_fishes; i++) + { + delete fishes[i]; + } + delete[] fishes; + } + + void insertFish(Fish* fish) + { + if (current_fishes < max_fishes) + { + fishes[current_fishes] = fish; + current_fishes++; + } + else + { + std::cerr << "Aquarium is full"; + } + } + + void speakAllFish() + { + for (unsigned int i = 0; i < current_fishes; i++) + { + fishes[i]->speak(); + } + } + + void feedFish() + { + for (unsigned int i = 0; i < current_fishes; i++) + { + + } + } +}; + +void aquariumExample() +{ + Aquarium aquarium(10); + aquarium.addFish(new Trout()); + aquarium.addFish(new Trout()); + aquarium.addFish(new Fish(1.0)); + aquarium.addFish(new Shark()); + aquarium.addFish(new Carp()); + aquarium.speakAllFish(); +} + +int main(int argc, char ** argv) +{ + aquariumExample(); + _CrtDumpMemoryLeaks(); + return 0; +} diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/ForestExample/ForestExample.cpp b/SZE/OODB/kyberszittya/Rec5/Recitation5/ForestExample/ForestExample.cpp new file mode 100644 index 00000000..12c62411 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec5/Recitation5/ForestExample/ForestExample.cpp @@ -0,0 +1,228 @@ +// ForestExample.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include +#include + +#define _CRTDBG_MAP_ALLOC +#include +#include + +class Creature +{ +protected: + double mass; + const double energy; + bool alive; +public: + Creature(double mass, double energy) : + mass(mass), + energy(energy), + alive(true) {} + + virtual double nutrition() + { + return mass*energy; + } + + virtual void harvest() = 0; + + bool isAlive() + { + return alive; + } + + void kill() + { + alive = false; + } +}; + +class Plant: public Creature +{ +private: + const double collagen_ratio; + const double growth_ratio; +public: + Plant(const double collagen_ratio, double mass, double energy) : Creature(mass, energy), collagen_ratio(collagen_ratio), growth_ratio(0.04) {} + + virtual double nutrition() + { + return collagen_ratio * mass * energy; + } + + void grow() + { + if (mass > 0.0) + { + mass += growth_ratio * mass; + } + else + { + mass = 0.1; + } + } + + virtual void harvest() + { + mass = 0; + } +}; + +class Animal: public Creature +{ +private: + const double metabolism_rate; +public: + Animal(const double metabolism_rate, double mass, double energy) : Creature(mass, energy), metabolism_rate(metabolism_rate) {} + + virtual void eat(Creature* creature) = 0; + virtual void metabolism() + { + if (mass > 0.0) + { + mass -= metabolism_rate * mass; + } + else + { + mass = 0.0; + kill(); + } + } +}; + +class Rabbit: public Animal +{ +public: + Rabbit(double metabolism_rate, double mass, double energy) : Animal(0.01, mass, energy) {} + + virtual void eat(Creature* creature) + { + if (dynamic_cast(creature) + != nullptr && creature->isAlive()) + { + std::cout << "Rabbit eats the plant" << std::endl; + mass += creature->nutrition(); + creature->harvest(); + } + } + + virtual void harvest() + { + kill(); + mass = 0; + } +}; + +class Fox : public Animal +{ +public: + Fox(double metabolism_rate, double mass, double energy) : Animal(0.05, mass, energy) {} + + virtual void eat(Creature* creature) + { + if (dynamic_cast(creature) != nullptr + && creature->isAlive()) + { + std::cout << "Fox eats the rabbit" << std::endl; + mass += creature->nutrition(); + creature->harvest(); + } + } + + virtual void harvest() + { + kill(); + mass = 0; + } + +}; + +class Forest +{ +private: + Creature** creatures; + unsigned int current_creatures; + unsigned int max_creatures; +public: + Forest(int max_creatures) : current_creatures(0), max_creatures(max_creatures), creatures(new Creature* [max_creatures]) {} + + void addCreature(Creature* creature) + { + if (current_creatures < max_creatures) + { + creatures[current_creatures] = creature; + current_creatures++; + } + } + + ~Forest() + { + for (unsigned int i = 0; i < current_creatures; i++) + { + delete creatures[i]; + } + delete[] creatures; + } + + void printForest() + { + for (unsigned int i = 0; i < current_creatures; i++) + { + if (dynamic_cast(creatures[i]) + !=nullptr) + { + std::cout << "There is a plant\n"; + } + else if (dynamic_cast(creatures[i]) + != nullptr) + { + std::cout << "There is a rabbit\n"; + } + else if (dynamic_cast(creatures[i]) + != nullptr) + { + std::cout << "There is a fox\n"; + } + } + } + + void simulate() + { + for (unsigned int i = 0; i < current_creatures; i++) + { + Animal* animal = dynamic_cast(creatures[i]); + if (animal != nullptr) + { + for (unsigned int j = 0; j < current_creatures; j++) + { + animal->eat(creatures[j]); + } + + } + } + } +}; + + + +void forestProgram() +{ + Forest* forest = new Forest(40); + forest->addCreature(new Plant(0.4, 1, 100)); + forest->addCreature(new Plant(0.4, 1, 100)); + forest->addCreature(new Plant(0.4, 1, 100)); + forest->addCreature(new Rabbit(0.4, 1, 100)); + forest->addCreature(new Rabbit(0.4, 1, 100)); + forest->addCreature(new Fox(0.4, 1, 100)); + forest->printForest(); + forest->simulate(); + delete forest; +} + +int main(int argc, char** argv) +{ + forestProgram(); + _CrtDumpMemoryLeaks(); + return 0; +} diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/ForestExample/ForestExample.vcxproj b/SZE/OODB/kyberszittya/Rec5/Recitation5/ForestExample/ForestExample.vcxproj new file mode 100644 index 00000000..ffe21b83 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec5/Recitation5/ForestExample/ForestExample.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {B831124B-D3E1-4494-A5DC-890F553191BC} + Win32Proj + ForestExample + 8.1 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/HouseSensors/HouseSensors.cpp b/SZE/OODB/kyberszittya/Rec5/Recitation5/HouseSensors/HouseSensors.cpp new file mode 100644 index 00000000..20d05589 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec5/Recitation5/HouseSensors/HouseSensors.cpp @@ -0,0 +1,17 @@ +// HouseSensors.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include + +class Sensor +{ +protected: + double meas_value; +public: + void measureValue +}; + +int main() +{ + std::cout << "Hello World!\n"; +} diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/HouseSensors/HouseSensors.vcxproj b/SZE/OODB/kyberszittya/Rec5/Recitation5/HouseSensors/HouseSensors.vcxproj new file mode 100644 index 00000000..ca6b4bf0 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec5/Recitation5/HouseSensors/HouseSensors.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {7159CE49-4575-49C8-A1D4-AB9A444835E3} + Win32Proj + HouseSensors + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/Recitation5.sln b/SZE/OODB/kyberszittya/Rec5/Recitation5/Recitation5.sln new file mode 100644 index 00000000..1ea69b10 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec5/Recitation5/Recitation5.sln @@ -0,0 +1,91 @@ +ďťż +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27428.2027 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ForestExample", "ForestExample\ForestExample.vcxproj", "{B831124B-D3E1-4494-A5DC-890F553191BC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrainLineStl", "TrainLine\TrainLine.vcxproj", "{3793D3E2-2F68-4482-9F1B-74F7AE43B25F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SensorNetwork", "SensorNetwork\SensorNetwork.vcxproj", "{9DB3C5CB-A3DF-4351-87C9-1DF2F6B0D99C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AquariumDynamicCast", "AquariumDynamicCast\AquariumDynamicCast.vcxproj", "{6F52EC43-15C7-4776-852D-094A336E42BA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RobotInteraction", "RobotInteraction\RobotInteraction.vcxproj", "{6941EAFB-1DAF-414F-BC5D-931C9E079A4A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SphereList", "SphereList\SphereList.vcxproj", "{274B5DA9-CDA3-40DA-8C49-9C5FE91C43E1}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StlListExample", "StlListExample\StlListExample.vcxproj", "{41E10F93-C9C5-4786-9962-954A26720A0E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B831124B-D3E1-4494-A5DC-890F553191BC}.Debug|x64.ActiveCfg = Debug|x64 + {B831124B-D3E1-4494-A5DC-890F553191BC}.Debug|x64.Build.0 = Debug|x64 + {B831124B-D3E1-4494-A5DC-890F553191BC}.Debug|x86.ActiveCfg = Debug|Win32 + {B831124B-D3E1-4494-A5DC-890F553191BC}.Debug|x86.Build.0 = Debug|Win32 + {B831124B-D3E1-4494-A5DC-890F553191BC}.Release|x64.ActiveCfg = Release|x64 + {B831124B-D3E1-4494-A5DC-890F553191BC}.Release|x64.Build.0 = Release|x64 + {B831124B-D3E1-4494-A5DC-890F553191BC}.Release|x86.ActiveCfg = Release|Win32 + {B831124B-D3E1-4494-A5DC-890F553191BC}.Release|x86.Build.0 = Release|Win32 + {3793D3E2-2F68-4482-9F1B-74F7AE43B25F}.Debug|x64.ActiveCfg = Debug|x64 + {3793D3E2-2F68-4482-9F1B-74F7AE43B25F}.Debug|x64.Build.0 = Debug|x64 + {3793D3E2-2F68-4482-9F1B-74F7AE43B25F}.Debug|x86.ActiveCfg = Debug|Win32 + {3793D3E2-2F68-4482-9F1B-74F7AE43B25F}.Debug|x86.Build.0 = Debug|Win32 + {3793D3E2-2F68-4482-9F1B-74F7AE43B25F}.Release|x64.ActiveCfg = Release|x64 + {3793D3E2-2F68-4482-9F1B-74F7AE43B25F}.Release|x64.Build.0 = Release|x64 + {3793D3E2-2F68-4482-9F1B-74F7AE43B25F}.Release|x86.ActiveCfg = Release|Win32 + {3793D3E2-2F68-4482-9F1B-74F7AE43B25F}.Release|x86.Build.0 = Release|Win32 + {9DB3C5CB-A3DF-4351-87C9-1DF2F6B0D99C}.Debug|x64.ActiveCfg = Debug|x64 + {9DB3C5CB-A3DF-4351-87C9-1DF2F6B0D99C}.Debug|x64.Build.0 = Debug|x64 + {9DB3C5CB-A3DF-4351-87C9-1DF2F6B0D99C}.Debug|x86.ActiveCfg = Debug|Win32 + {9DB3C5CB-A3DF-4351-87C9-1DF2F6B0D99C}.Debug|x86.Build.0 = Debug|Win32 + {9DB3C5CB-A3DF-4351-87C9-1DF2F6B0D99C}.Release|x64.ActiveCfg = Release|x64 + {9DB3C5CB-A3DF-4351-87C9-1DF2F6B0D99C}.Release|x64.Build.0 = Release|x64 + {9DB3C5CB-A3DF-4351-87C9-1DF2F6B0D99C}.Release|x86.ActiveCfg = Release|Win32 + {9DB3C5CB-A3DF-4351-87C9-1DF2F6B0D99C}.Release|x86.Build.0 = Release|Win32 + {6F52EC43-15C7-4776-852D-094A336E42BA}.Debug|x64.ActiveCfg = Debug|x64 + {6F52EC43-15C7-4776-852D-094A336E42BA}.Debug|x64.Build.0 = Debug|x64 + {6F52EC43-15C7-4776-852D-094A336E42BA}.Debug|x86.ActiveCfg = Debug|Win32 + {6F52EC43-15C7-4776-852D-094A336E42BA}.Debug|x86.Build.0 = Debug|Win32 + {6F52EC43-15C7-4776-852D-094A336E42BA}.Release|x64.ActiveCfg = Release|x64 + {6F52EC43-15C7-4776-852D-094A336E42BA}.Release|x64.Build.0 = Release|x64 + {6F52EC43-15C7-4776-852D-094A336E42BA}.Release|x86.ActiveCfg = Release|Win32 + {6F52EC43-15C7-4776-852D-094A336E42BA}.Release|x86.Build.0 = Release|Win32 + {6941EAFB-1DAF-414F-BC5D-931C9E079A4A}.Debug|x64.ActiveCfg = Debug|x64 + {6941EAFB-1DAF-414F-BC5D-931C9E079A4A}.Debug|x64.Build.0 = Debug|x64 + {6941EAFB-1DAF-414F-BC5D-931C9E079A4A}.Debug|x86.ActiveCfg = Debug|Win32 + {6941EAFB-1DAF-414F-BC5D-931C9E079A4A}.Debug|x86.Build.0 = Debug|Win32 + {6941EAFB-1DAF-414F-BC5D-931C9E079A4A}.Release|x64.ActiveCfg = Release|x64 + {6941EAFB-1DAF-414F-BC5D-931C9E079A4A}.Release|x64.Build.0 = Release|x64 + {6941EAFB-1DAF-414F-BC5D-931C9E079A4A}.Release|x86.ActiveCfg = Release|Win32 + {6941EAFB-1DAF-414F-BC5D-931C9E079A4A}.Release|x86.Build.0 = Release|Win32 + {274B5DA9-CDA3-40DA-8C49-9C5FE91C43E1}.Debug|x64.ActiveCfg = Debug|x64 + {274B5DA9-CDA3-40DA-8C49-9C5FE91C43E1}.Debug|x64.Build.0 = Debug|x64 + {274B5DA9-CDA3-40DA-8C49-9C5FE91C43E1}.Debug|x86.ActiveCfg = Debug|Win32 + {274B5DA9-CDA3-40DA-8C49-9C5FE91C43E1}.Debug|x86.Build.0 = Debug|Win32 + {274B5DA9-CDA3-40DA-8C49-9C5FE91C43E1}.Release|x64.ActiveCfg = Release|x64 + {274B5DA9-CDA3-40DA-8C49-9C5FE91C43E1}.Release|x64.Build.0 = Release|x64 + {274B5DA9-CDA3-40DA-8C49-9C5FE91C43E1}.Release|x86.ActiveCfg = Release|Win32 + {274B5DA9-CDA3-40DA-8C49-9C5FE91C43E1}.Release|x86.Build.0 = Release|Win32 + {41E10F93-C9C5-4786-9962-954A26720A0E}.Debug|x64.ActiveCfg = Debug|x64 + {41E10F93-C9C5-4786-9962-954A26720A0E}.Debug|x64.Build.0 = Debug|x64 + {41E10F93-C9C5-4786-9962-954A26720A0E}.Debug|x86.ActiveCfg = Debug|Win32 + {41E10F93-C9C5-4786-9962-954A26720A0E}.Debug|x86.Build.0 = Debug|Win32 + {41E10F93-C9C5-4786-9962-954A26720A0E}.Release|x64.ActiveCfg = Release|x64 + {41E10F93-C9C5-4786-9962-954A26720A0E}.Release|x64.Build.0 = Release|x64 + {41E10F93-C9C5-4786-9962-954A26720A0E}.Release|x86.ActiveCfg = Release|Win32 + {41E10F93-C9C5-4786-9962-954A26720A0E}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2B331114-8BC2-4DBC-A0F2-FF7D28BD7B17} + EndGlobalSection +EndGlobal diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/SensorNetwork/SensorNetwork.cpp b/SZE/OODB/kyberszittya/Rec5/Recitation5/SensorNetwork/SensorNetwork.cpp new file mode 100644 index 00000000..366c5bb8 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec5/Recitation5/SensorNetwork/SensorNetwork.cpp @@ -0,0 +1,128 @@ +// SensorNetwork.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include +#include +#include +#include + +#define _CRTDBG_MAP_ALLOC +#include +#include + +class Sensor +{ +private: + std::list values; + const std::string name; +public: + Sensor(const std::string name) : name(name) {} + + virtual void measure() = 0; + + void printValues() + { + for (const auto& v : values) + { + std::cout << v << '\n'; + } + } + + std::string getName() const + { + return name; + } +}; + +class TemperatureSensor: public Sensor +{ +private: + double temperature; + +public: + TemperatureSensor(const std::string name): Sensor(name){} + + double getTemperature() + { + return temperature; + } + + virtual void measure() + { + temperature = 0.0; + } +}; + +class PressureSensor : public Sensor +{ +private: + double pressure; +public: + PressureSensor(const std::string name) : Sensor(name) {} + + virtual void measure() + { + pressure = 0.0; + } + + double getPressure() + { + return pressure; + } +}; + +class Network +{ +private: + std::string name; + std::map sensors; +public: + Network(std::string name): name(name){} + + void addSensor(Sensor* sensor) + { + sensors[sensor->getName()] = sensor; + } + + ~Network() + { + for (const auto& a : sensors) + { + delete a.second; + } + } + + void printCurrentValues() + { + for (const auto& a : sensors) + { + std::cout << a.first << '\t'; + if (dynamic_cast(a.second) != nullptr) + { + std::cout << dynamic_cast(a.second)->getTemperature(); + } + else if (dynamic_cast(a.second) != nullptr) + { + std::cout << dynamic_cast(a.second)->getPressure(); + } + std::cout << '\n'; + } + } +}; + + +void clsuterExample() +{ + Network network("Home"); + network.addSensor(new TemperatureSensor("BMP110")); + network.addSensor(new PressureSensor("PRES22")); + network.addSensor(new TemperatureSensor("BMP111_2")); + network.printCurrentValues(); +} + +int main(int argc, char**argv) +{ + clsuterExample(); + _CrtDumpMemoryLeaks(); + return 0; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/SensorNetwork/SensorNetwork.vcxproj b/SZE/OODB/kyberszittya/Rec5/Recitation5/SensorNetwork/SensorNetwork.vcxproj new file mode 100644 index 00000000..2f477dfd --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec5/Recitation5/SensorNetwork/SensorNetwork.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {9DB3C5CB-A3DF-4351-87C9-1DF2F6B0D99C} + Win32Proj + SensorNetwork + 8.1 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/SphereList/SphereList.cpp b/SZE/OODB/kyberszittya/Rec5/Recitation5/SphereList/SphereList.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cdb0b7c038af497e4ef9f9df2e4babcfa0b1664c GIT binary patch literal 2938 zcmcJRUr!T36vgjrP5cfkB+^0zCB_Fp6NJQ=KqO*(QA4)d0*!5Hw%Zy)`0DEK%yhc5 z;+6z!n(6M&+&^dTJ@?N1`nhFWme{F{?9#fHGmflhV=HXaGG<4t?l2BnIcH_abIf<) z|#A3K3!{Ci}}}#=eFx?+|HhN5tK~unUDR~A?7#MoNN*$&!5HCT8^u+{U&iLy|wJdZr%PL9!Ia~bJHLf zVxcmT!{4OhEwS}`XZ-#fGgNh1IdIukZdHqMw3d^RbU_}1??pLC9lwMvg=_xne@8mS zo8ntO>ti{EJv}&=z_?IhC*& ziyvb~?kqL!C9w)fOEi*HUNv(@y{9n#JE+uef8eKD4KJwUO-5@8wq7mG()K@CDp~fY z6<=>U6T+F&BueU~_hm=xJ=c?zV}A-HZpQb*YV_Mg`hwM=YWfZM%Y2*jE_dlizi<9=@RQ?Exs46}z6p-6UhzL_w9W8^{?$ zXK(@Xz(mz|lZduVSsxPTKEDw%`8=bIdB4y}uqb-((OW~p_p1zR;+rzDGS5Uf1!Sv> zFLe#^RgqqVIPMK4>crtrmW+H%1j0?R4t>n1RR)mlFBN(dlm%Cx*O`Ibx6hr?EM(e1K6({?-B1QU3xsLe%VfDzv``^ymbX^ FzX2F~wNU^7 literal 0 HcmV?d00001 diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/SphereList/SphereList.vcxproj b/SZE/OODB/kyberszittya/Rec5/Recitation5/SphereList/SphereList.vcxproj new file mode 100644 index 00000000..204b4ef5 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec5/Recitation5/SphereList/SphereList.vcxproj @@ -0,0 +1,165 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {274B5DA9-CDA3-40DA-8C49-9C5FE91C43E1} + Win32Proj + SphereList + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + Create + Create + Create + Create + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/StlListExample/StlListExample.cpp b/SZE/OODB/kyberszittya/Rec5/Recitation5/StlListExample/StlListExample.cpp new file mode 100644 index 0000000000000000000000000000000000000000..42c31951ce9c8a905eedfe2637f5db5f748aee25 GIT binary patch literal 1650 zcmb`H-A=+l5QXQqCcZ-x6H|-R*UH#5(7ieQih=!D% z?#`T@_yC!{`m>fxSvS$%uL(&?xB&p;mA($zJjd!0l?`VQ3H!u2vH zPJE>7h#8$^M7@(^%9`2(=wti9=Xx)c5f!MjAqbkqgiK=Gqh#cNWMABc>dL(&)^Jm+ zt0u8F9;eh>m&tp?FtREtuV&bvgVO>j+QDC4Jq>CNy+*YxC$%T)*3U88(etkCfeDWi z=B*iRG}J4mE&k&z#rPPnt_Uqjxj8J%m~6dfVmsL}p`a)~pH-m^WeU%x#=g_1s?u4g zLtjP;t5;4-dh1lai7xre9nRNEuI@MCegPNHXjVMxYsoFCASQN>_S#N+mrjL^KO>&~ zJL1K^BdXWmy7tNlw`H=W8QqZ!7@RVLV{RjV4_8_D6OGn0jhH}~s%|VH#LTtB|C0N) i9ADO}_u9nk-bv9$S!urFps^TS{mP1N7cpL&^8EpAW(HCK literal 0 HcmV?d00001 diff --git a/SZE/OODB/kyberszittya/Rec5/Recitation5/StlListExample/StlListExample.vcxproj b/SZE/OODB/kyberszittya/Rec5/Recitation5/StlListExample/StlListExample.vcxproj new file mode 100644 index 00000000..c3573ee4 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec5/Recitation5/StlListExample/StlListExample.vcxproj @@ -0,0 +1,166 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {41E10F93-C9C5-4786-9962-954A26720A0E} + Win32Proj + StlListExample + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + + Console + true + + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + Create + Create + Create + Create + + + + + + + \ No newline at end of file From f477bbdff509f34116f8352cc749689517dbe37b Mon Sep 17 00:00:00 2001 From: Hajdu Csaba Date: Mon, 21 Oct 2019 12:22:51 +0200 Subject: [PATCH 08/14] Add files via upload --- SZE/OODB/kyberszittya/feladatok.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 SZE/OODB/kyberszittya/feladatok.txt diff --git a/SZE/OODB/kyberszittya/feladatok.txt b/SZE/OODB/kyberszittya/feladatok.txt new file mode 100644 index 00000000..be048f76 --- /dev/null +++ b/SZE/OODB/kyberszittya/feladatok.txt @@ -0,0 +1,14 @@ +Feladat #1: STL tárolók: bank nyilvántartás +- Ügyfelek: név, születési dátum, letét év, betett összeg kamatláb. +- Kérdezzük le a nyilvántartott ügyfelekre: átlag letét, maximális letét, mnimális letét +- Lehessen lekérdezni név szerint az ügyfeleket. MAP! + +Feladat #2: Vasúti menetrend +- Vonalaink vannak +- Tárold el az vonalon érintett állomásokat: város, kapacitas. + Háromféle állomás lehet: teherállomás, személyállomás és központi +- Egy állomást több vonal is érinthet. Hogyan érdemes ezt tárolni? MUTATÓK! +- Egy állomásból elérhető-e egy másik állomás közvetlenül. Azon az állomáson személyként leszállhatunk-e? +- Legyen három vonalunk, vonalanként 5-6 állomással +- Tároljuk el az állomásokat és a vonalakat is fájlban. +- Szeretnénk azt megtudni, miképp érhető el átszállásokkal egyik állomásból egy másik állomás \ No newline at end of file From c87d4861f4d9365720a287422a3639999f59966a Mon Sep 17 00:00:00 2001 From: Hajdu Csaba Date: Mon, 28 Oct 2019 13:03:51 +0100 Subject: [PATCH 09/14] Add files via upload --- .../rec7_feladatok_orai_1_lambda_kifejezesek.txt | 14 ++++++++++++++ ...c7_feladatok_orai_2_template_vector_matrix.txt | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 SZE/OODB/kyberszittya/rec7_feladatok_orai_1_lambda_kifejezesek.txt create mode 100644 SZE/OODB/kyberszittya/rec7_feladatok_orai_2_template_vector_matrix.txt diff --git a/SZE/OODB/kyberszittya/rec7_feladatok_orai_1_lambda_kifejezesek.txt b/SZE/OODB/kyberszittya/rec7_feladatok_orai_1_lambda_kifejezesek.txt new file mode 100644 index 00000000..80690d2d --- /dev/null +++ b/SZE/OODB/kyberszittya/rec7_feladatok_orai_1_lambda_kifejezesek.txt @@ -0,0 +1,14 @@ +Órai feladat +1. Legyen egy fájl amiben a következő formátumban vannak tárolva az emberek: +Keresztnév Családnév Nem Nemzetiség Foglalkozás + +Készíts programot, ami beolvassa az embereket a fájlból és eltárolja egy std::vector-ban! TIPP: érdemes stringstream-et használni + +2. A beolvasott vectorban keress rá az std::count_if segítségével egy adott foglalkozásra (pl.: Engineer, Medic) és számold össze őket. + +3. A beolvasott vectorban rendezd családnév szerint az embereket az std::sort függvény segítségével! + +A következő include-ok kellenek: algorithm, sstream, fstream + +A következő függvények, fogalmak használata van fókuszban: +lambda kifejezés, algorithm könyvtár, std::sort, std::count_if \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/rec7_feladatok_orai_2_template_vector_matrix.txt b/SZE/OODB/kyberszittya/rec7_feladatok_orai_2_template_vector_matrix.txt new file mode 100644 index 00000000..6274ac2d --- /dev/null +++ b/SZE/OODB/kyberszittya/rec7_feladatok_orai_2_template_vector_matrix.txt @@ -0,0 +1,15 @@ +2. órai feladat + +Készíts egy programot, ami definiálja a 3 dimenziós vectorokat (Vector3) és 3x3-as mátrixokat (Matrix3): +1. Template-ket használj! Működjön double-re és float-ra egyaránt! +2. A következő operátorok legyenek túlterhelve a Vector3 osztályon más Vector3 osztályokon: +=, +,-,*,/, ==, !=, [] +3. A követekző operátorok Matrix3 és Matrix3 között: +, * +4. A következő operátorok Matrix3 és Vector3 között: * + +BÓNUSZ: Származtass egy RotZ mátrixot a Matrix3 mátrixból! +Emlékeztető, RotZ: +[ cos(theta) sin(theta) 0] +[ -sin(tehta) cos(theta) 0] +[ 0 0 1] + +Fókusz: template, operátor túlterhelés \ No newline at end of file From 5a9b613c969597672995fd036b6c03ddda88d5f6 Mon Sep 17 00:00:00 2001 From: Hajdu Csaba Date: Mon, 28 Oct 2019 13:05:45 +0100 Subject: [PATCH 10/14] Rec7 first segment Rec 7 first segment --- .../FunctorExample/FunctorExample.cpp | 85 +++++++++ .../FunctorExample/FunctorExample.vcxproj | 159 +++++++++++++++++ .../Recitation7/SortPeople/SortPeople.cpp | 160 +++++++++++++++++ .../Recitation7/SortPeople/SortPeople.vcxproj | 162 ++++++++++++++++++ 4 files changed, 566 insertions(+) create mode 100644 SZE/OODB/kyberszittya/Rec7/Recitation7/FunctorExample/FunctorExample.cpp create mode 100644 SZE/OODB/kyberszittya/Rec7/Recitation7/FunctorExample/FunctorExample.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec7/Recitation7/SortPeople/SortPeople.cpp create mode 100644 SZE/OODB/kyberszittya/Rec7/Recitation7/SortPeople/SortPeople.vcxproj diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/FunctorExample/FunctorExample.cpp b/SZE/OODB/kyberszittya/Rec7/Recitation7/FunctorExample/FunctorExample.cpp new file mode 100644 index 00000000..f282492e --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/FunctorExample/FunctorExample.cpp @@ -0,0 +1,85 @@ +// FunctorExample.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include +#include + +#include + +template void apply(std::vector& vec, F func) +{ + for (unsigned int i = 0; i < vec.size(); i++) + { + vec[i] = func(vec[i]); + } +} + +class TransformerObject +{ +private: + int val; +public: + TransformerObject(int val) : val(val) {} + int operator()(int x) + { + return val * std::exp2(std::sqrt(x)); + } +}; + +int main() +{ + std::random_device rnd_device; + std::mt19937 mersenne_engine{ rnd_device() }; // Generates random integers + std::uniform_int_distribution dist{ 1, 52 }; + + std::vector vec(20); + auto gen = [&dist, &mersenne_engine]() { + return dist(mersenne_engine); + }; + std::generate(std::begin(vec), std::end(vec), gen); + + for (const auto& v : vec) + { + std::cout << v << ' '; + } + std::cout << '\n'; + + auto sqr = [](int vec) { + return vec * vec; + }; + + apply(vec, sqr); + for (const auto& v : vec) + { + std::cout << v << ' '; + } + std::cout << '\n'; + auto modulus95 = [](int vec) { + return vec % 95; + }; + apply(vec, modulus95); + for (const auto& v : vec) + { + std::cout << v << ' '; + } + std::cout << '\n'; + // Apply transformer object + TransformerObject transformerobject(-3); + apply(vec, transformerobject); + for (const auto& v : vec) + { + std::cout << v << ' '; + } + std::cout << '\n'; +} + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/FunctorExample/FunctorExample.vcxproj b/SZE/OODB/kyberszittya/Rec7/Recitation7/FunctorExample/FunctorExample.vcxproj new file mode 100644 index 00000000..ec380f94 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/FunctorExample/FunctorExample.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {89289290-54F5-4BA0-98E1-97174B62E88B} + Win32Proj + FunctorExample + 10.0.16299.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/SortPeople/SortPeople.cpp b/SZE/OODB/kyberszittya/Rec7/Recitation7/SortPeople/SortPeople.cpp new file mode 100644 index 00000000..bdd727b1 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/SortPeople/SortPeople.cpp @@ -0,0 +1,160 @@ +// SortPeople.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include +#include +#include +#include +#include +#include + +enum Gender { MALE, FEMALE }; + +class Person +{ +private: + std::string first_name; + std::string last_name; + + Gender gender; + std::string nationality; + std::string occupation; +public: + Person(const std::string first_name, const std::string last_name, const Gender gender, const std::string nationality, const std::string occupation): + first_name(first_name), + last_name(last_name), + gender(gender), + nationality(nationality), + occupation(occupation){} + + Person(const Person& other): + first_name(other.first_name), + last_name(other.last_name), + gender(other.gender), + nationality(other.nationality), + occupation(other.occupation) {} + + Person& operator=(const Person& other) + { + first_name = other.first_name; + last_name = other.last_name; + gender = other.gender; + nationality = other.nationality; + occupation = other.occupation; + return *this; + } + + const std::string getOccupation() + { + return occupation; + } + + const std::string getLastName() + { + return last_name; + } + + friend std::ostream& operator<<(std::ostream& os, const Person& person); + friend bool sortByLastName(Person& p0, Person& p1); +}; + +bool sortByLastName(Person& p0, Person& p1) +{ + return p0.last_name.at(0) < p1.last_name.at(0); +} + +std::ostream& operator<<(std::ostream& os, const Person& person) +{ + switch (person.gender) + { + case MALE: + os << person.first_name << '\t' << person.last_name << '\t' << "MALE" << '\t' << person.nationality << '\t' << person.occupation; + break; + case FEMALE: + os << person.first_name << '\t' << person.last_name << '\t' << "FEMALE" << '\t' << person.nationality << '\t' << person.occupation; + break; + default: + os << "Invalid information"; + } + + return os; +} + +int main() +{ + std::vector persons; + std::ifstream peoplefile("Persons.txt"); + if (peoplefile.is_open()) + { + std::string line; + + while (std::getline(peoplefile, line)) + { + std::stringstream ss(line); + std::string tmp_fname; + std::string tmp_lname; + std::string gender; + ss >> tmp_fname; + ss >> tmp_lname; + ss >> gender; + Gender t_gender; + if (gender.compare("Male") == 0) + { + t_gender = MALE; + } + else if (gender.compare("Female") == 0) + { + t_gender = FEMALE; + } + else + { + std::cerr << "Invalid gender" << '\n'; + break; + } + std::string nationality; + ss >> nationality; + std::string occupation; + ss >> occupation; + // Append to list + Person person(tmp_fname, tmp_lname, t_gender, + nationality, occupation); + persons.push_back(person); + } + for (const auto& v : persons) + { + std::cout << v << '\n'; + } + // Get the count of engineers + int count_engineers = std::count_if(persons.begin(), + persons.end(), [](Person& p) + { + return p.getOccupation().compare("Engineer")==0; + }); + std::cout << "Count of engineers: " << count_engineers << '\n'; + // Sort by last name + std::sort(std::begin(persons), std::end(persons), + [](Person& p0, Person& p1) + { + return sortByLastName(p0, p1); + }); + for (const auto& v : persons) + { + std::cout << v << '\n'; + } + } + else + { + std::cout << "File not found"; + } +} + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/SortPeople/SortPeople.vcxproj b/SZE/OODB/kyberszittya/Rec7/Recitation7/SortPeople/SortPeople.vcxproj new file mode 100644 index 00000000..ec20d11d --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/SortPeople/SortPeople.vcxproj @@ -0,0 +1,162 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {F1445681-EFEC-4CD3-8B0B-92FB0456FA1F} + Win32Proj + SortPeople + 10.0.16299.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file From 75d98a3a39b83441c3b948bbf4b82cd1e292d665 Mon Sep 17 00:00:00 2001 From: Hajdu Csaba Date: Mon, 28 Oct 2019 13:06:53 +0100 Subject: [PATCH 11/14] Recitation 6 Recitation 6 --- .../Recitation6/MapExample/MapExample.cpp | Bin 0 -> 2506 bytes .../Recitation6/MapExample/MapExample.vcxproj | 166 ++++++++++++++++++ .../StdAlgorithmExample.cpp | 58 ++++++ .../StdAlgorithmExample.vcxproj | 159 +++++++++++++++++ 4 files changed, 383 insertions(+) create mode 100644 SZE/OODB/kyberszittya/Rec6/Recitation6/MapExample/MapExample.cpp create mode 100644 SZE/OODB/kyberszittya/Rec6/Recitation6/MapExample/MapExample.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec6/Recitation6/StdAlgorithmExample/StdAlgorithmExample.cpp create mode 100644 SZE/OODB/kyberszittya/Rec6/Recitation6/StdAlgorithmExample/StdAlgorithmExample.vcxproj diff --git a/SZE/OODB/kyberszittya/Rec6/Recitation6/MapExample/MapExample.cpp b/SZE/OODB/kyberszittya/Rec6/Recitation6/MapExample/MapExample.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c7751a18757e6d76ef3f9f257668fad618921a45 GIT binary patch literal 2506 zcmc&$%Wl(95S^`&_y?;<)QO6dE_ju|f`?ckA$17|g~TZqC9#~OKv91kIA_M=YbQ=x zBqU@xzVRKOIdkS=|Nb?QfyDAg#!|>D`Ht&Xtj;BqR3=yz*ge7d5_e{j%N*Aw{;%XS zRx!>w)}{Qwx{!rhtgxP8T{i3{_&>*!3&oDrAN}O;G6q7f`>EWPTVOQME7x}vaRSS= zOx5EE49WJH+H~y`YpJX_H7#C%;R^Bd$)EaL zAo5%;G_DNlaVJtnQ~W!rxS7`&zNvXup+|_5I^|$Qt*78XOKM7e3+$7fD`uQ{_fw^& z`*U8&wVscF{dZn_S`!vmR7a51tDX?Ei*M3-w^wOo`Wfz(-m^7-Z8cMES#?x~`7=%1 z8NZ7?YL&s7TCo;KIGS2?J+V~YUaQpHRV3o1%5<;JRh!Lrtz7M>nWiP<+E+KuAeMfE z!|uFaAlh8jIYa!bI)X&nDo3bEkLVt%zbjkjB@)X;Gn)UUd{8Swoa|8MHRL9(YtVNN zZiQx5Q>$ZO^6PX_Iwi|F_r!!N8APO8#o<1v``7#2L* K^Jus=js5`I+<$oh literal 0 HcmV?d00001 diff --git a/SZE/OODB/kyberszittya/Rec6/Recitation6/MapExample/MapExample.vcxproj b/SZE/OODB/kyberszittya/Rec6/Recitation6/MapExample/MapExample.vcxproj new file mode 100644 index 00000000..93558cfe --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec6/Recitation6/MapExample/MapExample.vcxproj @@ -0,0 +1,166 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {FA96F99C-9BD2-4FD0-9A91-C4C94111FAA0} + Win32Proj + MapExample + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + + Console + true + + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + Create + Create + Create + Create + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec6/Recitation6/StdAlgorithmExample/StdAlgorithmExample.cpp b/SZE/OODB/kyberszittya/Rec6/Recitation6/StdAlgorithmExample/StdAlgorithmExample.cpp new file mode 100644 index 00000000..14f1cd15 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec6/Recitation6/StdAlgorithmExample/StdAlgorithmExample.cpp @@ -0,0 +1,58 @@ +// StdAlgorithmExample.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include +#include +#include + +int main() +{ + std::vector vals({ 0.1, 0.8, 0.4, 1, 2.9, 5.3, 4.1, + 1.9, 10.3, 4.7, 5.2 }); + std::vector vals; + + std::cout << "Original list: "; + for (const auto& v : vals) + { + std::cout << v << ' '; + } + std::cout << '\n'; + // Revert + std::cout << "Reversed list: "; + std::reverse(std::begin(vals), std::end(vals)); + for (const auto& v : vals) + { + std::cout << v << ' '; + } + std::cout << '\n'; + // Max + auto max_el = std::max_element(vals.begin(), vals.end()); + std::cout << "Max element: " << + vals[std::distance(vals.begin(), max_el)] << '\n'; + // Binary search + if (std::binary_search(vals.begin(), vals.end(), 10.3)) { + std::cout << "Found element\n"; + } + else + { + std::cout << "Element not found\n"; + } + // Sort + std::sort(vals.begin(), vals.end()); + std::cout << "Sorted list: "; + for (const auto& v : vals) + { + std::cout << v << ' '; + } +} + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/SZE/OODB/kyberszittya/Rec6/Recitation6/StdAlgorithmExample/StdAlgorithmExample.vcxproj b/SZE/OODB/kyberszittya/Rec6/Recitation6/StdAlgorithmExample/StdAlgorithmExample.vcxproj new file mode 100644 index 00000000..ce935be6 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec6/Recitation6/StdAlgorithmExample/StdAlgorithmExample.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {4CA21A6F-5865-4EDC-99E3-D2D0F8DBD585} + Win32Proj + StdAlgorithmExample + 8.1 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file From 3d6b1ed7d724780d3f07dec06480e4ab0699f4c4 Mon Sep 17 00:00:00 2001 From: kyberszittya Date: Sun, 3 Nov 2019 18:21:07 +0100 Subject: [PATCH 12/14] Tempalte vectors added --- .../VectorsOperatorOverloading/.gitignore | 2 + .../VectorsOperatorOverloading/Matrix3.h | 68 +++++++ .../VectorsOperatorOverloading/Vector3.h | 81 +++++++++ .../VectorMatrix.cpp | 17 ++ .../VectorsOperatorOverloading/VectorMatrix.h | 11 ++ .../VectorsOperatorOverloading/VectorN.h | 124 +++++++++++++ .../VectorsOperatorOverloading.cpp | 50 ++++++ .../VectorsOperatorOverloading.vcxproj | 166 ++++++++++++++++++ 8 files changed, 519 insertions(+) create mode 100644 SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/.gitignore create mode 100644 SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/Matrix3.h create mode 100644 SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/Vector3.h create mode 100644 SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorMatrix.cpp create mode 100644 SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorMatrix.h create mode 100644 SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorN.h create mode 100644 SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorsOperatorOverloading.cpp create mode 100644 SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorsOperatorOverloading.vcxproj diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/.gitignore b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/.gitignore new file mode 100644 index 00000000..d9b7a2c1 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/.gitignore @@ -0,0 +1,2 @@ +Debug/ +x64/ \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/Matrix3.h b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/Matrix3.h new file mode 100644 index 00000000..da65e5fd --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/Matrix3.h @@ -0,0 +1,68 @@ +#pragma once + +#include "Vector3.h" + +template class Matrix3 +{ +private: + std::vector vals; +public: + Matrix3() : vals(9) {} + Matrix3(std::initializer_list il) : vals(il) {} + Matrix3(const Matrix3& other) : vals(other.vals) {} + // Overload operator<< + friend std::ostream& operator<<(std::ostream& os, const Matrix3& v); + // Overload arithmetics + template friend Matrix3 operator+(const Matrix3& m0, const Matrix3& m1); + template friend Matrix3 operator*(const Matrix3& m0, const Matrix3& m1); + template friend Vector3 operator*(const Matrix3& m0, Vector3& v); +}; + +template Matrix3 operator+(const Matrix3& m0, const Matrix3& m1) +{ + Matrix3 res(m0); + res.vals[0] += m1.vals[0]; + res.vals[1] += m1.vals[1]; + res.vals[2] += m1.vals[2]; + res.vals[3] += m1.vals[3]; + res.vals[4] += m1.vals[4]; + res.vals[5] += m1.vals[5]; + res.vals[6] += m1.vals[6]; + res.vals[7] += m1.vals[7]; + res.vals[8] += m1.vals[8]; + return res; +} + +template Matrix3 operator*(const Matrix3& m0, const Matrix3& m1) +{ + Matrix3 res; + res.vals[0] = m0.vals[0] * m1.vals[0] + m0.vals[1] * m1.vals[3] + m0.vals[2] * m1.vals[6]; + res.vals[1] = m0.vals[0] * m1.vals[1] + m0.vals[1] * m1.vals[4] + m0.vals[2] * m1.vals[7]; + res.vals[2] = m0.vals[0] * m1.vals[2] + m0.vals[1] * m1.vals[5] + m0.vals[2] * m1.vals[8]; + + res.vals[3] = m0.vals[3] * m1.vals[0] + m0.vals[4] * m1.vals[3] + m0.vals[5] * m1.vals[6]; + res.vals[4] = m0.vals[3] * m1.vals[1] + m0.vals[4] * m1.vals[4] + m0.vals[5] * m1.vals[7]; + res.vals[5] = m0.vals[3] * m1.vals[2] + m0.vals[4] * m1.vals[5] + m0.vals[5] * m1.vals[8]; + + res.vals[6] = m0.vals[6] * m1.vals[0] + m0.vals[7] * m1.vals[3] + m0.vals[8] * m1.vals[6]; + res.vals[7] = m0.vals[6] * m1.vals[1] + m0.vals[7] * m1.vals[4] + m0.vals[8] * m1.vals[7]; + res.vals[8] = m0.vals[6] * m1.vals[2] + m0.vals[7] * m1.vals[5] + m0.vals[8] * m1.vals[8]; + + return res; +} + +template Vector3 operator*(const Matrix3& m0, Vector3& v1) +{ + Vector3 res{ + m0.vals[0] * v1[0] + m0.vals[1] * v1[1] + m0.vals[2] * v1[2], + m0.vals[3] * v1[0] + m0.vals[4] * v1[1] + m0.vals[5] * v1[2], + m0.vals[6] * v1[0] + m0.vals[7] * v1[1] + m0.vals[8] * v1[2] + }; + return res; +} + +template class RotationYaw : public Matrix3 +{ +public: + //RotationYaw(double yaw) : Matrix3({}) +}; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/Vector3.h b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/Vector3.h new file mode 100644 index 00000000..33ddb4e1 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/Vector3.h @@ -0,0 +1,81 @@ +#pragma once + +#include +#include +#include + + +template class Vector3 +{ +private: + std::vector vals; +public: + Vector3() : vals(3) { } + Vector3(std::initializer_list il) : vals(il) {} + Vector3(const Vector3& other) : vals(other.vals) + {} + + // Overload << operator + friend std::ostream& operator<<(std::ostream& os, const Vector3& v); + + template friend Vector3 operator+(const Vector3& v0, const Vector3& v1); + template friend Vector3 operator-(const Vector3& v0, const Vector3& v1); + template friend Vector3 operator*(const Vector3& v0, const Vector3& v1); + template friend Vector3 operator/(const Vector3& v0, const Vector3& v1); + template friend bool operator==(const Vector3& v0, const Vector3& v1); + template friend bool operator!=(const Vector3& v0, const Vector3& v1); + // Overload index operator + T& operator[](const int index) + { + return vals[index]; + } + // Overload addition operator + Vector3& operator+=(const Vector3& v) + { + vals[0] += v.vals[0]; + vals[1] += v.vals[1]; + vals[2] += v.vals[2]; + } + + template friend T0 dotproduct(Vector3& v0, Vector3& v1); + +}; + +template T0 dotproduct(Vector3& v0, Vector3& v1) +{ + return v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2]; +} + +template Vector3 operator+(const Vector3& v0, const Vector3& v1) +{ + Vector3 res({ v0.vals[0] + v1.vals[0], v0.vals[1] + v1.vals[1], v0.vals[2] + v1.vals[2] }); + return res; +} + +template Vector3 operator-(const Vector3& v0, const Vector3& v1) +{ + Vector3 res({ v0.vals[0] - v1.vals[0], v0.vals[1] - v1.vals[1], v0.vals[2] - v1.vals[2] }); + return res; +} + +template Vector3 operator*(const Vector3& v0, const Vector3& v1) +{ + Vector3 res({ v0.vals[0] * v1.vals[0], v0.vals[1] * v1.vals[1], v0.vals[2] * v1.vals[2] }); + return res; +} + +template Vector3 operator/(const Vector3& v0, const Vector3& v1) +{ + Vector3 res({ v0.vals[0] / v1.vals[0], v0.vals[1] / v1.vals[1], v0.vals[2] / v1.vals[2] }); + return res; +} + +template bool operator==(const Vector3& v0, const Vector3& v1) +{ + return (v0.vals[0] == v1.vals[0]) && (v0.vals[1] == v1.vals[1]) && (v0.vals[2] == v1.vals[2]); +} + +template bool operator!=(const Vector3& v0, const Vector3& v1) +{ + return (v0.vals[0] != v1.vals[0]) && (v0.vals[1] != v1.vals[1]) && (v0.vals[2] != v1.vals[2]); +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorMatrix.cpp b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorMatrix.cpp new file mode 100644 index 00000000..9dcb2476 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorMatrix.cpp @@ -0,0 +1,17 @@ +#include "VectorMatrix.h" + + +std::ostream& operator<<(std::ostream& os, const Vector3& v) +{ + os << v.vals[0] << ',' << v.vals[1] << ',' << v.vals[2]; + return os; +} + +std::ostream& operator<<(std::ostream& os, const Matrix3& v) +{ + os << v.vals[0] << ',' << v.vals[1] << ',' << v.vals[2] << '\n'; + os << v.vals[3] << ',' << v.vals[4] << ',' << v.vals[5] << '\n'; + os << v.vals[6] << ',' << v.vals[7] << ',' << v.vals[8] << '\n'; + return os; +} + diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorMatrix.h b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorMatrix.h new file mode 100644 index 00000000..13ba10e7 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorMatrix.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include +#include + + +#include "Vector3.h" +#include "Matrix3.h" + +#include "VectorN.h" \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorN.h b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorN.h new file mode 100644 index 00000000..14ec8d98 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorN.h @@ -0,0 +1,124 @@ +#pragma once + +#include + +template class VectorN +{ +private: + std::vector vals; +public: + VectorN() : vals(N) { } + VectorN(std::initializer_list il) : vals(il) {} + VectorN(const VectorN& other) : vals(other.vals) + {} + + // Overload << operator + template friend std::ostream& operator<<(std::ostream& os, VectorN& v); + + template friend VectorN operator+(const VectorN& v0, const VectorN& v1); + template friend VectorN operator-(const VectorN& v0, const VectorN& v1); + template friend VectorN operator*(const VectorN& v0, const VectorN& v1); + template friend VectorN operator/(const VectorN& v0, const VectorN& v1); + template friend bool operator==(const VectorN& v0, const VectorN& v1); + template friend bool operator!=(const VectorN& v0, const VectorN& v1); + // Overload index operator + T& operator[](const int index) + { + return vals[index]; + } + // Overload addition operator + VectorN& operator+=(const VectorN& v) + { + for (unsigned int i = 0; i < N; i++) + { + vals[i] += v.vals[i]; + + } + + } + +}; + + + +template VectorN operator+(const VectorN& v0, const VectorN& v1) +{ + VectorN res; + for (unsigned int i = 0; i < N0; i++) + { + res[i] = v0.vals[i] + v1.vals[i]; + } + + return res; +} + +template VectorN operator-(const VectorN& v0, const VectorN& v1) +{ + VectorN res; + for (unsigned int i = 0; i < N0; i++) + { + res[i] = v0.vals[i] - v1.vals[i]; + } + + return res; +} + +template VectorN operator*(const VectorN& v0, const VectorN& v1) +{ + VectorN res; + for (unsigned int i = 0; i < N0; i++) + { + res[i] = v0.vals[i] * v1.vals[i]; + } + + return res; +} + +template VectorN operator/(const VectorN& v0, const VectorN& v1) +{ + VectorN res; + for (unsigned int i = 0; i < N0; i++) + { + res[i] = v0.vals[i] / v1.vals[i]; + } + + return res; +} + +template VectorN operator==(const VectorN& v0, const VectorN& v1) +{ + bool res = true; + for (unsigned int i = 0; i < N0; i++) + { + res[i] &= v0.vals[i] == v1.vals[i]; + if (!res) { + return false; + } + } + + return true; +} + +template VectorN operator!=(const VectorN& v0, const VectorN& v1) +{ + bool res = true; + for (unsigned int i = 0; i < N0; i++) + { + res[i] &= v0.vals[i] == v1.vals[i]; + if (!res) { + return true; + } + } + + return false; +} + +template std::ostream& operator<<(std::ostream& os, VectorN& v) +{ + for (unsigned int i = 0; i < N0; i++) + { + os << v[i] << ','; + + } + return os; +} \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorsOperatorOverloading.cpp b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorsOperatorOverloading.cpp new file mode 100644 index 00000000..03537ae9 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorsOperatorOverloading.cpp @@ -0,0 +1,50 @@ +// VectorsOperatorOverloading.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include "VectorMatrix.h" + +// WARNING: this is just a representation of operator overloading. +// For performance matrix calculations, use Eigen/GLM/MKL etc. + + + + +int main() +{ + Vector3 v({ 0.4, 0.6, 0.3 }); + Vector3 v0({ 0.1, 0.3, 0.7 }); + + std::cout << v << '\n'; + std::cout << v0 << '\n'; + std::cout << v + v0 << '\n'; + std::cout << v - v0 << '\n'; + std::cout << v * v0 << '\n'; + std::cout << v / v0 << '\n'; + std::cout << (v == v0) << '\n'; + std::cout << (v == v) << '\n'; + std::cout << (v != v) << '\n'; + std::cout << v[0] << '\n'; + // Matrix3 + Matrix3 m({1.0, 2.3, 4.5, + 6.7, 8.9, 1.2, + 5.6, 7.8, 2.4}); + std::cout << m << '\n'; + std::cout << m * v << '\n'; + std::cout << dotproduct(v0, v) << '\n'; + VectorN<5, double> vec0({ 1.0, 2.0, 3.0, 4.0, 5.0 }); + VectorN<5, double> vec1({ 1.0, 2.0, 3.0, 4.0, 5.0 }); + std::cout << vec0 << '\n'; + auto n = vec0 + vec1; + std::cout << n << '\n'; +} + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorsOperatorOverloading.vcxproj b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorsOperatorOverloading.vcxproj new file mode 100644 index 00000000..bed36e0d --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorsOperatorOverloading.vcxproj @@ -0,0 +1,166 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {70787726-08C8-4FAD-ADFE-AACD2BB4B080} + Win32Proj + VectorsOperatorOverloading + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + \ No newline at end of file From ee688b2cbbe41945eb7f6cc853251e7e0ca1ce30 Mon Sep 17 00:00:00 2001 From: kyberszittya Date: Sun, 3 Nov 2019 18:26:44 +0100 Subject: [PATCH 13/14] Adding RotationYaw class as a good representation --- .../Rec7/Recitation7/VectorsOperatorOverloading/Matrix3.h | 6 +++++- .../VectorsOperatorOverloading.cpp | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/Matrix3.h b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/Matrix3.h index da65e5fd..b7d01389 100644 --- a/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/Matrix3.h +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/Matrix3.h @@ -64,5 +64,9 @@ template Vector3 operator*(const Matrix3& m0, Vector3& template class RotationYaw : public Matrix3 { public: - //RotationYaw(double yaw) : Matrix3({}) + RotationYaw(T yaw) : Matrix3({ + cos(yaw), sin(yaw), 0, + -sin(yaw), cos(yaw), 0, + 0, 0, 1 + }) {} }; \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorsOperatorOverloading.cpp b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorsOperatorOverloading.cpp index 03537ae9..0ef8b974 100644 --- a/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorsOperatorOverloading.cpp +++ b/SZE/OODB/kyberszittya/Rec7/Recitation7/VectorsOperatorOverloading/VectorsOperatorOverloading.cpp @@ -36,6 +36,8 @@ int main() std::cout << vec0 << '\n'; auto n = vec0 + vec1; std::cout << n << '\n'; + RotationYaw yaw0(0.12566); + std::cout << yaw0 << '\n'; } // Run program: Ctrl + F5 or Debug > Start Without Debugging menu From 15eb99701abfcac305944c7e0a7d17e8764ce610 Mon Sep 17 00:00:00 2001 From: Hajdu Csaba Date: Mon, 4 Nov 2019 23:36:55 +0100 Subject: [PATCH 14/14] Recitation 8 --- .../CustomIteratorExample/.gitignore | 2 + .../CustomIteratorExample.cpp | 113 +++++++++++ .../CustomIteratorExample.vcxproj | 159 +++++++++++++++ .../Recitation8/ExceptionExample/.gitignore | 2 + .../ExceptionExample/ExceptionExample.cpp | 122 ++++++++++++ .../ExceptionExample/ExceptionExample.vcxproj | 160 +++++++++++++++ .../Rec8/Recitation8/GraphBFSDFS/.gitignore | 2 + .../Recitation8/GraphBFSDFS/GraphBFSDFS.cpp | 187 ++++++++++++++++++ .../GraphBFSDFS/GraphBFSDFS.vcxproj | 159 +++++++++++++++ 9 files changed, 906 insertions(+) create mode 100644 SZE/OODB/kyberszittya/Rec8/Recitation8/CustomIteratorExample/.gitignore create mode 100644 SZE/OODB/kyberszittya/Rec8/Recitation8/CustomIteratorExample/CustomIteratorExample.cpp create mode 100644 SZE/OODB/kyberszittya/Rec8/Recitation8/CustomIteratorExample/CustomIteratorExample.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec8/Recitation8/ExceptionExample/.gitignore create mode 100644 SZE/OODB/kyberszittya/Rec8/Recitation8/ExceptionExample/ExceptionExample.cpp create mode 100644 SZE/OODB/kyberszittya/Rec8/Recitation8/ExceptionExample/ExceptionExample.vcxproj create mode 100644 SZE/OODB/kyberszittya/Rec8/Recitation8/GraphBFSDFS/.gitignore create mode 100644 SZE/OODB/kyberszittya/Rec8/Recitation8/GraphBFSDFS/GraphBFSDFS.cpp create mode 100644 SZE/OODB/kyberszittya/Rec8/Recitation8/GraphBFSDFS/GraphBFSDFS.vcxproj diff --git a/SZE/OODB/kyberszittya/Rec8/Recitation8/CustomIteratorExample/.gitignore b/SZE/OODB/kyberszittya/Rec8/Recitation8/CustomIteratorExample/.gitignore new file mode 100644 index 00000000..b6e941ce --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec8/Recitation8/CustomIteratorExample/.gitignore @@ -0,0 +1,2 @@ +x64/ +Debug/ \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec8/Recitation8/CustomIteratorExample/CustomIteratorExample.cpp b/SZE/OODB/kyberszittya/Rec8/Recitation8/CustomIteratorExample/CustomIteratorExample.cpp new file mode 100644 index 00000000..15130bc0 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec8/Recitation8/CustomIteratorExample/CustomIteratorExample.cpp @@ -0,0 +1,113 @@ +// CustomIteratorExample.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include +#include +#include + +#define _CRTDBG_MAP_ALLOC +#include +#include + +template class BlockingArray +{ +private: + std::vector data; + int current_elements; +public: + BlockingArray() : current_elements(0) { data.reserve(N); } + BlockingArray(std::initializer_list il) : data(il), current_elements(il.size()) {} + + void push(T elem) + { + if (current_elements < N) + { + data.push_back(elem); + current_elements++; + } + else + { + throw std::length_error("Array is full"); + } + } + + T pop() + { + current_elements--; + T res = data.back(); + data.pop_back(); + return res; + } + + struct iterator + { + typename std::vector::iterator t; + + iterator& operator++() + { + ++t; + return *this; + } + + bool operator==(iterator other) const + { + return t == other.t; + } + bool operator!=(iterator other) const + { + return !(*this==other); + } + + using iterator_category = std::forward_iterator_tag; + using difference_type = std::ptrdiff_t; + using value_type = T; + + using pointer = T*; + T& operator*() { return *t; } + + }; + iterator begin() { return { std::begin(data) }; } + iterator end() { return { std::end(data) }; } +}; + +void blockingArray() +{ + BlockingArray<5, double> blocking_array; + try + { + blocking_array.push(10.8); + blocking_array.push(20.0); + blocking_array.push(15.0); + blocking_array.push(16.25); + blocking_array.push(17.1); + blocking_array.push(18.0); + + } + catch (std::length_error& en) + { + std::cerr << en.what() << '\n'; + } + blocking_array.pop(); + blocking_array.pop(); + for (const auto& v : blocking_array) + { + std::cout << v << '\n'; + } +} + +int main() +{ + blockingArray(); + _CrtDumpMemoryLeaks(); +} + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/SZE/OODB/kyberszittya/Rec8/Recitation8/CustomIteratorExample/CustomIteratorExample.vcxproj b/SZE/OODB/kyberszittya/Rec8/Recitation8/CustomIteratorExample/CustomIteratorExample.vcxproj new file mode 100644 index 00000000..67b8514d --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec8/Recitation8/CustomIteratorExample/CustomIteratorExample.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {332EF184-291B-4F8D-89EB-B5A42C519340} + Win32Proj + CustomIteratorExample + 10.0.16299.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec8/Recitation8/ExceptionExample/.gitignore b/SZE/OODB/kyberszittya/Rec8/Recitation8/ExceptionExample/.gitignore new file mode 100644 index 00000000..b6e941ce --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec8/Recitation8/ExceptionExample/.gitignore @@ -0,0 +1,2 @@ +x64/ +Debug/ \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec8/Recitation8/ExceptionExample/ExceptionExample.cpp b/SZE/OODB/kyberszittya/Rec8/Recitation8/ExceptionExample/ExceptionExample.cpp new file mode 100644 index 00000000..e328f314 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec8/Recitation8/ExceptionExample/ExceptionExample.cpp @@ -0,0 +1,122 @@ +// ExceptionExample.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include +#include +#include +#include + +class PersonDatabase; + +class Person +{ +private: + const std::string name; + unsigned int age; +public: + Person(const std::string name, unsigned int age) : name(name), age(age) {} + + friend PersonDatabase; +}; + +class InvalidPersonError : public std::exception +{ +public: + InvalidPersonError(const char* message) : std::exception(message) {} +}; + +class PersonDatabase +{ +private: + std::list persons; +public: + ~PersonDatabase() + { + for (const auto& v : persons) + { + delete v; + } + } + + double averageAge() + { + if (persons.size() > 0) + { + double avg_age = 0.0; + unsigned int cnt_persons = 0; + for (const auto& v : persons) + { + avg_age += static_cast(v->age); + cnt_persons++; + } + return avg_age / static_cast(cnt_persons); + } + else + { + throw std::length_error("No persons exist in database"); + + } + } + + void addPerson(const std::string name, unsigned int age) + { + if (name.length() > 0 && age > 0) + { + persons.push_back(new Person(name, age)); + } + else + { + throw InvalidPersonError("Invalid person data"); + } + } +}; + +int main() +{ + PersonDatabase persondatabase; + do { + try + { + std::cout << "New person! " << '\n'; + std::string name; + unsigned int age; + std::cout << "Name: " ; + std::cin >> name; + std::cout << "Age: "; + std::cin >> age; + persondatabase.addPerson(name, age); + } + catch (InvalidPersonError& en) + { + std::cout << "ERROR INVALID PERSON" << '\n'; + std::cout << en.what() << '\n'; + break; + } + std::cout << "Continue? (Y/N) "; + char c; + std::cin >> c; + if (c == 'N' || c == 'n') + { + break; + } + } while (true); + try { + std::cout << "Average age: " << persondatabase.averageAge() << '\n'; + } + catch (std::length_error& e) + { + std::cout << "ERROR INVALID LENGTH" << '\n'; + std::cout << e.what() << '\n'; + } +} + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/SZE/OODB/kyberszittya/Rec8/Recitation8/ExceptionExample/ExceptionExample.vcxproj b/SZE/OODB/kyberszittya/Rec8/Recitation8/ExceptionExample/ExceptionExample.vcxproj new file mode 100644 index 00000000..a8870f91 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec8/Recitation8/ExceptionExample/ExceptionExample.vcxproj @@ -0,0 +1,160 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {3F7C7AC9-B960-4C4F-BAB7-70AF04EB2A3C} + Win32Proj + ExceptionExample + 10.0.16299.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + Sync + + + Console + true + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec8/Recitation8/GraphBFSDFS/.gitignore b/SZE/OODB/kyberszittya/Rec8/Recitation8/GraphBFSDFS/.gitignore new file mode 100644 index 00000000..b6e941ce --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec8/Recitation8/GraphBFSDFS/.gitignore @@ -0,0 +1,2 @@ +x64/ +Debug/ \ No newline at end of file diff --git a/SZE/OODB/kyberszittya/Rec8/Recitation8/GraphBFSDFS/GraphBFSDFS.cpp b/SZE/OODB/kyberszittya/Rec8/Recitation8/GraphBFSDFS/GraphBFSDFS.cpp new file mode 100644 index 00000000..8de8c2d7 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec8/Recitation8/GraphBFSDFS/GraphBFSDFS.cpp @@ -0,0 +1,187 @@ +// GraphBFSDFS.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#define _CRTDBG_MAP_ALLOC +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +class CityNode +{ +private: + const std::string name; + std::vector adjacent_cities; +public: + CityNode(const std::string name): name(name) + {} + + void addAdjacentNode(CityNode* citynode) + { + adjacent_cities.push_back(citynode); + } + + const std::vector& getAdjacentNodes() + { + return adjacent_cities; + } + + friend std::ostream& operator<<(std::ostream& os, const CityNode& node); +}; + +std::ostream& operator<<(std::ostream& os, const CityNode& node) +{ + os << node.name; + return os; +} + +class MapGraph +{ +private: + std::vector nodes; + std::map maps; +public: + MapGraph(){} + + ~MapGraph() + { + for (const auto& v : nodes) + { + delete v; + } + } + + MapGraph(std::initializer_list il) + { + for (const auto& v : il) + { + CityNode* node = new CityNode(v); + nodes.push_back(node); + maps[v] = node; + } + } + + void addNode(const std::string &name) + { + CityNode* node = new CityNode(name); + nodes.push_back(node); + maps[name] = node; + } + + void addAdjacency(const std::string &from, const std::string &to) + { + maps[from]->addAdjacentNode(maps[to]); + maps[to]->addAdjacentNode(maps[from]); + } + + CityNode* getCity(const std::string& name) + { + return maps[name]; + } +}; + + +template void breadthFirstSearch(MapGraph& graph, CityNode* start, Proc p) +{ + std::queue fringe; + + std::unordered_set visited_nodes; + visited_nodes.insert(start); + fringe.push(start); + + while (!fringe.empty()) + { + CityNode* current_node = fringe.front(); + fringe.pop(); + // On visit execute proc + p(current_node); + for (auto v: current_node->getAdjacentNodes()) + { + if (visited_nodes.find(v) == visited_nodes.end()) + { + visited_nodes.insert(v); + fringe.push(v); + } + + } + } +} + +template void depthFirstSearch(MapGraph& graph, CityNode* start, Proc p) +{ + std::stack fringe; + + std::unordered_set visited_nodes; + fringe.push(start); + + while (!fringe.empty()) + { + CityNode* current_node = fringe.top(); + fringe.pop(); + if (visited_nodes.find(current_node) == visited_nodes.end()) + { + visited_nodes.insert(current_node); + // On visit execute proc + p(current_node); + for (auto v : current_node->getAdjacentNodes()) + { + fringe.push(v); + } + } + + } +} + +void graphExample() +{ + MapGraph graph({ "Budapest", "Zalaegerszeg", "Szombathely", "Miskolc", "Gyor", + "Veszprem", "Szeged", "Kecskemet", "Szabadka", "Szekszard", "Szolnok", "Mosonmagyarovar", + "Rajka", "Bratislava" }); + graph.addAdjacency("Budapest", "Gyor"); + graph.addAdjacency("Budapest", "Miskolc"); + graph.addAdjacency("Budapest", "Kecskemet"); + graph.addAdjacency("Budapest", "Veszprem"); + graph.addAdjacency("Budapest", "Szolnok"); + graph.addAdjacency("Veszprem", "Gyor"); + graph.addAdjacency("Veszprem", "Zalaegerszeg"); + graph.addAdjacency("Kecskemet", "Szeged"); + graph.addAdjacency("Kecskemet", "Szolnok"); + graph.addAdjacency("Szeged", "Szabadka"); + graph.addAdjacency("Szeged", "Szekszard"); + graph.addAdjacency("Miskolc", "Szolnok"); + graph.addAdjacency("Gyor", "Szombathely"); + graph.addAdjacency("Gyor", "Mosonmagyarovar"); + graph.addAdjacency("Mosonmagyarovar", "Rajka"); + graph.addAdjacency("Rajka", "Bratislava"); + auto printNode = [](CityNode* node) { + std::cout << *node << '\n'; + }; + std::cout << '\n' << "Breadth first search" << std::endl; + breadthFirstSearch(graph, graph.getCity("Budapest"), printNode); + std::cout << '\n' << "Depth first search" << '\n'; + depthFirstSearch(graph, graph.getCity("Budapest"), printNode); +} + +int main() +{ + graphExample(); + _CrtDumpMemoryLeaks(); +} + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/SZE/OODB/kyberszittya/Rec8/Recitation8/GraphBFSDFS/GraphBFSDFS.vcxproj b/SZE/OODB/kyberszittya/Rec8/Recitation8/GraphBFSDFS/GraphBFSDFS.vcxproj new file mode 100644 index 00000000..83082540 --- /dev/null +++ b/SZE/OODB/kyberszittya/Rec8/Recitation8/GraphBFSDFS/GraphBFSDFS.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {611C943B-144A-4C2C-86FA-DE9845BFDE81} + Win32Proj + GraphBFSDFS + 10.0.16299.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file