Solution to In a car race game, when a car object is created it should be filled … - Sikademy
Author Image

Archangel Macsika

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

The Answer to the Question
is below this banner.

Can't find a solution anywhere?

NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?

Get the Answers Now!

You will get a detailed answer to your question or assignment in the shortest time possible.

Here's the Solution to this Question


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); }


Related Answers

Was this answer helpful?

Join our Community to stay in the know

Get updates for similar and other helpful Answers

Question ID: mtid-3-stid-44-sqid-1097-qpid-93