#include<iostream>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<windows.h>
using namespace std;
void z()
{
Sleep(100);
}
class Car
{
double fuel;
double speed;
double X;
double Y;
public:
Car(double n, char *type)
{
fuel=n;
speed=120;
}
double Speed()
{
return speed;
}
void Position(double p, double q)
{
X = p;
Y = q;
}
void Move()
{
X=X+(Speed()/3600);
Y=Y+(Speed()/3600);
}
};
int main()
{
Car c(70,"Car");
double x,y;
c.Position(3.2,2.2);
cout<<c.Speed()<<endl;
while(1)
{
c.Move();
c.Position(x,y);
cout<<x<<","<<y<<endl;
z();
}
return 0;
}
我想在同一行中显示位置的变化,这意味着每秒都会更新位置的值,并将其显示在同一行中,替换旧值,但不会创建任何新行。