Question

Please use C++ and Please do all file separate separately. And also I need output too....

Please use C++ and Please do all file separate separately. And also I need output too. thanks.

Please do it complete work.

ShapeNodePoly.cpp

Avaliable from: Wednesday, July 27, 2016, 10:20 AM
Requested files: Point.h, Point.cpp, Shape.h, Shape.cpp, Polygon.h, Polygon.cpp, Ellipse.h, Ellipse.cpp, ShapeNodePoly.cpp, ShapeNodePoly_test.cpp (Download)
Type of work: Individual work

In this assignment, you will create a class that can behave as any of the shapes listed below. You will use object inheritance to enable all shapes to be managed using the same interface. The functions named in your interface file will be polymorphic; they behave differently depending on the instance of a shape is being emulated by an object.

Using the combination of inheritance and function overloading, you will design a program that can manipulate a group of objects derived from the base class Shape. A Shape is an abstract class that can be used to represent instances of the following geometric shapes:

A Triangle

A Rectangle

A Square

An Oval

A Circle

An Elliipse

Your program should contain classes to create each type of object listed above. You should design an inheritance hierarchy where all classes are derived from an abstract class called Shape. The shape class should have a virtual function getArea() that when invoked on an object will return the area of that shape object. You should insert the code from the GeometricArea program for the appropriate type of shape object. Here is a guide to calculating the area of an ellipse and how it relates to a circle.

Your program should make use of a concrete class named Point. Point has two fields of type float: x and y representing a Cartesian coordinate that identifies a location in the xy plane. Each shape should contain the necessary fields to represent itself: for example, a triangle would contain 3 Point objects, a circle 1 Point.

Be sure to consider using intermediate classes. For example, Triangle, Rectangle, Square are all polygons, so it is good design practice to create an intermediate class Polygon, from which Triangle, Rectangle and Square are all derived. There is a similar relationship between an ellipse and a circle; a circle is an ellipse where the two focal points are the same and the length of the major and minor radii are the same.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot of the code:

Point.h

#1fndef POINT H define POINT H #include <iostream> //Use the standard namespace. using namespace std; //Define the class Poin

Point.cpp

Shape.h

Shape.cpp

Polygon.h

Polygon.cpp

Ellipse.h

Ellipse.cpp

ShapeNodePoly.cpp

Sample Output:

Code to Copy:

Point.h

#ifndef POINT_H

#define POINT_H

#include <iostream>

//Use the standard namespace.

using namespace std;

//Define the class Point.

class Point

{

     //Declare the variables.

     float x_cordinate, y_cordinate;

     //Define the access specifier.

public:

     //Default constructor.

     Point();

     //Define the setter functions.

     void setX(float X_val);

     void setY(float Y_val);

     //Define the getter functions.

     float getX();

     float getY();

};

#endif

Point.cpp

#include "Point.h"

//Default constructor.

Point::Point()

{

     x_cordinate = 0.0;

     y_cordinate = 0.0;

}

//Define the setter functions.

void Point::setX(float X_val)

{

     x_cordinate = X_val;

}

void Point::setY(float Y_val)

{

     y_cordinate = Y_val;

}

Shape.h

#ifndef SHAPE_H

#define SHAPE_H

#include "Point.h"

//Define the class Shape.

class Shape

{

     //Define the access specifier.

public:

     //Every shape has at-least a single point.

     Point object_P;

     //Function to set the data points.

     virtual void setData() = 0;

     //Function to compute the area of the shape.

     virtual double getArea() = 0;

};

#endif

Shape.cpp

#include "Shape.h"

void Shape:: setData()

{

     return;

}

double Shape::getArea()

{

     return 0.0;

}

Polygon.h

#pragma once

#ifndef POLYGON_H

#define POLYGON_H

#include "Shape.h"

//Define the class Polygon derived

//from the Shape class.

class Polygon :public Shape

{

    

     //Define the access specifier.

public:

     Polygon();

     Point object_Q, object_R;

};

#endif

Polygon.cpp

#include "Polygon.h"

Polygon::Polygon()

{

}

Ellipse.h

#pragma once

#ifndef ELLIPSE_H

#define ELLIPSE_H

#include "Shape.h"

//Define the class Ellipse derived from Shape.

class Ellipse :public Shape

{

     //Define the access specifier.

protected:

     //Declare the variables.

     Point object_Q;

     double radius_major, radius_minor;

     //Define the access specifier.

public:

     //Define the function to set the data.

     void setData();

     //Define the function to compute the

     //area of the ellipse.

     double getArea();

};

#endif

Ellipse.cpp

#include "Ellipse.h"

//Define the function to set the data.

void Ellipse::setData() //set the radii & the focal points

{

     float cordinate_X, cordinate_Y;

     cout << "Enter X Co-ordinate for the 1st"

          " Focal Point : ";

     cin >> cordinate_X;

     cout << "Enter Y Co-ordinate for the 1st"

          " Focal Point : ";

     cin >> cordinate_Y;

     //Set the first coordinate.

     object_P.setX(cordinate_X);

     object_P.setY(cordinate_Y);

     cout << "Enter X Co-ordinate for the 2nd"

          " Focal Point :";

     cin >> cordinate_X;

     cout << "Enter Y Co-ordinate for the 2nd"

          " Focal Point :";

     cin >> cordinate_Y;

     //Set the second coordinate.

     object_Q.setX(cordinate_X);

     object_Q.setY(cordinate_Y);

     cout << "Enter the Major radius : ";

     cin >> radius_major;

     cout << "Enter the Minor radius : ";

     cin >> radius_minor;

}

//Define the function to compute the

//area of the ellipse.

double Ellipse::getArea()

{

     return 3.14159*radius_major*radius_minor;

}

ShapeNodePoly.cpp

//Include the header file for visual studio.

//Otherwise remove the below header file.

#include "stdafx.h"

//Include the header files.

#include <iostream>

#include <cmath>

#include "Point.h"

#include "Polygon.h"

#include "Shape.h"

#include "Ellipse.h"

//Use the standard namespace.

using namespace std;

//Define the function to compute the distance

//between the two points.

double getDistance(Point P1, Point P2)

{

     //Return the distance using distance formulae.

     return(sqrt(((P2.getY() - P1.getY())

          *(P2.getY() - P1.getY()))

          + ((P2.getX() - P1.getX())

               *(P2.getX() - P1.getX()))));

}

//Define the class Triangle derived from Polygon.

class Triangle :public Polygon

{

//Define the access specifier.

public:

     //Define the function to set the data.

     void setData()

     {

          float cordinate_X, cordinate_Y;

          cout << "Enter the co-ordinates for the "

               "three vertices of the triangle:-" << endl;

          cout << "Enter X Co-ordinate for the 1st Point : ";

          cin >> cordinate_X;

          cout << "Enter Y Co-ordinate for the 1st Point : ";

          cin >> cordinate_Y;

         

          //Set the first coordinate.

          object_P.setX(cordinate_X);

          object_P.setY(cordinate_Y);

          cout << "Enter X Co-ordinate for the 2nd Point : ";

          cin >> cordinate_X;

          cout << "Enter Y Co-ordinate for the 2nd Point : ";

          cin >> cordinate_Y;

          //Set the second coordinate.

          object_Q.setX(cordinate_X);

          object_Q.setY(cordinate_Y);

          cout << "Enter X Co-ordinate for the 3rd Point : ";

          cin >> cordinate_X;

          cout << "Enter Y Co-ordinate for the 3rd Point : ";

          cin >> cordinate_Y;

          //Set the Third coordinate.

          object_R.setX(cordinate_X);

          object_R.setY(cordinate_Y);

     }

     double getArea()

     {

          //Compute the area of the triangle using

          //the coordinates of the vertices.

          double triangle_area = abs((object_P.getX()

               *(object_Q.getY() - object_R.getY())

               + object_Q.getX()*(object_R.getY() - object_P.getY())

               + object_R.getX()*(object_P.getY()

                     - object_Q.getY())) / 2);

          //Return the area.

          return triangle_area;

     }

}; //Triangle

class Rectangle :public Polygon

{

//Define the access specifier.

protected:

     Point S;

//Define the access specifier.

public:

     //Define the function to set the data.

     void setData()

     {

          float cordinate_X, cordinate_Y;

          cout << "Enter the Co-ordinates for the"

               " four vertices :-" << endl;

          cout << "Enter X Co-ordinate for the 1st Point : ";

          cin >> cordinate_X;

          cout << "Enter Y Co-ordinate for the 1st Point : ";

          cin >> cordinate_Y;

          //Set the first coordinate.

          object_P.setX(cordinate_X);

          object_P.setY(cordinate_Y);

          cout << "Enter X Co-ordinate for the 2nd Point : ";

          cin >> cordinate_X;

          cout << "Enter Y Co-ordinate for the 2nd Point : ";

          cin >> cordinate_Y;

          //Set the second coordinate.

          object_Q.setX(cordinate_X);

          object_Q.setY(cordinate_Y);

          cout << "Enter X Co-ordinate for the 3rd Point : ";

          cin >> cordinate_X;

          cout << "Enter Y Co-ordinate for the 3rd Point : ";

          cin >> cordinate_Y;

          //Set the Third coordinate.

          object_R.setX(cordinate_X);

          object_R.setY(cordinate_Y);

          cout << "Enter X Co-ordinate for the 4th Point : ";

          cin >> cordinate_X;

          cout << "Enter Y Co-ordinate for the 4th Point : ";

          cin >> cordinate_Y;

         

          //Set the Fourth coordinate.

          S.setX(cordinate_X);

          S.setY(cordinate_Y);

     }

     //Prototype of the function.

     friend double getDistance(Point A, Point B);

     //Define the function to compute the

     //area of the rectangle.

     double getArea()

     {

          //Compute the length of the rectangle.

          double length = getDistance(object_P, object_Q);

          //Compute the length of the rectangle.

          double breadth = getDistance(object_Q, object_R);

          //Return the area of the rectangle

          //which is length * breadth.

          return length*breadth;

     }

};

//Define the class Square derived from Rectangle.

class Square :public Rectangle

{

//Define the access specifier.

public:

     //Prototype of the function.

     friend double getDistance(Point p1, Point p2);

     //Define the function to compute the

     //area of the square.

     double getArea()

     {

          //Compute the side of the square.

          double side = getDistance(object_P, object_Q);

          //Return the area of the square

          //which is side * side.

          return side*side;

     }

};

class Oval :public Ellipse

{

     //Its just an other name of Ellipse.

     //This will inherite all the methods and the

     //attributes of the class Ellipse.

    

};

//Define the class Circle.

class Circle :public Ellipse

{

//Define the access specifier.

public:

     //Define the function to set the data.

     void setData() //set the center and radius of the circle

     {

          float cordinate_X, cordinate_Y;

          cout << "Enter Circle Data:-" << endl;

          cout << "Enter X Co-ordinate for Center : ";

          cin >> cordinate_X;

          cout << "Enter Y Co-ordinate for Center : ";

          cin >> cordinate_Y;

          //Set up the center.

          object_P.setX(cordinate_X);

          object_P.setY(cordinate_Y);

          //Set the first and the second coordinate.

          object_Q.setX(cordinate_X);

          object_Q.setY(cordinate_Y);

          cout << "Enter the radius : ";

          cin >> radius_major;    

          radius_minor = radius_major;

     }

    

};

//Define the main function.

int main()

{

     //Define the objects of the class.

     Ellipse object_E;

     Oval object_O;

     Circle object_C;

     Triangle object_T;

     Rectangle object_R;

     Square object_S;

     //Display the heading.

     cout << "---Ellipse---" << endl;

     //Call the function.

     object_E.setData();

     //Display the area.

     cout << "Area of Ellipse = "

          << object_E.getArea() << endl;

     //Display the heading.

     cout << "\n---Oval---" << endl;

     //Call the function.

     object_O.setData();

     //Display the area.

     cout << "Area of Oval = "

          << object_O.getArea() << endl;

     //Display the heading.

     cout << "\n---Circle---" << endl;

     //Call the function.

     object_C.setData();

     //Display the area.

     cout << "Area of Circle = "

          << object_C.getArea() << endl;

     //Display the heading.

     cout << "\n---Triangle---" << endl;

     //Call the function.

     object_T.setData();

     //Display the area.

     cout << "Area of Triangle = "

          << object_T.getArea() << endl;

     //Display the heading.

     cout << "\n---Rectangle---" << endl;

     //Call the function.

     object_R.setData();

     //Display the area.

     cout << "Area of Rectangle = "

          << object_R.getArea() << endl;

    

     //Display the heading.

     cout << "\n---Square---" << endl;

     //Call the function.

     object_S.setData();

     //Display the area.

     cout << "Area of Square = "

          << object_S.getArea() << endl;

     //Command to pause the screen in visual studio.

     system("pause");

     //Return the value for the main function.    

     return 0;

}

Add a comment
Know the answer?
Add Answer to:
Please use C++ and Please do all file separate separately. And also I need output too....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q2) Interface Create a program that calculates the perimeter and the area of any given 2D...

    Q2) Interface Create a program that calculates the perimeter and the area of any given 2D shape. The program should dynamically assign the appropriate calculation for the given shape. The type of shapes are the following: • Quadrilateral 0 Square . Perimeter: 4xL • Area:LXL O Rectangle • Perimeter: 2(L+W) • Area:LxW Circle Circumference: I x Diameter (TT = 3.14) Area: (TT xD')/4 Triangle (assume right triangle) o Perimeter: a+b+c O Area: 0.5 x base x height (hint: the base...

  • Purpose: The purpose of this lab is for you to design and implement several classes that...

    Purpose: The purpose of this lab is for you to design and implement several classes that use Inheritance. The problem: The program must handle a collection of different 2-dimensional shapes: triangles, rectangles and circles. All shapes have a color (use a Stringl and are either filled or not (use a boolean). All shapes must calculate and return their perimeter, and area. toStrina) for all shapes must implement the standardized formatting for inheritance. You are required to implement each of the...

  • Using the IST Linux system create the following Java command line inheritance application Lab4. Create the...

    Using the IST Linux system create the following Java command line inheritance application Lab4. Create the following project Java files: Point.java, Shape.java, Circle.java, Triangle.java, Rectangle.java, and Lab4.java Point.java will contain two coordinates x and y. This will be reused to create point objects to draw all the shapes. Shape.java will be the parent class and will contain a Point type. Circle.java, Triangle.java, Rectangle.java will all be children of Shapes.java class Each class (Circle, Triangle, Rectangle) will contain the private class...

  • java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectang...

    java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...

  • create a program shape.cpp that uses classes point.h and shape.h. The program should compile using the...

    create a program shape.cpp that uses classes point.h and shape.h. The program should compile using the provided main program testShape.cpp. the provided programs should not be modified. Instructions ar egiven below. Shape class The Shape class is an abstract base class from which Rectangle and Circle are derived. bool fits_in(const Rectangle& r) is a pure virtual function that should return true if the Shape fits in the Rectangle r. void draw(void) is a pure virtual function that writes the svg...

  • in C++ use Inheritance for the following Shape Circle Sphere Cylinder Rectangle Square Cube You must define one class for each shape. And, use public inheritance when deriving from base cla...

    in C++ use Inheritance for the following Shape Circle Sphere Cylinder Rectangle Square Cube You must define one class for each shape. And, use public inheritance when deriving from base classes. Circle int r; void area(); void perimeter(); void volume(); //No volume for circle Sphere int r; void area();//Sphere surface area= 4 × pi × radius2 void perimeter(); //No perimeter for Sphere void volume();//Sphere volume= 4/3 × pi × radius2 Cylinder int r, height; void area();// Cylinder surface area=perimeter of...

  • GUI bouncing shapes program use this interface the out put of the program should be a jFr...

    GUI bouncing shapes program use this interface the out put of the program should be a jFrame with three buttons: “add triangle”, “add square” and “add circle” and a blank screen. when the user clicks any of these buttons the corresponding shape appears and starts bouncing around the screen. the shape of these shaoes and randomized and anytime the user clicks the button you should be able to keeping adding shapes on the screen while the previosus shape is bouncing...

  • C++ ONLY PLEASE Problem Description: Objective: Create Inheritance Hierarchy to Demonstrate Polymorphic Behavior Create a Rectangle...

    C++ ONLY PLEASE Problem Description: Objective: Create Inheritance Hierarchy to Demonstrate Polymorphic Behavior Create a Rectangle Class Derive a Square Class from the Rectangle Class Derive a Right Triangle Class from the Rectangle Class Create a Circle Class Create a Sphere Class Create a Prism Class Define any other classes necessary to implement a solution Define a Program Driver Class for Demonstration a) Create a Container to hold objects of the types described above b) Create and Add two(2) objects...

  • This question is about java program. Please show the output and the detail code and comment.And...

    This question is about java program. Please show the output and the detail code and comment.And the output (the test mthod )must be all the true! Thank you! And the question is contain 7 parts: Question 1 Create a Shape class with the following UML specification: (All the UML "-" means private and "+" means public) +------------------------------------+ | Shape | +------------------------------------+ | - x: double | | - y: double | +------------------------------------+ | + Shape(double x, double y) | |...

  • /* FILE: ./shapes7/shape.h */ #include <iostream> using std::ostream; class shape{ int x,y; public: shape( ) {...

    /* FILE: ./shapes7/shape.h */ #include <iostream> using std::ostream; class shape{ int x,y; public: shape( ) { x=y=0;} shape(int xvalue, int yvalue); void setShape(int new_x, int new_y); void setX(int new_x); void setY(int new_y); int getX( ) const; int getY( ) const; virtual void move(int x, int y) = 0; virtual void shift(int dx, int dy) = 0; virtual void draw( ) = 0; virtual void rotate(double r) = 0; virtual void print(ostream&)const; friend ostream & operator<<(ostream & os, const shape& s);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT