The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
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. *below is the original code that needs to be modified*
#include <iostream>
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: "<<getSgapeId()<<endl;
cout<<"Shpae Type: "<<getShapeType()<<endl;
cout<<"Unit of Measure: "<<getUnitOfMeasure();
cout<<"Area: "<<getArea()<<endl;
cout<<endl;
}
};
/* 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: "<<getSgapeId()<<endl;
cout<<"Shpae Type: "<<getShapeType()<<endl;
cout<<"Unit of Measure: "<<getUnitOfMeasure();
cout<<"Area: "<<getArea()<<endl;
cout<<endl;
}
};
/* 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: "<<getSgapeId()<<endl;
cout<<"Shpae Type: "<<getShapeType()<<endl;
cout<<"Unit of Measure: "<<getUnitOfMeasure();
cout<<"Area: "<<getArea()<<endl;
cout<<endl;
}
};
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 "<<endl
<< " 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;
}
Â