M1103 Mini-Set 4

Problem 1 — Cars and Parking Lots

Warning: we do not give automatic tests for this mini-set. So you will start from an empty project and write your own main function to test your program.

We want to write two classes to model cars and parking lots. The goal is to be able to add cars and parking lots.

Create the files car.h, car.cpp, lot.h, lot.cpp, and main.cpp in your project.

a — Car

A car has a plate (of type string), a make (of type string) and a maximum speed (of type int).

Write a class Car with the private data members plate, make, and maxspeed.

Write a constructor to initialize them. If the given max speed is negative, throw an exception of type invalid_argument.

Add member functions get_plate,get_make and get_maxspeed to make them accessible from the exterior.

Respect the separation into files car.h and car.cpp.

Add tests in the main function in the file main.cpp to test your class.

b — Equality of Cars

We now want to compare two cars by their plate to not have twice the same car in a parking.

Add an == operator that takes two (constant references to) cars. It returns true if the plates of the two cars are equal and false otherwise.

Add tests in the main function in the file main.cpp to test your operator.

c — Parking Lots

A parking lot contains a set of cars.

Write a class Lot with a vector of cars as private data member.

Add a member function to add a car to the lot (if it’s not already in it).

Add a member function contains to check if a given car is in the lot.

Respect the separation into files lot.h and lot.cpp.

Add tests in the main function in the file main.cpp to test your class.

d — Display

Add the operators << to be able to display cars as well as parking lots (with a full list of their cars).

back to the course web site