This commit is contained in:
Andrey Kassaev 2024-03-04 15:47:33 +04:00
commit 9dc630256d
8 changed files with 142 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*/*
OOP*

11
Main.cpp Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include "UserInteraction.h"
int main() {
UserInteraction userInteraction;
userInteraction.execute();
system("pause");
return 0;
};

1
Square.cpp Normal file
View File

@ -0,0 +1 @@
#include "Square.h"

22
Square.h Normal file
View File

@ -0,0 +1,22 @@
#pragma once
#include <iostream>
#include <math.h>
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;
};
};

1
SquarePrism.cpp Normal file
View File

@ -0,0 +1 @@
#include "SquarePrism.h"

27
SquarePrism.h Normal file
View File

@ -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));
};
};

1
UserInteraction.cpp Normal file
View File

@ -0,0 +1 @@
#include "UserInteraction.h"

77
UserInteraction.h Normal file
View File

@ -0,0 +1,77 @@
#pragma once
#include <iostream>
#include "Square.h"
#include "SquarePrism.h"
#include <vector>
class UserInteraction
{
public:
int numberOfSquares;
int numberOfSquarePrisms;
std::vector<Square> squareList;
std::vector<SquarePrism> 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";
};
};