Write a program that creates Car objects. Your Car class should store the following attributes of a car:
Color ('R'=red; 'G'=green; 'B'=blue; 'W'=white; 'S'=Silver)
Ignition (false=off; true=on)
Position (any X, Y coordinate in a 20 X 20 grid)
main() should create an array of 10 Car instances with random color, ignition set to off/false, and position randomly assigned. Once you assign the beginning state to the cars you should have a loop which asks the user what she wants to do next. For example:
Which car would you like to use next (0-9)?
Then ask the user what she wants to do to the car she selected. For example:
What would you like to do next
1 - change ignition;
2 - change position of car;
3 - quit this program)?
If the user wants to change the car's ignition status it will call the car’s instance method which changes the ignition state (explained below).
If the user wants to change the car's position, main() will prompt the user for a direction (e.g. What direction would you like to move the car (1 - horizontal; 2 - vertical)?) and the distance (e.g. How far (negative value to move left)?; How far (negative value to move up) ?). Then the appropriate method (move horizontal or move vertical -- see below) would be called. You must use care to use the correct car's variables when calling the methods.
Each of the qualities will be represented by an instance variable in the Car class. You should write an instance method for each of the following:
color assignment: Randomly picks one of the five colors (represented by a letter) and returns the corresponding char to main(). This method should be called once from the Car class’ constructor. The color will not change during the execution of the program.
Fall 2013 Object Oriented Programing Assignment#1
move car horizontally: This method will need the number of spaces you would like to move the car (a negative value will move the car left; positive value will move the car right) and will adjust the xPosition of the car.
If the car's ignition is not on, this method tells the user that s/he must turn the ignition on first and leaves the xPosition unchanged.
If the user tries to move the car beyond the border of the 20 X 20 grid, this method should leaves the xPosition unchanged.; instead you should report an
Imagine a tollbooth at a bridge. Cars passing by the booth are expected to pay a 50 rupees toll. Mostly they do, but sometimes a car goes by without paying. The tollbooth keeps track of the number of cars that have gone by, and of the total amount of money collected.
Model this tollbooth with a class called tollBooth. The two data items are a type unsigned int to hold the total number of cars, and a type double to hold the total amount of money collected. A constructor initializes both of these to 0. A member function called payingCar()increments the car total and adds 50 to the cash total. Another function, callednopayCar(),increments the car total but adds nothing to the cash total. Finally, a member function called display()displays the two totals.