Create a program that calculates the area of various shapes.
Console
Specifications
#include<iostream>
using namespace std;
//abstract class
class Shape
{
virtual double get_area()=0;//returns double
type
};
class Circle:Shape
{
double radius;
//constructor
public:
Circle(double r)
{
radius=r;
}
double get_radius()
{
return radius;
}
void set_radius(double r)
{
radius=r;
}
double get_area()
{
return
3.14*radius*radius;//returning area
}
};
class Square:Shape
{
double width;
//constructor
public:
Square(double w)
{
width=w;
}
double get_width()
{
return width;
}
void set_width(double w)
{
width=w;
}
double get_area()
{
return width*width;//returning
area
}
};
class Rectangle:Shape
{
double width,height;
//constructor
public:
Rectangle(double w,double h)
{
width=w;
height =h;
}
double get_width()
{
return width;
}
void set_width(double w)
{
width=w;
}
double get_height()
{
return height;
}
void set_height(double h)
{
height=h;
}
double get_area()
{
return width*height;//returning
area
}
};
//method to display area of each shape
void display_area()
{
double r;
double w,h;
cout<<"Enter circle radius :";
cin>>r;
Circle *c= new Circle(r);
cout<<"Area of circle
:"<<c->get_area()<<endl;
cout<<"Enter Square width :";
cin>>w;
Square *s= new Square(w);
cout<<"Area of Square
:"<<s->get_area()<<endl;
cout<<"Enter Rectangel width :";
cin>>w;
cout<<"Enter Rectangel height :";
cin>>h;
Rectangle *R= new Rectangle(w,h);
cout<<"Area of Rectangle
:"<<R->get_area()<<endl;
}
int main()
{
display_area();
return 0;
}
//PLS give a thumbs up if you find this helpful, its helps me alot,
thanks.
Create a program that calculates the area of various shapes. Console Specifications Create an abstract class...
Define an interface named Shape with a single method named area that calculates the area of the geometric shape: public double area(); Next, define a class named Circle that implements Shape. The Circle class should have an instance variable for the radius, a constructor that sets the radius, an accessor and a mutator method for the radius, and an implementation of the area method. Define another class named Rectangle that implements Shape. The Rectangle class should have instance variables...
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...
Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...
Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....
Description Create an object-oriented program that uses inheritance to perform calculations on a rectangle or a square. Sample Output (Your output should be similar to the text in the following box) Rectangle Calculator Rectangle or square? (r/s): r Height: 5 Width: 10 Perimeter: 30 Area: 50 Continue? (y/n): y Rectangle or square? (r/s): s Length: 5 Perimeter: 20 Area: 25 Continue? (y/n): n Thank you for using my app Specifications Use a Rectangle class that provides attributes to store the...
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...
Area Program – Build a Java Class to Calculate the area of a Figure(call it “Area.java”. The figure may be a circle, or a square or a rectangle. The user will enter the type of figure they want through a Scanner. If they enter a “C”, proceed to calculate the area of the Circle using values read in for radius. If they enter an “S”, then calculate the area of a Square using values read in for side. If they...
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...
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...
I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a void method named howToColor(). void howToColor(); } GeometricObject class: public class GeometricObject { } Sqaure class: public class Square extends GeometricObject implements Colorable{ //side variable of Square double side; //Implementing howToColor() @Override public void howToColor() { System.out.println("Color all four sides."); } //setter and getter methods for Square public void setSide(double side) { this.side = side; } public double getSide() { return...