/
nanezz
/
st1
Обзор
Документация
Войти
/
nanezz
/
st1
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
st1.cpp
103 строки
2 KB
nanezz
Create: st1.slnx, st1.cpp
02 авг 2026, 18:21
Верифицирован
02 авг 2026, 18:21
239a185
Код
Авторство
О чём код?
#include <string> #include <iostream> #include <algorithm> class SimpleText { public: virtual void render(const std::string& data) const { std::cout << data; } }; class DecoratedText : public SimpleText { public: SimpleText* _text_; DecoratedText(SimpleText* text) : _text_(text) {} }; class ItalicText : public DecoratedText { public: ItalicText(SimpleText* text) : DecoratedText(text) {} void render(const std::string& data) { std::cout << "<i>"; _text_->render(data); std::cout << "</i>"; } }; class BoldText : public DecoratedText { public: BoldText(SimpleText* text) : DecoratedText(text) {} void render(const std::string& data) { std::cout << "<b>"; _text_->render(data); std::cout << "</b>"; } }; class Paragraph : public DecoratedText { public: Paragraph(SimpleText* text) : DecoratedText(text) {} void render(const std::string& data) { std::cout << "<p>"; _text_->render(data); std::cout << "</p>"; } }; class Reversed : public DecoratedText { public: Reversed(SimpleText* text) : DecoratedText(text) {} void render(const std::string& data) { std::string reversed = data; std::reverse(reversed.begin(), reversed.end()); _text_->render(reversed); } }; class Link : public DecoratedText { public: Link(SimpleText* text) : DecoratedText(text) {} void render(const std::string& href, const std::string& data) { std::cout << "<a href=" << href << ">"; _text_->render(data); std::cout << "</a>"; } }; int main() { auto text = new SimpleText(); auto paragraph = new Paragraph(text); paragraph->render("Hello world"); std::cout << std::endl; auto reversed = new Reversed(text); reversed->render("Hello world"); std::cout << std::endl; auto link = new Link(text); link->render("netology.ru", "Hello world"); std::cout << std::endl; delete link; delete reversed; delete paragraph; delete text; return 0; }