Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

++ 10. The following task deals with exception handling You will implement two classes for this. The first class is called Road. It has only

++ image text in transcribed
10. The following task deals with exception handling You will implement two classes for this. The first class is called Road. It has only one private member variable int slimit. The second class is called Vehicle. It has three private member variables int curspeed, int maxspeed and Road carroad. The following tasks are to be accom- plished. For your solution, you can assume that all code is written to a single source code file that also contains the main function. There is no need for extra header files and source code files in addition to this one source code file: (a) Define the class Road. The member functions, mentioned below, are to be declared only within the class definition no inline definitions of the member functions). The member functions are then to be defined implemented) after the class definition (b) Define the default constructor Road-Road(): default constructor of the class Road. It initial- izes slimit to 0. (e) Define the parameterized constructor Road-Roadint speedlimit): parametrized constructor of the class Road. To store speedlimit, call the member function set Speed Limit() within the constructor (d) Define the public function void Road.setSpeed Limit(int limit): set the maximum road speed. If a negative speed is entered, the error message "No negative Speed Limit" is to be thrown (type: invalid_argument). Otherwise the value is to be assigned to the proper member variable. (e) Define the public function int Road:getSpeed Limit()const: this function returns the road's speed limit. (f) Define the class Vehicle. The member functions are only to be declared within the class definition (no inline definitions of the member functions). The member functions are to be defined implemented) after the class definition. (8) Define the parametrized constructor Vehicle Vehicle(int maxspeed, Road carroad): constructor for creating an object. Initially the variable curspeed_ should be set to 0. In addition, the value of the variable maxspeed is to be assigned to maxspeed. Then the element function change Road() should be called to store curread. (h) Define the public function void Vehicle change Road(Road newroad): Set the current road by assigning newroad to carroad. If the current speed of the vehicle, caurspeed, exceeds the maximum permitted speed of the road, the error message "Current Speed exceeds Speed Limit" is to be thrown (type: invalid_argument). (1) Define the public function void Vehicle::setSpeed intsespeed): Set the current speed by as- signing newspeed to curspeed, if no exceptions are thrown. If newspeed is above the max- imum speed of the car, the error message "New Speed exceeds Vehicle maximum Speed" is to be thrown (Type: invalid argument). If newspeed is above the road's maximum speed, the error message "New Speed exceeds Road's Speed Limit" is to be thrown (type: invalid argument). 6) Define the public function int Vehicle = getSpeed() const: returns the current vehicle speed. (k) Write down how to call the member function setSpeed) in the main function at the location marked by your code below such that the exception "New Speed exceeds Road's Speed Limit" is triggered. The other entries in the main function do not need to be repeated. 10. The following task deals with exception handling You will implement two classes for this. The first class is called Road. It has only one private member variable int slimit. The second class is called Vehicle. It has three private member variables int curspeed, int maxspeed and Road carroad. The following tasks are to be accom- plished. For your solution, you can assume that all code is written to a single source code file that also contains the main function. There is no need for extra header files and source code files in addition to this one source code file: (a) Define the class Road. The member functions, mentioned below, are to be declared only within the class definition no inline definitions of the member functions). The member functions are then to be defined implemented) after the class definition (b) Define the default constructor Road-Road(): default constructor of the class Road. It initial- izes slimit to 0. (e) Define the parameterized constructor Road-Roadint speedlimit): parametrized constructor of the class Road. To store speedlimit, call the member function set Speed Limit() within the constructor (d) Define the public function void Road.setSpeed Limit(int limit): set the maximum road speed. If a negative speed is entered, the error message "No negative Speed Limit" is to be thrown (type: invalid_argument). Otherwise the value is to be assigned to the proper member variable. (e) Define the public function int Road:getSpeed Limit()const: this function returns the road's speed limit. (f) Define the class Vehicle. The member functions are only to be declared within the class definition (no inline definitions of the member functions). The member functions are to be defined implemented) after the class definition. (8) Define the parametrized constructor Vehicle Vehicle(int maxspeed, Road carroad): constructor for creating an object. Initially the variable curspeed_ should be set to 0. In addition, the value of the variable maxspeed is to be assigned to maxspeed. Then the element function change Road() should be called to store curread. (h) Define the public function void Vehicle change Road(Road newroad): Set the current road by assigning newroad to carroad. If the current speed of the vehicle, caurspeed, exceeds the maximum permitted speed of the road, the error message "Current Speed exceeds Speed Limit" is to be thrown (type: invalid_argument). (1) Define the public function void Vehicle::setSpeed intsespeed): Set the current speed by as- signing newspeed to curspeed, if no exceptions are thrown. If newspeed is above the max- imum speed of the car, the error message "New Speed exceeds Vehicle maximum Speed" is to be thrown (Type: invalid argument). If newspeed is above the road's maximum speed, the error message "New Speed exceeds Road's Speed Limit" is to be thrown (type: invalid argument). 6) Define the public function int Vehicle = getSpeed() const: returns the current vehicle speed. (k) Write down how to call the member function setSpeed) in the main function at the location marked by your code below such that the exception "New Speed exceeds Road's Speed Limit" is triggered. The other entries in the main function do not need to be repeated

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building The Data Warehouse

Authors: W. H. Inmon

4th Edition

0764599445, 978-0764599446

Students also viewed these Databases questions