diff --git a/cpp/Figure.cpp b/cpp/Figure.cpp new file mode 100644 index 0000000..98653a0 --- /dev/null +++ b/cpp/Figure.cpp @@ -0,0 +1,19 @@ +// +// Created by ahypki on 28.03.23. +// + +#include "Figure.h" + +namespace ahypki { + std::string Figure::getName() { + return this->name; + } + + void Figure::setName(std::string newName) { + this->name = newName; + } + + double Figure::computeArea() { + return 0.0; + } +} // ahypki \ No newline at end of file diff --git a/cpp/Figure.h b/cpp/Figure.h new file mode 100644 index 0000000..0a9d9e0 --- /dev/null +++ b/cpp/Figure.h @@ -0,0 +1,23 @@ +// +// Created by ahypki on 28.03.23. +// +#include <iostream> + +#ifndef TESTCPPPROGOBIE_FIGURE_H +#define TESTCPPPROGOBIE_FIGURE_H + +namespace ahypki { + + class Figure { + private: + std::string name = "Unknown figure"; + public: + std::string getName(); + void setName(std::string newName); + virtual double computeArea(); + virtual double pureVirtualComputeArea() = 0; + }; + +} // ahypki + +#endif //TESTCPPPROGOBIE_FIGURE_H diff --git a/cpp/Square.cpp b/cpp/Square.cpp new file mode 100644 index 0000000..5de1bc1 --- /dev/null +++ b/cpp/Square.cpp @@ -0,0 +1,32 @@ +// +// Created by ahypki on 28.03.23. +// + +#include "Square.h" + +namespace ahypki { + Square::Square() { + setName("Square"); + } + + Square::Square(double x) { + setName("Square"); + setX(x); + } + + double Square::getX() { + return x; + } + + void Square::setX(double newX) { + x = newX; + } + + double Square::computeArea() { + return getX() * getX(); + } + + double Square::pureVirtualComputeArea() { + return getX() * getX(); + } +} // ahypki \ No newline at end of file diff --git a/cpp/Square.h b/cpp/Square.h new file mode 100644 index 0000000..62d3073 --- /dev/null +++ b/cpp/Square.h @@ -0,0 +1,26 @@ +// +// Created by ahypki on 28.03.23. +// + +#include "Figure.h" + +#ifndef TESTCPPPROGOBIE_SQUARE_H +#define TESTCPPPROGOBIE_SQUARE_H + +namespace ahypki { + + class Square : public Figure { + private: + double x; + public: + Square(); + Square(double x); + void setX(double x); + double getX(); + virtual double computeArea(); + virtual double pureVirtualComputeArea(); + }; + +} // ahypki + +#endif //TESTCPPPROGOBIE_SQUARE_H diff --git a/cpp/main.cpp b/cpp/main.cpp new file mode 100644 index 0000000..6bca32e --- /dev/null +++ b/cpp/main.cpp @@ -0,0 +1,22 @@ +#include <iostream> +#include "Figure.h" +#include "Square.h" + +int main() { + std::cout << "Hello, World!" << std::endl; + +// ahypki::Figure figure = ahypki::Figure(); +// std::cout << "Default name: " << figure.getName() << std::endl; +// +// figure.setName("Next name"); +// std::cout << "New name: " << figure.getName() << std::endl; + + ahypki::Square s = ahypki::Square(10); + std::cout << s.getName() + << " has x= " << s.getX() + << " has area= " << s.computeArea() + << std::endl; + + + return 0; +}