Другие языки программирования и технологии

Помогите с кодом С++

Мне скинули вот так код. Помогите попереносить строки правильно... Я уже долблюсь долгоо. И почему то не получается.... Скорее всего потому что я на низком уровне еще в этом понимаю... Кому не жалко, пожалуйста помогите

#include #include #include #include #include #include #include using namespace std; class Cather { public: Cather(const string name):name(name){} Cather(const Cather &a):name(a.name){} ~Cather(){} virtual double work()=0; virtual ostream& print(ostream& os)const = 0; const string Getname() const { return name; } double getY()const { return y; } double getL() const { return l; } protected: double y; double l=0; private: string name; }; ostream& Cather ::print(ostream& os) const { os«name; return os; } class Dolphen : public Cather { public: Dolphen(const string& name):Cather(name){} static const double fatigue; protected: virtual double work() override; virtual ostream& print(ostream& os)const override; }; double Dolphen::work() { l = static_cast(rand())/RAND_MAX; double Y = fatigue*l; y+=Y; return Y; } ostream& Dolphen::print(ostream& os) const { this->Cather::print(os); return os; } const double Dolphen::fatigue = 0.1; class Diver : public Cather { public: static const double fatigue; Diver(const string& name):Cather(name){} protected: virtual double work() override; virtual ostream& print(ostream& os)const override; }; const double Diver::fatigue = 0.3; double Diver::work() { l= static_cast(rand())/RAND_MAX; double Y = fatigue * (0.5+l); y+=Y; return Y; } ostream& Diver::print(ostream& os) const { this->Cather::print(os); return os; } ostream&operator «(ostream& os,const Cather& p){ p.print(os); return os; } int main() { srand(time(0)); vector whyaaaa; whyaaaa.push_back(new Dolphen("Dolphen")); whyaaaa.push_back(new Diver("Diver")); whyaaaa.push_back(new Dolphen("Dolphen2")); for(int j = 0; j < 3; j++){ cout«*whyaaaa[j]«endl; for(int i = 0; i < 10; i++){ cout«i+1«": " « whyaaaa[j]->work() « ";\n"; } cout«"All : "«whyaaaa[j]->getY()«endl«endl; } return 0; }
Открываешь вот этот сайт: http://format.krzaq.cc/, копипастишь туда свой код и жмёшь снизу кнопку "Format!". Можешь ещё комбобокс рядом с кнопкой попереключать, чтобы попробовать разные стили форматирования.
Или https://codebeautify.org/cpp-formatter-beautifier - там нужно вставить код в поле "C++ Input" и нажать "Beautify/Format".
Ещё есть https://www.onlinegdb.com/online_c++_formatter.
Александр Дракин
Александр Дракин
24 295
Лучший ответ
Стас Ли Вы путаете форматирование кода и декомпрессию. http://format.krzaq.cc/ Этот ресурс не поможет
В NotePad++ замена (CTRL + H)
заменить с ; на ;\n
заменить с } на }\n
заменить с { на \n{
заменить с # на \n#
Залил сюда: codepen. io/anon/pen/KeJeoJ?editors=0010

#include #include #include #include #include #include #include

using namespace std;

class Cather
{
public: Cather(const string name):name(name){}
Cather(const Cather &a):name(a.name){}
~Cather(){}
virtual double work()=0;
virtual ostream& print(ostream& os)const = 0;

const string Getname() const
{
return name;
}

double getY()const
{
return y;
}

double getL() const
{
return l;
}

protected: double y;
double l=0;
private: string name;
};

ostream& Cather ::print(ostream& os) const
{
os«name;
return os;
}

class Dolphen : public Cather
{
public: Dolphen(const string& name):Cather(name){}

static const double fatigue;
protected: virtual double work() override;
virtual ostream& print(ostream& os)const override;
};

double Dolphen::work()
{
l = static_cast(rand())/RAND_MAX;
double Y = fatigue*l;
y+=Y;
return Y;
}

ostream& Dolphen::print(ostream& os) const
{
this->Cather::print(os);
return os;
}

const double Dolphen::fatigue = 0.1;

class Diver : public Cather
{
public: static const double fatigue;
Diver(const string& name):Cather(name){}

protected: virtual double work() override;
virtual ostream& print(ostream& os)const override;
};

const double Diver::fatigue = 0.3;

double Diver::work()
{
l= static_cast(rand())/RAND_MAX;
double Y = fatigue * (0.5+l);
y+=Y;
return Y;
}

ostream& Diver::print(ostream& os) const
{
this->Cather::print(os);
return os;
}

ostream&operator «(ostream& os,const Cather& p)
{
p.print(os);
return os;
}

int main()
{
srand(time(0));
vector whyaaaa;
whyaaaa.push_back(new Dolphen("Dolphen"));
whyaaaa.push_back(new Diver("Diver"));
whyaaaa.push_back(new Dolphen("Dolphen2"));

for(int j = 0; j < 3; j++)
{
cout«*whyaaaa[j]«endl;

for(int i = 0; i < 10; i++)
{
cout«i+1«": " « whyaaaa[j]->work() « ";
\n";
}
cout«"All : "«whyaaaa[j]->getY()«endl«endl;
}
return 0;
}
Юрий Суровцев
Юрий Суровцев
3 120