/
lyapdy
/
Object_oriented_programming_cpp_318
Обзор
Документация
Войти
/
lyapdy
/
Object_oriented_programming_cpp_318
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lab6/task_5.cpp
98 строк
4 KB
danillyapunov
lab6commit
10 янв 2026, 15:23
10 янв 2026, 15:23
b29f1a0
Код
Авторство
О чём код?
#include <iostream> #include <iomanip> #include <algorithm> #include "task_5.h" Brick::Brick(int l, int w, int h) : length(l), width(w), height(h) {} void Brick::getDimensions() { std::cout << "Размеры кирпича (LxWxH): " << length << 'x' << width << 'x' << height << '\n'; } void Brick::printProjections() const { int brickSides[] = {length, width, height}; std::sort(brickSides, brickSides + 3); std::string brickStars0(brickSides[0] + 1, '*'); std::string brickStars1(brickSides[1] + 1, '*'); std::string brickStars2(brickSides[2] + 1, '*'); std::string gapSide0(brickSides[0] - 1, ' '); std::string gapSide1(brickSides[1] - 1, ' '); std::string gapSide2(brickSides[2] - 1, ' '); std::string gapProjections(3, ' '); std::cout << "\nПроекции кирпича:\n"; std::cout << brickStars0 << gapProjections << brickStars2<< '\n'; for (int i = 0; i < (brickSides[1] / 2 - 1 ); ++i) { std::cout << brickStars1[i] << gapSide0 << brickStars1[i] << gapProjections << brickStars1[i]<< gapSide2 << brickStars1[i] << '\n'; } std::cout << brickStars0 << gapProjections << brickStars2 << '\n'; std::cout << '\n'; std::cout << brickStars0 << gapProjections << '\n'; for (int i = 0; i < (brickSides[2] / 2 - 1 ); ++i) { std::cout << brickStars2[i] << gapSide0 << brickStars2[i] << '\n'; } std::cout << brickStars0 << '\n'; } Model3d::Model3d(int hh, int hl, int hw) : holeLength(hl), holeWidth(hw), holeHeight(hh) {} void Model3d::printProjections() const { int modelSides[] = {holeLength, holeWidth, holeHeight}; std::sort(modelSides, modelSides + 3); std::string brickStars0(modelSides[0] + 1, '*'); std::string brickStars1(modelSides[1] + 1, '*'); std::string brickStars2(modelSides[2] + 1, '*'); std::string gapSide0(modelSides[0] - 1, ' '); std::string gapSide1(modelSides[1] - 1, ' '); std::string gapSide2(modelSides[2] - 1, ' '); std::string gapProjections(3, ' '); std::cout << "\nПроекции отверстия 3д:\n"; std::cout << brickStars0 << gapProjections << brickStars2<< '\n'; for (int i = 0; i < (modelSides[1] / 2 - 1 ); ++i) { std::cout << brickStars1[i] << gapSide0 << brickStars1[i] << gapProjections << brickStars1[i]<< gapSide2 << brickStars1[i] << '\n'; } std::cout << brickStars0 << gapProjections << brickStars2 << '\n'; std::cout << '\n'; std::cout << brickStars0 << gapProjections << '\n'; for (int i = 0; i < (modelSides[2] / 2 - 1 ); ++i) { std::cout << brickStars2[i] << gapSide0 << brickStars2[i] << '\n'; } std::cout << brickStars0 << '\n'; } bool canPassThrough(const Brick& b, const Model3d& m) { int brickDims[] = {b.length, b.width, b.height}; int holeDims[] = {m.holeLength, m.holeWidth, m.holeHeight}; std::sort(brickDims, brickDims + 3); std::sort(holeDims, holeDims + 3); return (brickDims[0] <= holeDims[0]) && (brickDims[1] <= holeDims[1]) && (brickDims[2] <= holeDims[2]); } void BrickChecker::run() { Brick brick; brick.getDimensions(); int l, w, h; std::cout << "Введите размеры отверстия (L W H) в миллиметрах через пробел: "; std::cin >> l >> w >> h; Model3d model(l, w, h); brick.printProjections(); model.printProjections(); if (canPassThrough(brick, model)) { std::cout << "\nКирпич пройдет через отверстие.\n"; } else { std::cout << "\nКирпич не пройдет через отверстие.\n"; } }