Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Request help for the following C++ warnings: Line 15: class Square has virtual functions and accessible non-virtual destructor Line 14: class Rectangle has virtual functions

Request help for the following C++ warnings:

Line 15: class Square has virtual functions and accessible non-virtual destructor Line 14: class Rectangle has virtual functions and accessible non-virtual destructor

In function int main()

Line 71: comparing floating point with == or != is unsafe Line 120: comparing floating point with == or != is unsafe Line 150: comparing floating point with == or != is unsafe Line 198: comparing floating point with == or != is unsafe Line 43: switch missing default case

//main.cpp

Line 10: #include //Need this header file to support the C++ I/O system #include "circle.cpp"// including the header and implementation files #include "square.cpp" #include "rectangle.cpp" #include "shape.cpp" //#include

using namespace std;//Telling the compiler to use name space where C++ library is declared

int main( ) { double radius = 0; double length = 0; double width = 0; Square square; Circle circle; Rectangle rectangle;

int shapeid;//shape properties string shapetype; string shapeunit;

int menuOption;//declare menu selection variable do { // Initialize while loop cout << endl << "______Assessment 5: Exceptions______" << endl; cout << "Select a Shape ID or '0' to Exit" << endl; cout << " 1: Square" << endl; cout << " 2: Rectangle" << endl; cout << " 3: Circle" < cout << " 0: Exit" << endl; cout << " Enter Your Choice: "; cin >> menuOption; switch(menuOption)//test variables against a list of values by calling a case { case 1://cycle a potential number of times until the while condition is true {

cout<<"Verify shape id: ";//user enter values cin>>shapeid;//accept the input from the standard input device

square.setShapeID(shapeid);//base class

cout<<"Enter shape name: "; cin>>shapetype;//accept the input from the standard input device square.setShape_type(shapetype);

cout<<"Enter 'mm^2' for shape area unit of measure: ";//square millimeter (mm2) is a metric unit of area equal to 0.000001 square meters cin>>shapeunit;//accept the input from the standard input device square.setUnit(shapeunit);

try//check for error in the condition { cout<< "Enter length of one side of the square : "< cin >> length;//accept the input from the standard input device { if (length < 0) { NegativeValueException e; throw e; } if (length == 0) { ZeroValueException e; throw e; } } } catch(NegativeValueException &e) { cout << e.what(); return 0;//exit the program if a Negative exception was caught } catch(ZeroValueException &e) { cout << e.what(); return 0;//exit the program if a Zero exception was caught }

square.setLength(length);

cout << "Shape ID - " << square.getShapeID() << endl; cout << "Shape type - " << square.getShape_type() << endl; cout<< "Area of the square is "< break;//the loop is immediately terminated and program control resumes at the next statement following the loop } case 3://cycle a potential number of times until the while condition is true { cout<<"Verify shape id : "; cin>>shapeid;//accept the input from the standard input device circle.setShapeID(shapeid);//base class

cout<<"Enter shape name: "; cin>>shapetype;//accept the input from the standard input device circle.setShape_type(shapetype);

cout<<"Enter 'mm^2' for shape area unit of measure: ";//Square Millimeter (mm2) is a metric unit of area equal to 0.000001 square meters cin>>shapeunit;//accept the input from the standard input device circle.setUnit(shapeunit);

try//check for error in the condition { cout<< "Enter the radius : " < cin>> radius;//accept the input from the standard input device { if (radius < 0) { NegativeValueException e; throw e; } if (radius == 0) { ZeroValueException e; throw e; } } } catch(NegativeValueException &e) { cout << e.what(); return 0;//exit the program if a Negative exception was caught } catch(ZeroValueException &e) { cout << e.what(); return 0;//exit the program if a Zero exception was caught } circle.setRadius(radius);

cout << "Shape ID - " << circle.getShapeID() << endl; cout << "Shape type - " << circle.getShape_type() << endl; cout<< "Area of the circle is "<} } } while(menuOption!=0);//until the value is greater than 0 cout<<" ________End Exception Program________" < }()>

//exception.h #include using namespace std;//telling the compiler to use names pace where C++ library is declared

class NegativeValueException : public exception

{

public:

virtual const char * what () const throw ()

{

return "Error:Negative value";

}

};

class ZeroValueException : public exception

{

public:

virtual const char * what () const throw ()

{

return "Error:Zero value";

}

};

//shape.cpp

#include "shape.h"//including the header file #include //need this header file to support the C++ I/O system #include //telling the compiler to use name space where C++ library is declared

using namespace std;//telling the compiler to use names pace where C++ library is declared Shape::Shape(){//declare method area = 0; } double Shape::getArea(){ return area; } void Shape::setShapeID(int Shape_ID) { ShapeID = Shape_ID; } int Shape::getShapeID(void) { return ShapeID; } void Shape::setShape_type(string Shape_type)//writing to output parameters; control returns back to the caller { ShapeType = Shape_type; } string Shape::getShape_type(void) { return ShapeType; } void Shape::setUnit(string unit) { unit = unitM; } string Shape::getUnit(void) { return unitM; }

//shape.h #ifndef SHAPE_H #define SHAPE_H #include #include using namespace std; class Shape { // Base Class public: Shape(); double getArea(); void setShapeID(int Shape_ID); void setShape_type(string Shape_type); void setUnit(string unit); int getShapeID(void); string getShape_type(void); string getUnit(void); int ShapeID; string ShapeType; string unitM; private: double area; }; #endif // SHAPE_H_INCLUDED

//square.cpp

#include "square.h"//including the header file #include //need this header file to support the C++ I/O system using namespace std;//telling the compiler to use names pace where C++ library is declared

Square::Square(double len)//declare method used for square shape { length = len;//parameterized constructor }

double Square::getLength() {//iterate through the list of attributes return length;//returns the count of attributes }

void Square::setLength(double len){//writing to output parameters; control returns back to the caller length = len; }

double Square::getArea(){ return length * length;//returning length & width }

/square.h

#ifndef SQUARE_H #define SQUARE_H #include //need this header file to support the C++ I/O system #include "shape.h"//including the header file

using namespace std;//telling the compiler to use names pace where C++ library is declared class Square : public Shape//square class { public://declare square access specifier Square (double length =0);//parameterized constructor double getLength();//retrieve length void setLength(double length);//set length virtual double getArea ();//retrieve area private: double length;// length value declaration access specifier }; #endif // SQUARE_H INCLUDED

//rectangle.cpp #include "rectangle.h"//including the header file #include //need this header file to support the C++ I/O system using namespace std;//telling the compiler to use names pace where C++ library is declared Rectangle::Rectangle(double len, double wid)//declare method used for rectangle shape { length = len; width = wid; } double Rectangle::getLength() {//iterate through the list of attributes return length;//returns the count of attributes } void Rectangle::setLength(double len){//writing to output parameters; control returns back to the caller length = len; } double Rectangle::getWidth() { return width; } void Rectangle::setWidth(double wid){ width= wid; } double Rectangle::getArea(){ return length * width;//returning length and width }

//rectangle.h #ifndef RECTANGLE_H_INCLUDED #define RECTANGLE_H_INCLUDED #include //need this header file to support the C++ I/O system

#include "shape.h"//including the header file

class Rectangle: public Shape//square structure class { public://declare square access specifier Rectangle (double length =0, double width =0);//parameterized constructor double getLength();//retrieve length double getWidth();//retrieve width void setLength(double length);//set length void setWidth(double width);//set width virtual double getArea ();//retrieve area private: double length;//length value declaration access specifier double width;//width value declaration access specifier }; #endif // RECTANGLE_H_INCLUDED

//circle.cpp

#include "circle.h"//include the header file #include //need this header file to support the C++ I/O system using namespace std;//telling the compiler to use names pace where C++ library is declared

Circle::Circle (double r=0)// declare circle method { radius = r; } double Circle::getRadius() {//iterate through the list of attributes return radius;//returns the count of attributes } void Circle::setRadius (double r){//writing to output parameters; control returns back to the caller radius = r;//Parameterized constructor } double Circle::getArea(){ return radius * radius * 3.14159;//retrieve and store value of the area }

//circle.h

#ifndef CIRCLE_H #define CIRCLE_H #include "shape.h"//including the header file using namespace std;//telling the compiler to use names pace where C++ library is declared

class Circle : public Shape//circle structure class { public://declare circle access specifier Circle (double r);//parameterized constructor double getRadius();//retrieve radius value void setRadius (double r);//set radius value double getArea();//retrieve area value private: double radius;//declare value for the radius access specifiers }; #endif // CIRCLE_H INCLUDED

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

Step: 3

blur-text-image

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

What is goodwill and how is it measured?

Answered: 1 week ago

Question

=+4. Are there areas where you are seeing healing take root?

Answered: 1 week ago