Week10 Labexam3 GroupA
Week10 Labexam3 GroupA
Objective
In this exam, you will implement a vehicle routing simulation where vehicles traverse
through 10 different checkpoints to deliver packages. This simulation demonstrates
inheritance through different vehicle types that implement a common interface but
exhibit distinct behaviours. In this case Car (Section 1) and Truck(Section 2). Car is said
to be more agile but chooses next point randomly while Truck goes to its nearest
neighbour from each point. Program eventually calculates their total delivery time.
Instructions
A. Define the class ‘Checkpoint’
• Attributes:
1. id : int
2. X_Coordinate: double
3. Y_Coordinate: double
4. name: string
• Static Attribute:
1. ID_COUNTER : int => used to assign unique IDs to checkpoints
• Default Constructor:
1. Creates a “Starting Depot” at position(0,0) with id=99 this will be used
as initial position for every new Vehicle
• Parameterized Constructor:
1. Creates a Checkpoint with a given name(parameter) and random
position between -100 and 100 for both x and y coordinates and
should be assigned next ID through ID_COUNTER static variable.
• Getters for
1. X_Coordinate,Y_Coordinate,Id,name
Vehicle.h and Vehicle.cpp are given as full source code with this assignment. Include
the code by copy pasting into your project.
The Vehicle class is an abstract base class that serves as the foundation for all specific
vehicle types in the simulation. It defines the common structure and behaviour that all
vehicles share, while allowing for different implementations of certain behaviours
through polymorphism.
Attributes
move Method
• Moves the vehicle from its current position to the next checkpoint
• Calculates Manhattan distance between current and next checkpoint
• Calculates time needed based on the distance and the vehicle's speed
• Updates the total travel time
• Updates the current position
• Marks the checkpoint as visited
PickNextCheckpoint Method
• Pure virtual method that must be implemented by derived classes (Car, Truck)
• Determines how a specific vehicle type selects its next destination.
• Returns the index of the next checkpoint to visit
• This is where polymorphism occurs in the simulation
E. Files to be created
The 7 files that need to be created are as follows:
1) main.cpp (1 Point)
2) Vehicle.h (already supplied)
3) Vehicle.cpp (already supplied)
4) Car.h (1 Point)
5) Car.cpp (3 Points) (2 Pts for PickNextCheckpoint , 1 for rest )
6) Checkpoint.h (1 Point)
7) Checkpoint.cpp (1 Point)
Sample Screenshot: