In a car race game, when a car object is created it should be filled with fuel, and placed at certain x,y coordinates. Once the game is over, all cars should be deleted ? How do you handle it using c++ classes. Write suitable c++ code
using namespace std;
/*
In a car race game, when a car object is created it should be filled with fuel,
and placed at certain x,y coordinates. Once the game is over, all cars should be deleted ?
How do you handle it using c++ classes. Write suitable c++ code
*/
#define NO_OF_CARS 10
class Car
{
public:
int ID;
int Fuel;
int x;
int y;
void SetCar(int id, int fuel, int X, int Y)
{
ID = id;
Fuel = fuel;
x = X;
y = Y;
}
// Destructor
~Car()
{
cout << "Destructor is called!\n";
}
};
int main()
{
int x,y,n;
class Car C[NO_OF_CARS];
x = 0;
y = 0;
for(n=0;n<NO_OF_CARS;n++) C[n].SetCar(n,100,x,y); //Create Objects
delete C; //Delele all objects
return(0);
}
Comments
Leave a comment