[go: up one dir, main page]

0% found this document useful (0 votes)
6 views3 pages

Week10 Labexam3 GroupA

The document outlines a lab exam for COMP 2215 focusing on implementing a vehicle routing simulation using inheritance in C++. It describes the creation of a 'Checkpoint' class and a base 'Vehicle' class, along with derived classes like 'Car' that exhibit different behaviors in selecting checkpoints. The simulation involves creating checkpoints, simulating vehicle movements, and calculating total delivery time, with specific instructions for file creation and implementation details.

Uploaded by

sheliaece1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Week10 Labexam3 GroupA

The document outlines a lab exam for COMP 2215 focusing on implementing a vehicle routing simulation using inheritance in C++. It describes the creation of a 'Checkpoint' class and a base 'Vehicle' class, along with derived classes like 'Car' that exhibit different behaviors in selecting checkpoints. The simulation involves creating checkpoints, simulating vehicle movements, and calculating total delivery time, with specific instructions for file creation and implementation details.

Uploaded by

sheliaece1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

COMP 2215 WEEK – 10 LAB EXAM - 3(INHERITANCE IN C++)

Vehicle Routing Simulation (Section – 1)

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

B. Define the base class ‘Vehicle’

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

• manufacturer: String representing the vehicle's make (e.g., Toyota, Ford)

• model: String representing the vehicle's model (e.g., Corolla, F150)

• x_speed: Double representing the vehicle's speed along the x-axis

• y_speed: Double representing the vehicle's speed along the y-axis

• current_checkpoint: The vehicle's current position as a Checkpoint object. This


will be home depot in the beginning of the simulation.

• visitedCheckpoints[10]: Boolean array tracking which checkpoints have been


visited

• time: Double tracking the total travel time in minutes

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

Checkpoint Tracking Methods

• markCheckpointVisited: Sets a checkpoint as visited in the tracking array.


• hasVisitedAllCheckpoints: Checks if all checkpoints have been visited.
• isCheckpointVisited: Checks if a specific checkpoint has been visited.

C. Create derived class Car


• Sets the x_speed and y_speed to 5.0 in the constructor
• Implements the pickNextCheckpoint method to select the next checkpoint
randomly from the unvisited checkpoints.

D. Implement the main


• Create 10 instances of checkpoints with names "Checkpoint 1" through
"Checkpoint 10"
• Displays information about all created checkpoints.
• Create a Car object (Toyota Corolla)
• Simulate Car visiting all checkpoints until completion.
• Displays which checkpoint Car is visiting and the time after each move.
• Shows the total time taken by Car after completion.

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:

You might also like