Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <list>
- #include <cmath>
- #include <algorithm>
- #include <iterator>
- #include <memory>
- #include "shape.hpp"
- #include "allFigures.hpp"
- void task_1()
- {
- std::list<double> list((std::istream_iterator<double>(std::cin)), std::istream_iterator<double>());
- if (!std::cin.eof() && std::cin.fail())
- {
- throw std::runtime_error("Error reading data");
- }
- std::transform(list.begin(), list.end(), std::ostream_iterator<double>(std::cout, " "),
- [](double &list)
- { return list * M_PI; });
- std::cout << std::endl;
- }
- void task_2()
- {
- Shape::shape_ptr shape_ptr;
- std::list<Shape::shape_ptr> list;
- std::string line;
- while (std::getline(std::cin, line, '\n'))
- {
- line.erase(remove(line.begin(), line.end(), ' '), line.end());
- line.erase(remove(line.begin(), line.end(), '\t'), line.end());
- if (line.empty())
- {
- continue;
- }
- const auto openBracket = line.find_first_of('(');
- const auto semicolon = line.find_first_of(';');
- const auto closeBracket = line.find_first_of(')');
- if (openBracket == std::string::npos || semicolon == std::string::npos || closeBracket == std::string::npos)
- {
- throw std::runtime_error("Invalid data!\n");
- }
- const auto shape = line.substr(0, openBracket);
- Center center{};
- center.x = std::stod(line.substr(openBracket + 1, semicolon - openBracket + 1));
- center.y = std::stod(line.substr(semicolon + 1, closeBracket - semicolon + 1));
- if (shape == "CIRCLE")
- {
- shape_ptr = std::make_shared<Circle>(center);
- list.push_back(shape_ptr);
- } else if (shape == "SQUARE")
- {
- shape_ptr = std::make_shared<Square>(center);
- list.push_back(shape_ptr);
- } else if (shape == "TRIANGLE")
- {
- shape_ptr = std::make_shared<Triangle>(center);
- list.push_back(shape_ptr);
- } else
- {
- throw std::runtime_error("Invalid shape!\n");
- }
- }
- std::cout << "Original: " << std::endl;
- std::for_each(list.begin(), list.end(), [](const Shape::shape_ptr &ptr)
- { ptr->draw(); });
- std::cout << "Left-Right: " << std::endl;
- list.sort([](const Shape::shape_ptr &leftFigure, const Shape::shape_ptr &rightFigure)
- { return leftFigure->isMoreLeft((const Shape &) rightFigure); });
- std::for_each(list.begin(), list.end(), [](const Shape::shape_ptr &ptr)
- { ptr->draw(); });
- std::cout << "Right-Left: " << std::endl;
- list.reverse();
- std::for_each(list.begin(), list.end(), [](const Shape::shape_ptr &ptr)
- { ptr->draw(); });
- std::cout << "Top-Bottom: " << std::endl;
- list.sort([](const Shape::shape_ptr &topFigure, const Shape::shape_ptr &bottomFigure)
- { return topFigure->isUpper(*bottomFigure); });
- std::for_each(list.begin(), list.end(), [](const Shape::shape_ptr &ptr)
- { ptr->draw(); });
- std::cout << "Bottom-Top: " << std::endl;
- list.reverse();
- std::for_each(list.begin(), list.end(), [](const Shape::shape_ptr &ptr)
- { ptr->draw(); });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement