Starting from:
$30

$24

Lab 19 Solution

Objectives:




Handling exceptions within a program



Using try/catch block



Creating exception class






Question:







Design a program that repeatedly asks for the dimensions (length and width) of a rectangle and computes the area. Consider a class Rectangle which includes the following two functions:




void Rectangle::setWidth(int width); void Rectangle::setLength(int length);




If the length and width are positive, then above functions store the values in the Rectangle object. However, if the length and width are negative, the functions throw an object of DimError class that includes a message indicating which method was called and the reason for the error.




Note: DimError class is used by the Rectangle class for showing error messages.




Download lab19.cpp to get the driver function. Submit one single cpp file named as lastname_firstname_lab19.cpp

More products