Question: C++ Exceptions Program Help Hello, need help with my c++ program, it must work with this main function. Expected output is also given. Rating best/helpful

C++ Exceptions Program Help

Hello, need help with my c++ program, it must work with this main function. Expected output is also given. Rating best/helpful solution thumbs up!

C++ Exceptions Program Help Hello, need help with my c++ program, it

must work with this main function. Expected output is also given. Rating

My program so far..:

#include

#include

using namespace std;

class car

{

private:

int speed; //private

int limit; //private

string name; //private

public:

car()

{

}

car(int speed, int limit)

{

//throw/catch

}

car(int speed, int limit, string name)

{

//throw/catch error

}

void setSpeed(int speed)

{

this->speed = speed;

}

int getSpeed() const

{

return this->speed;

}

void setLimit(int limit)

{

this->limit = limit;

}

int getLimit() const

{

return this->limit;

}

};

class myException: public exception //must inherit from c++ exception class

{

private:

public:

myException()

{

}

myException(string text)

{

}

int what()

{

//override the what function in myCustomException class to give a more personalized message

}

};

class myCustomException

{

private:

string message; //private

int carSpeed; //private

int carLimit; //private

public:

myCustomException()

{

}

myCustomException(int carSpeed, int carLimit)

{

}

myCustomException(string text)

{

}

int what()

{

//Sample error message, needs to be in throw catch format

cout

cout

cout

cout

}

};

int main()

{

/*

car newCar;

try

{

newCar.setLimit(100);

newCar.setSpeed(250);

}

catch(myException& e)

{

cout

}

catch(myCustomException& e)

{

cout

}

try

{

car otherCar(100, 50); //throws the speed>limit error

}

catch(myException& e)

{

e.what();

}

catch(myCustomException& e)

{

cout

}

try

{

car otherCar(100, 250, "name"); // throws the length error

}

catch(myException& e)

{

e.what();

}

catch(myCustomException& e)

{

cout

}

*/

return 0;

}

The goal is to throw exceptions whenever the following situations happen inside the car class: . Speed is more than the limit. Name of the car is smaller than 5 characters and larger than 20 characters. Include throw statements wherever the above-mentioned situations happen inside the car class. The goal is to throw exceptions whenever the following situations happen inside the car class: . Speed is more than the limit. Name of the car is smaller than 5 characters and larger than 20 characters. Include throw statements wherever the above-mentioned situations happen inside the car class

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!