Question: Objectives 1. Handling exceptions within a program 2. Usingtry/catchblock 3. Building your own exception Question 1 Design a program with vehicle class as base class

Objectives

1. Handling exceptions within a program

2. Usingtry/catchblock

3. Building your own exception

Question 1

Design a program with vehicle class as base class and two classes: car and truck derived from vehicle. The vehicle class has a method to set the type of vehicle. The car and truck classes have two methods, one to set name and the other one to set speed. Write an OverSpeed exception class that checks the speeds of cars and trucks. The overspeed limit of cars > 70 and that of truck > 50.

// Exception class

class OverSpeed {

//Constructor to create OverSpeed s;

// A method to display message

}

// Base class

class vehicle{

public:

setType(string type);

private:

string type;

}

//implement setType(string type);

//Derived class1

class car: public vehicle {

public:

setName(string name);

setSpeed(int speed);

private:

string name;

int speed;

}

//implement setName(string name);

//implement setSpeed(int speed); // OverSpeed exception class

//Derived class2

class truck: public vehicle {

public:

setName(string name);

setSpeed(int speed);

private:

string name;

int speed;

}

//implement setName(string name);

//implement setSpeed(int speed); // OverSpeed exception class

Write a main function and call appropriate methods such that your output matches the given one

Objectives 1. Handling exceptions within a program 2. Usingtry/catchblock 3. Building your

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!