CSCI 1300
Introduction to Computing
Fall 1997
Programming Assignment #4
Due Sept. 26
Write a program as follows:
-
1. Create a class called Car. The class should have:
-
- Private member variables x and y of type int (that specify the
location of the car on the screen).
- A private member function called draw() that draws the car at
location (x, y) on the screen.
Note: Use the function gotoxy() to get to the proper place on the
screen, then draw the car using cout and characters. The car may be
as simple as a single character.
- Public member functions forward(), backward(), right(), and left() that
-
- Erase the car (using clrscr() or by drawing blanks where the car currently is)
- Increment or decrement x or y, as appropriate.
- Call draw() to draw the car at the new location.
Note: The member functions should check the values of x and y and not increment or decrement anything if they car would be off of the screen. In other words, x must be between 1 and 80 and y must be between 1 and 25.
-
2. In main()
- Define a variable of type Car
- Write a while loop that get character from the user and calls the appropriate function depending on the character
-
- If the user types 'f', call forward()
- If the user types 'b', call backward()
- If the user types 'r', call right()
- If the user types 'l', call left()
- If the user types anything else, break out of the while loop and exit the program