1.6 KiB
1.6 KiB
IF.03.22 POSE - Procedural Programming
Assignment: Car - Abstract Data Type
An abstract data type Car should be implemented, which realizes basic functionalities of a car.
Example
The code sequence to retrieve a car from a parking spot and accelerate it to 100 km/h would look as follows:
Car c = get_car(JEEP);
if (get_color(c) == BLACK) {
set_acceleration_rate(c, 3);
while (get_speed(c) < 100)
accelerate(c);
} else {
printf("I only drive black cars!");
}
Tasks
- Define two enums,
CarTypeandColor. - Create a forward declaration for the Car type so that the prototypes in the header file can be accepted by the compiler.
- Create minimal stub implementations for all required functions. This should allow the overall project to build successfully.
- Define the struct from the forward declaration.
- Create local (file-specific in car.cpp only) variables for all required cars.
- Create a local array
car_parkto store all cars. - Write a program in the file car_main_driver.c that races all cars defined in
car.cppagainst each other.- Level 1: Retrieve all cars from
car.cppand display them sequentially in the terminal. Represent the cars by their initial letter and a running number. - Level 2: Now let the cars "race" by setting each car's acceleration randomly in each round and, based on the resulting speed, move each car accordingly to the right. The race should stop as soon as one car reaches the finish line (the right edge of the screen).
- Level 1: Retrieve all cars from
Note: Speed is given in km/h, while acceleration is given in m/s.