Hi I need help doing this problem
*The program must re-prompt as long as invalid input is inserted
Implement a program that manages shapes. Implement a class named Shape with a virtual function area()which returns the double value. Implement three derived classes named Diamond, Oval, and Pentagon. Declare necessary properties in each including getter and setter function and a constructor that sets the values of these properties. Override the area() function in each by calculating the area using the defined properties in that class. Write a program that repeatedly shows the user a menu to create one of the three main shapes or to print the shapes created so far. If the user selects to create a new shape, the program prompts the user to enter the values for the size of the selected shape. The shape is then stored in an array*. If the user selects to print the current shapes, print the name and the total area of each shape to the console. Creating objects for testing all classes in the main function.
*The array must hold pointers to Shape objects. You may limit the size of the array to 10.
Note: Could you plz go through this code and let me know
if u need any changes in this.Thank You
_________________
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
class Shape
{
private :
string name;
public :
Shape(string
n)
{
this->name=n;
}
virtual double
area()=0;
string getShape()
{
return name;
}
};
class Diamond:public Shape
{
private :
double base;
double height;
public :
Diamond(double
b,double h,string name):Shape(name)
{
this->base=b;
this->height=h;
}
double
area()
{
return (base*height)/2;
}
};
class Oval:public Shape
{
private :
double a;
double b;
public :
Oval(double a,double b,string name):Shape(name)
{
this->a=a;
this->b=b;
}
double area()
{
return a*b*3.14159;
}
};
class Pentagon:public Shape
{
private :
double s;
double a;
public :
Pentagon(double
s,double a,string name):Shape(name)
{
this->s=s;
this->a=a;
}
double
area()
{
return (5*(s*a))/2;
}
};
int main()
{
int choice,cnt=0;
const int SIZE=10;
Shape* shapes[SIZE];
while(true)
{
cout<<"\n1.Oval"<<endl;
cout<<"2.Pentagon"<<endl;
cout<<"3.Diamond"<<endl;
cout<<"4.Display all Shapes"<<endl;
cout<<"5.Exit"<<endl;
cout<<"Enter Choice :";
cin>>choice;
if(cnt>=SIZE)
{
cout<<"** Array is full **"<<endl;
continue;
}
switch(choice)
{
case 1:{
double a,b;
cout<<"Enter Minor Radius
(a):";
cin>>a;
cout<<"Enter Major Radius
(a):";
cin>>b;
Oval* o=new Oval(a,b,"Oval");
shapes[cnt]=o;
cnt++;
continue;
}
case 2:{
double s,a;
cout<<"Enter the side length
(s):";
cin>>s;
cout<<"Enter the length of
apothem (a):";
cin>>a;
Pentagon* pen=new
Pentagon(s,a,"Pentagon");
shapes[cnt]=pen;
cnt++;
continue;
}
case 3:{
double b,h;
cout<<"Enter the length of
base (b):";
cin>>b;
cout<<"Enter the height
(h):";
cin>>h;
Diamond* d=new
Diamond(b,h,"Diamond");
shapes[cnt]=d;
cnt++;
continue;
}
case 4:{
for(int i=0;i<cnt;i++)
{
cout<<"Shape Name
:"<<shapes[i]->getShape()<<endl;
cout<<"Area :"<<shapes[i]->area()<<endl;
cout<<"------------------------------"<<endl;
}
continue;
}
case 5:{
break;
}
default:{
cout<<"** Invalid Choice
**"<<endl;
continue;
}
}
break;
}
return 0;
}
_____________________________
Output:

_______________Could you plz rate me well.Thank
You
Hi I need help doing this problem *The program must re-prompt as long as invalid input...
Write a C++ program for the instructions below. Please
read the instructions carefully and make sure they are followed
correctly.
please put comment with code! and please do not just
copy other solutions.
Instructions 1. Read instructions carefully! 2. Use C++ syntax only, C syntax will not be accepted. 3. Always use braces to define blocks. 4. Indent all lines within a block. Each block requires one more tab. 5. Organize your code well with proper formatting and a single...
JAVA Problem: Coffee Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare (); } The prepare method will...
JAVA Problem: Coffee do not use ArrayList or Case Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare ();...
Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...
Write a program in C++ with comments! Create an abstract class Property, containing the data items owner, address and price. Add an abstract method showOwner(). Also provide getter/setters for all the data items. Make validations if necessary in the setter so that no invalid values are entered. Create a class House, to inherit the Property class. This class should contain additional data item – yardSize – an integer – the size of the yard of the house, getter and setter...
QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members: • A private String data field named name for the name of the ship. • A private String data field named yearBuilt for the year that the ship was built. • A constructor that creates a ship with the specified name and the specified year that the ship was built. • Appropriate getter and setter methods. A toString method that overrides the toString method...
IN JAVA For the following questions, “define a class” means the following: • Create an appropriately-named file containing the Java class definition, including the following: – A block comment describing the file (and hence the class), as always – Any instance variables, as required by the question – Accessor (getter) and mutator (setter) methods for any instance variables – Constructors as appropriate or as required by the question – A toString method that prints instances of the class informatively –...
Hello! I need help with this problem! I noticed it's been answered before but I need a different version! Create a class named Building with one public pure virtual function computerEnergyConsumption() that returns a double value of the instance variable which stores the energy consumed by the building. Create the two classes SolarBuilding and WindMill that both publicly inherit from Building. SolarBuilding has an instance variable that stores the energy generated by the solar panels. WindMill has an instance variable...
c++
driver and car are independed classes
1. Create a class Car, which has a color, engine, horsepower, fuel, FuelLevel, year of manufacturing and driver which can be defined by name, age, licenseNumber. Create the corresponding OOP in For each class (Driver, Car) write a header file and the class implementation -In the main function do the following: from that class in main function. L.1 Write a function that will print the total number of objects created 12 Define an...
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...