Question: Need Help! for C++ Please modify the code below the area calculation application to handle exceptions. You will use the Code::Blocks software to write this

Need Help! for C++

Please modify the code below the area calculation application to handle exceptions. You will use the Code::Blocks software to write this application. Use custom exception classes that inherit from std::exception. 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 main() to use these custom exception classes. Please take a screen shot of the result. Thank you.

//Area Calculation Code:

#include #include "circle.h"

void circle::get_data() // To get data from User { cout<<" =====Data Entry for Circle===== "; cout<<"Enter radius of circle: "; cin>>data; } void circle::display_area() //To display area of circle { cout<<" =====Area of Circle===== "; double aoc; aoc=3.14*data*data; cout<<"Area of Circle is "< }

#ifndef CIRCLE_H #define CIRCLE_H #include "shape.h"

class circle: public shape { // circle class

public : void get_data(); void display_area(); };

#endif

#include #include "equilateral.h"

void equilateral::get_data(void) // To get data from User { cout<<" =====Data Entry for Triangle===== "; cout<<"Enter side of triangle: "; cin>>data; } void equilateral::display_area(void) //To display area of triangle { cout<<" =====Area of Triangle===== "; double aot; aot=0.43301*data*data; cout<<"Area of Equilateral Triangle is "< }

#ifndef EQUILATERAL_H #define EQUILATERAL_H

#include "shape.h"

class equilateral: public shape{ // equilateral class

public: void get_data(); void display_area();

}; #endif

#include "shape.h" #include "square.h" #include "circle.h" //Header Files Declaration #include "equilateral.h"

#include

using namespace std;

int main(void) //Beginning of driver function {

shape *list[3]; //Array to store shape pointers list[0]=new square(); list[1]=new circle(); list[2]=new equilateral();

int choice; while(1) //Loop implements until exit { cout<<" =====MEASURES OF DIFFERENT SHAPE===== "; cout<<" Choose your choice "; cout<<"1) Area of Square "; cout<<"2) Area of Circle "; //Choice for different operations cout<<"3) Area of Equilateral "; cout<<"4) Exit "; cout<<"Enter your choice:-"; cin>>choice; switch(choice) { case 1 : list[0]->get_data(); //Calling of methods to evaluate and display area list[0]->display_area();

break; case 2 : list[1]->get_data(); list[1]->display_area();

break; case 3 : list[2]->get_data(); list[2]->display_area();

break; case 4 : return 0; default: cout<<" Invalid choice Try again "; //Output if user gives invalid entry

} } return 0; //End of main() function

}

#include "shape.h"

void shape::get_data(){} //Abstract methods default implementation void shape::display_area(){}

#ifndef SHAPE_H #define SHAPE_H

class shape { // shape class public: virtual void get_data(); //Abstract methods used to implement inheritance virtual void display_area();

protected : double data; };

#endif

#include #include "square.h"

using namespace std;

void square::get_data() // To get data from User { cout<<" =====Data Entry for Square===== "; cout<<"Enter side of square: "; cin>>data; }

void square::display_area() //To display area of square { cout<<" =====Area of Square===== "; double aos; aos=data*data; cout<<"Area of Square is "< }

#ifndef SQUARE_H #define SQUARE_H

#include "shape.h"

class square: public shape { // square class public: void get_data(); void display_area(); };

#endif

#include #include

class shape { protected: double x,y; public: virtualvoid get_data()=0; virtualvoid display_area()=0; };

class triangle : public shape { public: void get_data(void) { cout<<" =====Data Entry for Triangle===== "; cout<<"Enter base and height respectively : "; cin>>x>>y; } void display_area(void) { cout<<" =====Area of Triangle===== "; double aot; aot = 0.5 * x * y; cout<<"Area of Triangle is "< } };

class rectangle : public shape { public: void get_data(void) { cout<<" =====Data Entry for Rectangle===== "; cout<<"Enter length of two sides : "; cin>>x>>y; } void display_area(void) { cout<<" =====Area of rectangle===== "; double aor; aor = x * y; cout<<"Area of Rectangle is "< } };

void main() { clrscr(); triangle tri; rectangle rect; shape *list[2]; list[0]=&tri; list[1]=

int choice; while(1) { clrscr(); cout<<" =====MEASURES OF DIFFERENT SHAPE===== "; cout<<" Choose your choice "; cout<<"1) Area of Triangle "; cout<<"2) Area of Rectangle "; cout<<"3) Exit "; cout<<"Enter your choice:-"; cin>>choice; switch(choice) { case 1 : list[0]->get_data(); list[0]->display_area(); getch(); break; case 2 : list[1]->get_data(); list[1]->display_area(); getch(); break; case 3 : goto end; default: cout<<" Invalid choice Try again "; getch(); } } end: }

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!