COMSC 200 – Section 8292 – Fall 2025 - PA7
30 points
Due Tuesday November 18 at 11:59PM
Topics: inheritance, polymorphism
Part 1 – Class definitions
Create a base class, called Vehicle. Vehicle is an abstract base class. It has these private members:
vehicle ID
- int
manufacturer
- string
date entered service
- string in YYYYMMDD form
capacity
- int
status
- char
‘A’
- vehicle is active and may be scheduled
‘I’
- vehicle is inactive and is excluded from scheduling
‘M’
- vehicle is currently in maintenance and is excluded from
scheduling
Create three derived classes, each representing a type of vehicle -- Bus, Railcar, and ACab. These classes each
inherit the base Vehicle class, so they share those common characteristics like manufacturer, status, and
capacity. However, the members for Bus, Railcar, and ACab class are different, because each type of vehicle
has characteristics not shared by the others. There are no Vehicles by themselves. Use a base class access
specification of public for all derived classes. Vehicle’s data members are protected, and the derived class
data members are private. Place all four class definitions (Vehicle, Bus, Railcar, and ACab) into a single header
file, and all the member functions into a single cpp file.
Descriptions of members:
Bus members:
mileage since last inspection
tire size
fuel type
- int
- string
- char
‘G’
‘P’
‘E’
- gasoline
- propane
- electric
‘A’
‘D’
- AC electric
- DC electric
Railcar members:
power-on time in days since last inspection - int
motor type
- char
motor voltage
ACab members:
mileage since last inspection
operating hours on battery
- int
- int
- int
software level
- int
Part 2 – Build and populate Vehicle objects.
Dynamically create and manage objects using a single pointer array, similar to what you’ve done in previous
assignments. The pointer array will be of type Vehicle *, and you’ll be dynamically creating Bus, Railcar, and
ACab objects. Data originates from a file, a7dataF25.txt. There is one record per vehicle. For each record,
allocate and populate the appropriate vehicle. Assume that all the data is valid. Record format:
positions
0-4
5-19
20-27
28-30
31
description
vehicle ID
Position 0: type indicator: B, R, or C (Bus, Railcar, ACab)
Positions 1-4: an int which uniquely identifies the vehicle
manufacturer
date vehicle entered service
vehicle capacity
status indicator: A, I, or M (Active, Inactive, in Maintenance)
if Bus:
32-38
39-47
48
mileage since last inspection
tire size
fuel type: G, P, or E (Gasoline, Propane, Electric)
if Railcar:
32-34
35
36-39
power-on time since last inspection, in days
motor type: A or D
motor voltage
if ACab:
32-35
36-39
40-45
mileage since last inspection
battery operating hours
software level
As you read each input record, examine the vehicle ID and determine if the data is for a bus, railcar, or ACab.
Dynamically create the correct type of object. Pass all the input data to a constructor for that object type.
That constructor will in turn invoke the constructor for the Vehicle class to populate the members belonging
to Vehicle.
At EOF, display all the vehicles. The output doesn’t need to be pretty: just enough to make sure that you’re
building all vehicles with the correct data.
Part 3 – Transaction processing
Prompt the console user for a vehicle ID. Given the vehicle ID, display all the data for that vehicle. The display
will have some common elements, like vehicle ID and manufacturer, but will also have some elements which
are specific to the vehicle type: for example, the bus milage or railcar motor type. If the vehicle is not found,
display a “not found” message. Examine the data present for the vehicle and determine if the vehicle is due
for maintenance. If it is, display a message saying that, and change the vehicle status code to M. A vehicle
needs maintenance when:
Bus:
Railcar:
ACab:
the mileage since the last inspection is greater than or equal to 25,000 miles.
the power-on time since the last inspection is 100 days or higher.
the mileage since last inspection is 500 miles or more, or, the battery operating hours is
750 hours or greater.
Coding:
There are three sets of virtual functions – vehicle type, vehicle display, and vehicle maintenance check.
Vehicle is an abstract base class, so there are no virtual functions in that class, but there are prototypes.
Vehicle Type: There is nothing in a Vehicle object that tells you what vehicle type it is, so if you're displaying
information for the user, you need something that can tell you what the type is. Use three virtual functions,
choose a name, one each for Bus, Railcar, and ACab objects. They return an indicator of vehicle type. You can
choose the indicator - a char, or string, etc.
Virtual display functions: There are three of these, one each for Bus, Railcar, and ACab objects. The
information to display is different in each case, so it makes sense to have different functions. But there is also
some information that is common to Bus, Railcar, and ACab objects, like manufacturer and capacity, which are
inherited from the base Vehicle class. Code a function that can be called to display this common information.
Each virtual display function, then, first calls the common display function, and then displays the information
specific to the vehicle type.
Virtual maintenance checking functions: There are three maintenance checking functions, because the
checking technique is different depending on the vehicle type.
Main loops, reading vehicleIDs from the console. Given a vehicleID, it searches the Vehicle structure for that
vehicle, and if found, calls the (virtual) display function. Use the pointer to the object to reference the virtual
function. After the display, main calls the (virtual) maintenance checking function to check, and potentially
change, the maintenance status.
Main only checks the maintenance for vehicles whose ID was entered at the console.
When the user enters a vehicle ID of “0000,” the loop stops.
Sample output:
Enter vehicle ID
1234
Vehicle found - that's a Railcar:
ID / MFR / DATE / CAP / STATUS:
1234 / Nippon / 20130513 / 150 / A
POWERON / MOTORTYPE / VOLTAGE
12500 / AC / 650
Maintenance not needed
Enter vehicle ID
2345
Vehicle found - that's a Bus:
ID / MFR / DATE / CAP / STATUS:
1234 / Chrysler / 20241224 / 115 / A
MILEAGE / TIRESIZE / FUEL
192000 / 65M234 / G
Maintenance Required
Enter vehicle ID
2345
Vehicle found - that's a Bus:
ID / MFR / DATE / CAP / STATUS:
1234 / Chrysler / 20241224 / 115 / M
MILEAGE / TIRESIZE / FUEL
192000 / 65M234 / G
. . .