0
please, help . What is not right here
#include <iostream> #include <string> #include <list> using namespace std; class TFish { public: int x;//координата x int y;//координата y int speed; //скорость int size; //размер // string color;//цвет char direction;//направление движения (вверх, вниз, вправо, влево) TFish() { cout « "x = "; cin » x; cout « "y = "; cin » y; cout « "speed = "; cin » speed; cout « "size = "; cin » size; /* cout « "color = "; cin » color;*/ cout « "direction = "; cin » direction; } void Draw()
2 Answers
+ 3
« and » are not the correct operators. Use >> and << with cin and cout respectively.
Secondly, use the code playground to save your codes, as there it is easier to edit codes.
0
#include <iostream>
#include <string>
#include <list>
using namespace std;
class TFish
{
public:
int x;//координата x
int y;//координата y
int speed; //скорость
int size; //размер
// string color;//цвет
char direction;//направление движения (вверх, вниз, вправо, влево)
TFish()
{
cout « "x = ";
cin » x;
cout « "y = ";
cin » y;
cout « "speed = ";
cin » speed;
cout « "size = ";
cin » size;
/* cout « "color = ";
cin » color;*/
cout « "direction = ";
cin » direction;
}
void Draw()
{
switch (direction)
{
case 'd': print('!');
break;
case 'u': print('^');
break;
case 'l': print('<');
break;
case 'r': print('>');
break;
}
}
void Run()
{
if (direction == 'd')
{
y = y - speed;
if (y < 0) { y = y * (-1); direction = 'u'; }
}
if (direction == 'u')
{
y = y + speed;
if (y > 10) { y = 20 - y; direction = 'd'; }
}
if (direction == 'l')
{
x = x - speed;
if (x < 0) { x = x * (-1); direction = 'r'; }
}
if (direction == 'r')
{
x = x + speed;
if (x > 10) { x = 20 - x; direction = 'l'; }
}
}
private:
void print(char s)
{
for (int i = 0; i < size; i++) cout « s;
}
};
int main()
{
list <TFish> a;
list <TFish> ::iterator here = a.begin();
for (int i=0; i<3; i++)
{
TFish temp;
a.push_back(temp);
}
for(int i =0; i < 3; i++)
{
here = a.begin();
advance(here, i);
here->Run();
};
for(int i =0; i < 3; i++)
{
cout « i+1 « ". ";
here = a.begin();
advance(here, i);
here->Draw();
cout « endl;
};
return 0;
}