This assignment focus on: • Inheritance
o abstractbaseclass o polymorphism
o dynamic binding
• Composition using container class
• Deep copying and dynamic memory allocation
o copy constructor
o assignment operator o destructor
Car handling system
Todays’ cars can be divided into cars that uses electricity and cars that uses fossil fuel (there are also cars that uses both electricity and fossil fuel but we will not consider those here).
A small company has cars of both kinds (cars that uses fossil fuel and cars that uses electricity) and the company wants a system to handle these cars. The person responsible for de design of this system has decided to implement a prototype (and this is your task) in which inheritance is used. The information that must be registered for all cars in the system is registration number, model and engine power (kW). Concerning electric cars, also the range of the car (how far in km it can be driven on a fully charged battery) needs to be registered. For car that uses fossil fuel instead the fuel consumption (liter/kilometer) and the volume of the fuel tank (liters) needs to be registered. Furthermore:
• the classes FossilCar and ElectricCar must be defined in an inheritance hierarchy
• the base class Cart must be abstract
• no member function (except for the destructor) can have empty bodies
• dynamic binding must be used (hint: virtual)
• all cars must be able to return their model
• all cars must be able to return their registration number
• all cars must be able to return a string that contains all information of the car
• all cars must be able to return their range (cars that uses fossil fuel must calculate this)
• cars that use fossil fuel must be able to return their consumption
• it is not allowed for member functions to make screen outputs
All cars should be handled in a management system that have the functionality given below:
1) Add a car that uses electricity as fuel using user input
2) Add a car that uses fossil fuel using user input
3) Remove a car given the registration number. The user inputs the registration number
4) Present all cars with all information (both cars with fossil fuel and with electricity) and also the
range for each car.
5) Present all cars that uses fossil fuel (all information)
6) Present all cars that uses electricity as fuel (all information)
7) Calculate the average of consumption of all cars that uses fossil as fuel
8) Present the car that that has the longest range and uses electricity as fuel
9) Find and present the car/cars that uses electricity as fuel that has a range that is more than a
certain value. The user inputs this value.
Besides the inheritance hierarchy you shall also create a class containing the cars (a car container class) in which one (1) statically allocated array of pointers to base class, with the capacity of 15, is used to keep / store all the cars.
In the car container class, you shall also implement copy constructor, assignment operator and a virtual destructor – deep copying is required!
Keyboard input and screen output in the functions within the car container class are not allowed. All cars must always be placed consecutive in the array.
Finally, you shall implement a file containing the main function which corresponds to a menu-based system for handling cars with the functionality described above in 1) – 9).
Other requirements:
• No memory leaks are allowed!
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); at the top of main function and run in debug-mode to detect memory leaks.
• Only private member variables are allowed
• All classes shall be divided into header- and cpp-files.
• The possibility to implement constant member functions shall be used
• Global variables are not allowed
• The menu based system shall handle separate part problems in separate functions

贵阳老马马善福专业维修游泳池堵漏防水工程 既然难,就把悬赏分加上。谢谢
一年多之前 回复
Csdn user default icon