From 26d8361a1878be666ed19599530d7c79d6d14efe Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Sat, 19 Jun 2021 01:15:56 +0300 Subject: [PATCH] lesson 1 --- lesson_1/exercise_1.hpp | 21 ++++++++++++++++++++ lesson_1/exercise_2.hpp | 23 +++++++++++++++++++++ lesson_1/exercise_3.hpp | 44 +++++++++++++++++++++++++++++++++++++++++ lesson_1/main.cpp | 42 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+) create mode 100644 lesson_1/exercise_1.hpp create mode 100644 lesson_1/exercise_2.hpp create mode 100644 lesson_1/exercise_3.hpp create mode 100644 lesson_1/main.cpp diff --git a/lesson_1/exercise_1.hpp b/lesson_1/exercise_1.hpp new file mode 100644 index 0000000..9ca419c --- /dev/null +++ b/lesson_1/exercise_1.hpp @@ -0,0 +1,21 @@ +#include + +class Power +{ +private: + float a = 0; + float b = 0; +public: + Power() {} + + void set(float num_a, float num_b) + { + a = num_a; + b = num_b; + } + + float calculate() + { + return pow(a, b); + } +}; diff --git a/lesson_1/exercise_2.hpp b/lesson_1/exercise_2.hpp new file mode 100644 index 0000000..e912502 --- /dev/null +++ b/lesson_1/exercise_2.hpp @@ -0,0 +1,23 @@ +#include +#include + +class RGBA +{ +private: + std::uint8_t m_red; + std::uint8_t m_green; + std::uint8_t m_blue; + std::uint8_t m_alpha; +public: + RGBA(std::uint8_t red = 0, std::uint8_t green = 0, std::uint8_t blue = 0, std::uint8_t alpha = 255) : + m_red(red), m_green(green), m_blue(blue), m_alpha(alpha) {} + + void print() + { + std::cout << "r=" << static_cast(m_red) << + " g=" << static_cast(m_green) << + " b=" << static_cast(m_blue) << + " a=" << static_cast(m_alpha) << std::endl; + } + +}; diff --git a/lesson_1/exercise_3.hpp b/lesson_1/exercise_3.hpp new file mode 100644 index 0000000..a17ece2 --- /dev/null +++ b/lesson_1/exercise_3.hpp @@ -0,0 +1,44 @@ +#include + +class Stack +{ +private: + int array[10]; + int length = 0; + +public: + Stack() {} + + void reset() + { + while (length) + array[length--] = 0; + } + + bool push(int num) + { + if (length > 9) + return false; + else + array[length++] = num; + + return true; + } + + int pop() + { + if (length) + return array[length--]; + else + std::cout << "Stack is empty!" << std::endl; + + return -1; + } + + void print() + { + for (int i = 0; i < length; i++) + std::cout << array[i] << ' '; + std::cout << std::endl; + } +}; diff --git a/lesson_1/main.cpp b/lesson_1/main.cpp new file mode 100644 index 0000000..9e2ec9e --- /dev/null +++ b/lesson_1/main.cpp @@ -0,0 +1,42 @@ +#include +#include "exercise_1.hpp" +#include "exercise_2.hpp" +#include "exercise_3.hpp" + +using namespace std; + +int main() +{ + // Exercise 1 + Power Num; + + Num.set(2.0, 3.0); + cout << Num.calculate() << endl; + + // Exercise 2 + + RGBA Color1; + Color1.print(); + RGBA Color2(100, 123, 210, 13); + Color2.print(); + + // Exercise 3 + + Stack stack; + stack.reset(); + stack.print(); + + stack.push(3); + stack.push(7); + stack.push(5); + stack.print(); + + stack.pop(); + stack.print(); + + stack.pop(); + stack.pop(); + stack.print(); + + return 0; +} -- 2.40.1