Compare commits

..

1 Commits

Author SHA1 Message Date
Alexander Zhirov 26d8361a18 lesson 1 2021-06-19 01:15:56 +03:00
4 changed files with 130 additions and 0 deletions

21
lesson_1/exercise_1.hpp Normal file
View File

@ -0,0 +1,21 @@
#include <math.h>
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);
}
};

23
lesson_1/exercise_2.hpp Normal file
View File

@ -0,0 +1,23 @@
#include <cstdint>
#include <iostream>
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<int>(m_red) <<
" g=" << static_cast<int>(m_green) <<
" b=" << static_cast<int>(m_blue) <<
" a=" << static_cast<int>(m_alpha) << std::endl;
}
};

44
lesson_1/exercise_3.hpp Normal file
View File

@ -0,0 +1,44 @@
#include <iostream>
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;
}
};

42
lesson_1/main.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <iostream>
#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;
}