Gholbilore 28 ноября 2019 в 10:32

Нужно создать через язык программирования Си
Создать приложение, которое выводит на экран следующую таблицу:

╔════════════════════════════════════════════╗
║ Vremena goda ║
╠═════════╦═══════════╦═══════════╦══════════╣
║ Zima ║ Vesna ║ Leto ║ Osen ║
╚═════════╩═══════════╩═══════════╩══════════╝
Подсказка:
Рекомедуем выполнить следующий пример
cout<<"\n"<<(char)201<<(char)205<<(char)205<<(char)187;
Необходимые символы находятся в дипазоне от 179 до 218

У меня есть какие-то наработки, они под линукс, но на винде должно работать все, кроме управления цветом, его выкинешь.

#include lt;cstdlibgt;#include lt;stringgt;#include lt;iostreamgt;#include "field.h"using namespace std;
int main(int argc, char** argv, char** env){    srand(time(0));    vectorlt; vectorlt; string gt; gt; S;    S.resize(2);    S[0].push_back("Vremena_goda");    S[1].push_back("Zima"); S[1].push_back("Vesna"); S[1].push_back("Leto"); S[1].push_back("Osen");
    Field A(S, Field().clGreen, Field().clLightblue);    cout lt;lt; A lt;lt; std::endl;    return 0;}
#ifndef FIELD_H_INCLUDED#define FIELD_H_INCLUDED
#include lt;vectorgt;#include lt;iteratorgt;#include lt;algorithmgt;#include lt;stringgt;#include lt;sstreamgt;class Field{public:    enum ConsoleColor { clBlack, clRed, clGreen, clYellow, clBlue, clPurple, clLightblue, clWhite };private:    size_t field_width, field_height;    std::vectorlt; std::vectorlt; std::string gt; gt; Data;    std::vectorlt; size_t gt; column_width;    ConsoleColor color_border, color_font;    std::string get_format_color_string(std::string S, ConsoleColor color)    {        std::stringstream result;        result lt;lt; "x1b[1;" lt;lt; color + 30 lt;lt; "m" lt;lt; S lt;lt; "x1b[0m";        return result.str();    }    std::string str_mul(std::string s, size_t num)    {        std::string result = "";        for(size_t i = 0; i lt; num; i++)            result += s;        return result;    }public:    Field() {};    Field(std::vectorlt; std::vectorlt; std::string gt; gt; D,          ConsoleColor color_border,          ConsoleColor color_font) :        Data(D), color_border(color_border), color_font(color_font)    {        field_height = Data.size();        field_width = 0;        for(size_t i = 0; i lt; field_height; i++)            field_width = std::max(field_width, Data[i].size());        for(size_t i = 0; i lt; field_height; i++)            while(Data[i].size() lt; field_width)                Data[i].push_back("");        column_width.assign(field_width, 0);        for(size_t i = 0; i lt; field_height; i++)            for(size_t j = 0; j lt; field_width; j++)                column_width[j] = std::max(column_width[j], Data[i][j].length());    }    void logs()    {        std::cout lt;lt; "field_height: " lt;lt; field_height lt;lt; std::endl;        std::cout lt;lt; "field_widht: " lt;lt; field_width lt;lt; std::endl;    }    friend std::ostreamamp; operator lt;lt;(std::ostreamamp; output_stream, Field amp; field)    {        /*        std::cout lt;lt; field.field_width lt;lt; " " lt;lt; field.field_height lt;lt; std::endl;        for(size_t i = 0; i lt; field.Data.size(); i++)        {            for(size_t j = 0; j lt; field.Data[i].size(); j++)                std::cout lt;lt; field.Data[i][j] lt;lt; " ";            std::cout lt;lt; std::endl;        }        */
        output_stream lt;lt; field.get_format_color_string("        ┌", field.color_border);        for(size_t i = 0; i lt; field.field_width - 1; i++)        {            output_stream lt;lt; field.get_format_color_string(field.str_mul("─", field.column_width[i] + 2), field.color_border);            output_stream lt;lt; field.get_format_color_string("┬", field.color_border);        }        output_stream lt;lt; field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border);        output_stream lt;lt; field.get_format_color_string("┐n        ", field.color_border);
        for(size_t i = 0; i lt; field.field_height; i++)        {            output_stream lt;lt; field.get_format_color_string("│", field.color_border);            for(size_t j = 0; j lt; field.field_width; j++)            {                std::stringstream ss;                ss lt;lt; field.str_mul(" ", field.column_width[j] - field.Data[i][j].size() + 1) lt;lt; (field.Data[i][j] != "" field.Data[i][j] : "");                output_stream lt;lt; field.get_format_color_string(ss.str(), field.color_font);                output_stream lt;lt; field.get_format_color_string(" │", field.color_border);            }            output_stream lt;lt; "n        ";            if(i != field.field_height - 1)            {                output_stream lt;lt; field.get_format_color_string("├", field.color_border);                for(size_t j = 0; j lt; field.field_width - 1; j++)                {                    output_stream lt;lt; field.get_format_color_string(field.str_mul("─", field.column_width[j] + 2), field.color_border);                    output_stream lt;lt; field.get_format_color_string("┼", field.color_border);                }                output_stream lt;lt; field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border);                output_stream lt;lt; field.get_format_color_string("┤", field.color_border);            }            else            {                output_stream lt;lt; field.get_format_color_string("└", field.color_border);                for(size_t j = 0; j lt; field.field_width - 1; j++)                {                    output_stream lt;lt; field.get_format_color_string(field.str_mul("─", field.column_width[j] + 2), field.color_border);                    output_stream lt;lt; field.get_format_color_string("┴", field.color_border);                }                output_stream lt;lt; field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border);                output_stream lt;lt; field.get_format_color_string("┘n", field.color_border);            }            output_stream lt;lt; "n        ";        }        return output_stream;
    }};
#endif // FIELD_H_INCLUDED

Для комментирования необходимо зарегистрироваться на сайте