From 9dc630256ddfb9d32dd0b4fce92e26a71bf55db8 Mon Sep 17 00:00:00 2001 From: Andrey Kassaev Date: Mon, 4 Mar 2024 15:47:33 +0400 Subject: [PATCH] init --- .gitignore | 2 ++ Main.cpp | 11 +++++++ Square.cpp | 1 + Square.h | 22 +++++++++++++ SquarePrism.cpp | 1 + SquarePrism.h | 27 ++++++++++++++++ UserInteraction.cpp | 1 + UserInteraction.h | 77 +++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 142 insertions(+) create mode 100644 .gitignore create mode 100644 Main.cpp create mode 100644 Square.cpp create mode 100644 Square.h create mode 100644 SquarePrism.cpp create mode 100644 SquarePrism.h create mode 100644 UserInteraction.cpp create mode 100644 UserInteraction.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6df1069 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*/* +OOP* \ No newline at end of file diff --git a/Main.cpp b/Main.cpp new file mode 100644 index 0000000..bfdd76a --- /dev/null +++ b/Main.cpp @@ -0,0 +1,11 @@ +#pragma once +#include "UserInteraction.h" + +int main() { + + UserInteraction userInteraction; + userInteraction.execute(); + + system("pause"); + return 0; +}; \ No newline at end of file diff --git a/Square.cpp b/Square.cpp new file mode 100644 index 0000000..805a3de --- /dev/null +++ b/Square.cpp @@ -0,0 +1 @@ +#include "Square.h" diff --git a/Square.h b/Square.h new file mode 100644 index 0000000..05a5262 --- /dev/null +++ b/Square.h @@ -0,0 +1,22 @@ +#pragma once +#include +#include + +class Square +{ +public: + double side; + Square(double side) { + this->side = side; + }; + virtual double getDiagonal() { + return this->side * sqrt(2); + }; + double getPerimeter() { + return this->side * 4; + }; + virtual double getArea() { + return this->side * this->side; + }; +}; + diff --git a/SquarePrism.cpp b/SquarePrism.cpp new file mode 100644 index 0000000..baab485 --- /dev/null +++ b/SquarePrism.cpp @@ -0,0 +1 @@ +#include "SquarePrism.h" diff --git a/SquarePrism.h b/SquarePrism.h new file mode 100644 index 0000000..9d55ae0 --- /dev/null +++ b/SquarePrism.h @@ -0,0 +1,27 @@ +#pragma once +#include "Square.h" +#include "math.h" + +class SquarePrism : + public Square +{ +public: + double height; + + SquarePrism(double side, double height):Square(side) { + this->height = height; + }; + + double getVolume() { + return Square::getArea() * this->height; + }; + + double getArea() override { + return Square::getArea() * 2 + 4 * this->side * this->height; + }; + + double getDiagonal() override { + return sqrt(pow(Square::getDiagonal(), 2) + pow(this->height, 2)); + }; +}; + diff --git a/UserInteraction.cpp b/UserInteraction.cpp new file mode 100644 index 0000000..53db012 --- /dev/null +++ b/UserInteraction.cpp @@ -0,0 +1 @@ +#include "UserInteraction.h" diff --git a/UserInteraction.h b/UserInteraction.h new file mode 100644 index 0000000..003c382 --- /dev/null +++ b/UserInteraction.h @@ -0,0 +1,77 @@ +#pragma once +#include +#include "Square.h" +#include "SquarePrism.h" +#include + +class UserInteraction +{ +public: + + int numberOfSquares; + int numberOfSquarePrisms; + + std::vector squareList; + std::vector squarePrismList; + + void getUserInput() { + std::cout << "Enter number of squares:\n"; + std::cin >> this->numberOfSquares; + + std::cout << "Enter number of square prisms:\n"; + std::cin >> this->numberOfSquarePrisms; + }; + + void execute() { + getUserInput(); + setData(); + displayData(); + }; + + void setData() { + + srand(time(NULL)); + for (size_t i = 0; i < numberOfSquares; i++) + { + squareList.push_back(Square(rand() % 101)); + } + + for (size_t i = 0; i < numberOfSquarePrisms; i++) + { + squarePrismList.push_back(SquarePrism(rand() % 101, rand() % 101)); + } + }; + + void displayData() { + + double maxSquareArea = 0; + int maxSquareAreaIndex; + + double maxSquarePrismDiagonal = 0; + int maxSquarePrismDiagonalIndex; + + for (size_t i = 0; i < squareList.size(); i++) + { + if (squareList[i].getArea() > maxSquareArea) { + maxSquareArea = squareList[i].getArea(); + maxSquareAreaIndex = i; + } + std::cout << "Square; index = " << i << "; side = " << squareList[i].side << "; area = " << squareList[i].getArea() << "\n"; + } + std::cout << "Max Square Area = " << maxSquareArea << " at Square with index " << maxSquareAreaIndex << "\n\n"; + + + for (size_t i = 0; i < squarePrismList.size(); i++) + { + if (squarePrismList[i].getDiagonal() > maxSquarePrismDiagonal) { + maxSquarePrismDiagonal = squarePrismList[i].getDiagonal(); + maxSquarePrismDiagonalIndex = i; + } + std::cout << "Square Prism; index = " << i << "; side = " << squarePrismList[i].side << "; height = " << squarePrismList[i].height << "; diagonal = " << squarePrismList[i].getDiagonal() << "\n"; + } + std::cout << "Max Square Prism Diagonal = " << maxSquarePrismDiagonal << " at Square Prism with index " << maxSquarePrismDiagonalIndex << "\n\n"; + }; + + +}; +