Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create 2 custom exception classes that inherit from std::exception to handle invalid dimensions for shapes (such as 0 and negative numbers). Revise the code in

Create 2 custom exception classes that inherit from std::exception to handle invalid dimensions for shapes (such as 0 and negative numbers). Revise the code in your program's classes and man() to use these custom exception classes.

Here is the code I have to revise. PLEASE HIGHLIGHT THE CHANGES YOU MAKE THANK YOU.

#include using namespace std; const float PI = 3.1415926;

class Shape{ private: string shapeType; string shapeId; string unit_of_measure;

public: Shape(){} Shape(string id){ shapeId = id; } Shape(string Id, string type, string unit){ shapeId = Id; shapeType = type; unit_of_measure= unit; }

string getShapeType(){ return shapeType; }

string getSgapeId(){ return shapeId; }

string getUnitOfMeasure(){ return unit_of_measure; }

void setShapeType(string type){ shapeType = type; } void setShapeId(string id){ shapeId = id; } void setUnitOfMeasure(string unit){ unit_of_measure = unit; }

virtual float getArea() = 0; };

/* Circle Class */ class Circle: public Shape { private: float radius; public: /* set value for radius */ void setRadius(float r) { radius = r; } /* get the value of radius */ float getRadius() { return radius; } /* Constructor */ Circle():Shape() { radius = 0; } /* Copy Constructor, which takes a parameter */ Circle(string id, float r):Shape(id) { radius = r; }

Circle(string id, string type, string unit, float r): Shape(id, type, unit){ radius = r; } /* Method to calculate the area of circle */ float getArea() { return PI*radius*radius; }

void display(){ cout<<"Shape Id: "< cout<<"Shpae Type: "< cout<<"Unit of Measure: "< cout<<"Area: "< cout< } };

/* Square Class */ class Square:public Shape { private: float length; public: /* get the value of length */ float getLength() { return length; } /* set value for length */ void setLength(float l) { length = l; } /* Constructor */ Square(): Shape(){ length = 0; } /* Copy Constructor, which takes a parameter */ Square(string id, float l):Shape(id) { length = l; }

Square(string id, string type, string unit, float l): Shape(id, type, unit){ length = l; } /* Method to calculate the area of circle */ float getArea() { return length * length; }

void display(){ cout<<"Shape Id: "< cout<<"Shpae Type: "< cout<<"Unit of Measure: "< cout<<"Area: "< cout< } };

/* Rectangle Class */ class Rectangle:public Shape { private: float length, width; public: /* get the value of length */ float getLength() { return length; }

float getWidth(){ return width; } /* set value for length */ void setLength(float l) { length = l; }

void setWidth(double w){ width = w; } /* Constructor */ Rectangle(): Shape(){ length = 0; width = 0; } /* Copy Constructor, which takes a parameter */ Rectangle(string id, float l, float w):Shape(id) { length = l; width = w; }

Rectangle(string id, string type, string unit, float l, float w): Shape(id, type, unit){ length = l; width = w; } /* Method to calculate the area of circle */ float getArea() { return length * width; }

void display(){ cout<<"Shape Id: "< cout<<"Shpae Type: "< cout<<"Unit of Measure: "< cout<<"Area: "< cout< } }; int main() { Circle circle1; Square square1; Rectangle rectangle1; int menuOption;

string id, type, unit;

do { // Starting of while loop cout << endl << "=========CALCULATE AREA================" << endl; cout<< endl << "Select an Object" << endl << " 1: Circle" << endl << " 2: Square" << endl << " 3: Rectangle "< << " 0: Exit" << endl << " Enter Your Choice: "; cin >> menuOption;

switch(menuOption) { case 1: cout<<"Enter shape id: "; cin>>id; cout<<"Enter unit of measure: "; cin>>unit; cout<< "Enter radius of the circle : "; float radius ; cin >> radius; circle1.setRadius(radius); circle1.setShapeId(id); circle1.setUnitOfMeasure(unit); circle1.setShapeType("Circle"); //cout << "Area of Circle : " << circle1.getArea()<< endl; circle1.display(); break; case 2: cout<<"Enter shape id: "; cin>>id; cout<<"Enter unit of measure: "; cin>>unit; cout<< "Enter length of one side of the square : "; float l ; cin >> l; square1.setLength(l); square1.setShapeId(id); square1.setShapeType("Square"); square1.setUnitOfMeasure(unit); square1.display(); //cout << "Area of Square : " << square1.getArea()<< endl; break; case 3: cout<<"Enter shape id: "; cin>>id; cout<<"Enter unit of measure: "; cin>>unit; cout<< "Enter length of side of the rectangle : "; float le ; cin >> le; cout<< "Enter width of side of the rectangle : "; float w ; cin >> w; rectangle1.setLength(le); rectangle1.setWidth(w); rectangle1.setShapeId(id); rectangle1.setShapeType("Rectangle"); rectangle1.setUnitOfMeasure(unit); rectangle1.display(); //cout << "Area of Square : " << square1.getArea()<< endl; break;

} } while(menuOption!=0); cout << endl<< endl << "============== THANK YOU ===================" << endl<< endl; return 0; }

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_2

Step: 3

blur-text-image_3

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

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions

Question

Approaches to Managing Organizations

Answered: 1 week ago

Question

Communicating Organizational Culture

Answered: 1 week ago