М
Молодежь
К
Компьютеры-и-электроника
Д
Дом-и-сад
С
Стиль-и-уход-за-собой
П
Праздники-и-традиции
Т
Транспорт
П
Путешествия
С
Семейная-жизнь
Ф
Философия-и-религия
Б
Без категории
М
Мир-работы
Х
Хобби-и-рукоделие
И
Искусство-и-развлечения
В
Взаимоотношения
З
Здоровье
К
Кулинария-и-гостеприимство
Ф
Финансы-и-бизнес
П
Питомцы-и-животные
О
Образование
О
Образование-и-коммуникации
valerea0
valerea0
13.02.2023 13:23 •  Информатика

с информатикой 5 вопросов,


с информатикой 5 вопросов,
с информатикой 5 вопросов,
с информатикой 5 вопросов,
с информатикой 5 вопросов,
с информатикой 5 вопросов,

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

#include <cstdlib>#include <string>#include <iostream>#include "field.h"using namespace std;
int main(int argc, char** argv, char** env){    srand(time(0));    vector< vector< string > > 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 << A << std::endl;    return 0;}
#ifndef FIELD_H_INCLUDED#define FIELD_H_INCLUDED
#include <vector>#include <iterator>#include <algorithm>#include <string>#include <sstream>class Field{public:    enum ConsoleColor { clBlack, clRed, clGreen, clYellow, clBlue, clPurple, clLightblue, clWhite };private:    size_t field_width, field_height;    std::vector< std::vector< std::string > > Data;    std::vector< size_t > column_width;    ConsoleColor color_border, color_font;    std::string get_format_color_string(std::string S, ConsoleColor color)    {        std::stringstream result;        result << "\x1b[1;" << color + 30 << "m" << S << "\x1b[0m";        return result.str();    }    std::string str_mul(std::string s, size_t num)    {        std::string result = "";        for(size_t i = 0; i < num; i++)            result += s;        return result;    }public:    Field() {};    Field(std::vector< std::vector< std::string > > 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 < field_height; i++)            field_width = std::max(field_width, Data[i].size());        for(size_t i = 0; i < field_height; i++)            while(Data[i].size() < field_width)                Data[i].push_back("");        column_width.assign(field_width, 0);        for(size_t i = 0; i < field_height; i++)            for(size_t j = 0; j < field_width; j++)                column_width[j] = std::max(column_width[j], Data[i][j].length());    }    void logs()    {        std::cout << "field_height: " << field_height << std::endl;        std::cout << "field_widht: " << field_width << std::endl;    }    friend std::ostream& operator <<(std::ostream& output_stream, Field & field)    {        /*        std::cout << field.field_width << " " << field.field_height << std::endl;        for(size_t i = 0; i < field.Data.size(); i++)        {            for(size_t j = 0; j < field.Data[i].size(); j++)                std::cout << field.Data[i][j] << " ";            std::cout << std::endl;        }        */
        output_stream << field.get_format_color_string("        ┌", field.color_border);        for(size_t i = 0; i < field.field_width - 1; i++)        {            output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[i] + 2), field.color_border);            output_stream << field.get_format_color_string("┬", field.color_border);        }        output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border);        output_stream << field.get_format_color_string("┐\n        ", field.color_border);
        for(size_t i = 0; i < field.field_height; i++)        {            output_stream << field.get_format_color_string("│", field.color_border);            for(size_t j = 0; j < field.field_width; j++)            {                std::stringstream ss;                ss << field.str_mul(" ", field.column_width[j] - field.Data[i][j].size() + 1) << (field.Data[i][j] != "" ? field.Data[i][j] : "");                output_stream << field.get_format_color_string(ss.str(), field.color_font);                output_stream << field.get_format_color_string(" │", field.color_border);            }            output_stream << "\n        ";            if(i != field.field_height - 1)            {                output_stream << field.get_format_color_string("├", field.color_border);                for(size_t j = 0; j < field.field_width - 1; j++)                {                    output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[j] + 2), field.color_border);                    output_stream << field.get_format_color_string("┼", field.color_border);                }                output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border);                output_stream << field.get_format_color_string("┤", field.color_border);            }            else            {                output_stream << field.get_format_color_string("└", field.color_border);                for(size_t j = 0; j < field.field_width - 1; j++)                {                    output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[j] + 2), field.color_border);                    output_stream << field.get_format_color_string("┴", field.color_border);                }                output_stream << field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border);                output_stream << field.get_format_color_string("┘\n", field.color_border);            }            output_stream << "\n        ";        }        return output_stream;
    }};
#endif // FIELD_H_INCLUDED
4,5(4 оценок)
Ответ:
gfitgfbjgffj
gfitgfbjgffj
13.02.2023
#include <iostream>
#include <cmath>
using namespace std;
class Circle
{
private:
    double x;
    double y;
    double r;
public:
    Circle();
    Circle(double xCo, double yCo, double rad);
    double area();
    double centre_dist(Circle & c);
    bool istouch(Circle & c);
};

Circle::Circle()
{
    cout << "Enter x coord: ";
    cin >> x;
    cout << "Enter y coord: ";
    cin >> y;
    cout << "Enter radius: ";
    while (cin >> r && r < 0)
    {
        cout << "Radius can't be negative\n";
        cout << "Enter radius: ";
    }
}

Circle::Circle(double xCo, double yCo, double rad) : x(xCo), y(yCo), r(rad)
{
    if (r < 0)
    {
        cout << "Radius can't be negative\n";
        cout << "Radius set to 0\n";
        r = 0;
    }
}

double Circle::area()
{
    return 3.1415926 * r * r;
}

double Circle::centre_dist(Circle & c)
{
    return sqrt((x - c.x) * (x - c.x) + (y - c.y) * (y - c.y));
}

bool Circle::istouch(Circle & c)
{
    return (this->centre_dist(c) <= r + c.r) ? true : false;
}

int main()
{
    Circle c1;
    Circle c2(0, 0, 5);
    cout << "area of c2: " << c2.area() << endl;
    cout << "centre distance: " << c2.centre_dist(c1) << endl;
    cout << "is touch: ";
    c2.istouch(c1) ? cout << "yes" : cout << "no";
    cout << endl;
    return 0;
}
4,4(70 оценок)
Это интересно:
Новые ответы от MOGZ: Информатика
logo
Вход Регистрация
Что ты хочешь узнать?
Спроси Mozg
Открыть лучший ответ