Write a program that manages a list of 2D and 3D shapes Here

Write a program that manages a list of 2D and 3D shapes. Here is a list of shapes that your program manages: Square, Rectangle, Circle, Sphere, Cone, and Cylinder. Your program implements the following tasks: Let users enter any number of shapes of any type in any order Your program will keep ask users to enter a new shape followed by the parameters For example: if user enters \"square 5\", you will create a square object with side length 5. If user enters \"cone 3 9\", you will create a cone object with base radius 3 and height 9. Display all 2D objects in the order of their creation. There properties of all 2D objects must be shown: Name of the shape Values of the shape (for example, for circle display the radius; for rectangle display the width and height) Circumference of the shape Area of the shape Display all 3D objects in the order of their creation. There properties of all 3D objects must be shown: Name of the shape Values of the shape (for example, for circle display the radius; for rectangle display the width and height) Surface area of the shape Volume of the shape

Solution

code:

#include<iostream>
#include<math.h>
#include<string>
#include <sstream>
using namespace std;
class square
{
   float length;
   float area;
   float circumference;
public:
   square()
   {
       length=0;
       area=0;
   }
   square(float leng)
   {
       length=leng;
   }
   void calcArea()
   {
       area=length*length;
   }
   float getArea()
   {
       return area;
   }
   void calcCircum()
   {
       circumference=4*length;
   }
   float getCircum()
   {
       return circumference;
   }
   void print()
   {
       cout<<\"Name: square\"<<endl;
       cout<<\"Length: \"<<length<<endl;
       cout<<\"Circumference: \"<<circumference<<endl;
       cout<<\"Area: \"<<area<<endl;
   }
};
class rectangle
{
   float length;
   float breadth;
   float area;
   float circumference;
public:
   rectangle()
   {
       length=0;
       breadth=0;
       area=0;
   }
   rectangle(float len,float br)
   {
       length=len;
       breadth=br;
   }
   void calcArea()
   {
       area=length*breadth;
   }
   float getArea()
   {
       return area;
   }
   void calcCircum()
   {
       circumference=2*(length+breadth);
   }
   float getCircum()
   {
       return circumference;
   }
   void print()
   {
       cout<<\"Name: rectangle\"<<endl;
       cout<<\"Length: \"<<length<<\"Breadth: \"<<breadth<<endl;
       cout<<\"Circumference: \"<<circumference<<endl;
       cout<<\"Area: \"<<area<<endl;
   }
};
class circle
{
   float radius;
   float circumference;
   float area;
public:

   circle()
   {
       radius=0;
       circumference=0;
       area=0;
   }
   circle(float r)
   {
       radius=r;
   }
   void calcArea()
   {
       area=3.14*radius*radius;
   }
   float getArea()
   {
       return area;
   }
   void calcCircum()
   {
       circumference=2*3.14*radius;
   }
   float getCircum()
   {
       return circumference;
   }
   void print()
   {
       cout<<\"Name: circle\"<<endl;
       cout<<\"Radius: \"<<radius<<endl;
       cout<<\"Circumference: \"<<circumference<<endl;
       cout<<\"Area: \"<<area<<endl;
   }
};
class sphere
{
   float radius;
   float surfacearea;
   float voloume;
public:
   sphere()
   {
   }
   sphere(float r)
   {
       radius=r;
   }
   void calcsurfarea()
   {
       surfacearea=4*3.14*radius*radius;
   }
   void calcVoloume()
   {
       voloume=(4/3)*3.14*radius*radius*radius;
   }
   float getsurfacearea()
   {
       return surfacearea;
   }
   float getVoloume()
   {
       return voloume;
   }
   void print()
   {
       cout<<\"Name: sphere\"<<endl;
       cout<<\"Radius: \"<<radius<<endl;
       cout<<\"Surface area: \"<<surfacearea<<endl;
       cout<<\"Voloume: \"<<voloume<<endl;
   }
};

class cone
{
   float radius;
   float height;
   float surfacearea;
   float voloume;
public:
   cone()
   {
   }
   cone(float r,float h)
   {
       radius=r;
       height=h;
   }
   void calcsurfarea()
   {
       surfacearea=3.14*radius*sqrt((height*height)+(radius*radius));
   }
   void calcVoloume()
   {
       voloume=(1/3)*3.14*radius*radius*height;
   }
   float getsurfacearea()
   {
       return surfacearea;
   }
   float getVoloume()
   {
       return voloume;
   }
   void print()
   {
       cout<<\"Name: cone\"<<endl;
       cout<<\"Radius: \"<<radius<<\"height: \"<<height<<endl;
       cout<<\"Surface area: \"<<surfacearea<<endl;
       cout<<\"Voloume: \"<<voloume<<endl;
   }
};
class cylinder
{
   float radius;
   float height;
   float surfacearea;
   float voloume;
public:
   cylinder()
   {
   }
   cylinder(float r,float h)
   {
       radius=r;
       height=h;
   }
   void calcsurfarea()
   {
       surfacearea=(2*3.14*radius*radius*2*3.14*radius*radius)+(2*3.14*radius*height);
   }
   void calcVoloume()
   {
       voloume=3.14*radius*radius*height;
   }
   float getsurfacearea()
   {
       return surfacearea;
   }
   float getVoloume()
   {
       return voloume;
   }
   void print()
   {
       cout<<\"Name: cylinder\"<<endl;
       cout<<\"Radius: \"<<radius<<\"Height: \"<<height<<endl;
       cout<<\"Surface area: \"<<surfacearea<<endl;
       cout<<\"Voloume: \"<<voloume<<endl;
   }
};

int main()
{
   string twoD[20];
   string threeD[20];
   string s,shape;
   square sq[10];
   rectangle rec[10];
   circle cir[10];
   sphere sp[10];
   cone co[10];
   cylinder cy[10];
   char ch;
   size_t sz;
   string radius,length,breadth,height;
   int i=0,j=0;
   int sqi=0,rei=0,cii=0,coi=0,cyi=0,sphi=0;
   do
   {
   cout<<\"Enter shape followed by parameters\"<<endl;
   cin>>s;
   istringstream is(s);
   is>>shape;
  
   if (shape==\"square\")
   {
       is>>length;
       cout<<length;
       sq[sqi]=square(stoi(length));
       sq[sqi].calcArea();
       sq[sqi].calcCircum();
       sqi++;
       twoD[i++]=\"square\";

   }
   else if (shape==\"rectangle\")
   {
       is>>length;
       is>>breadth;
       rec[rei]=rectangle(stoi(length),stoi(breadth));
       rec[rei].calcArea();
       rec[rei].calcCircum();
       rei++;
       twoD[i++]=\"rectangle\";

   }
   else if (shape==\"circle\")
   {
       is>>radius;
  
       cir[cii]=circle(stoi(radius));
       cir[cii].calcArea();
       cir[cii].calcCircum();
       cii++;
       twoD[i++]=\"circle\";

   }
   else if (shape==\"sphere\")
   {
       is>>radius;
       sp[sphi]=sphere(stoi(radius));
       sp[sphi].calcsurfarea();
       sp[sphi].calcVoloume();
       sphi++;
       threeD[j++]=\"sphere\";

   }
   else if (shape==\"cone\")
   {
       is>>radius>>height;
       co[coi]=cone(stoi(radius),stoi(height));
       co[coi].calcsurfarea();
       co[coi].calcVoloume();
       coi++;
       threeD[j++]=\"cone\";

   }
   else if (shape==\"cylinder\")
   {
       is>>radius>>height;
       cy[cyi]=cylinder(stoi(radius),stoi(height));
       cy[cyi].calcsurfarea();
       cy[cyi].calcVoloume();
       cyi++;
       threeD[j++]=\"cylinder\";

   }
   cout<<\"Do you want to continue\";
       cin>>ch;
   }
   while(ch==\'y\');
   cout<<\"Two D objects\"<<endl;
   int squi=0,recti=0,ciri=0,sphei=0,conei=0,cylini=0;
   for(int k=0;k<i;k++)
   {
       if (twoD[k]==\"square\")
       {
           sq[squi++].print();
       }
       else if (twoD[k]==\"rectangle\")
       {
           rec[recti++].print();
       }
       else if (twoD[k]==\"circle\")
       {
           cir[ciri++].print();
       }
   }
   cout<<\"Three D objects\"<<endl;
   for(int k=0;k<j;k++)
   {
       if (threeD[k]==\"sphere\")
       {
           sp[sphei++].print();
       }
       else if (threeD[k]==\"cone\")
       {
           co[conei++].print();
       }
       else if (threeD[k]==\"cylinder\")
       {
           cy[cylini++].print();
       }
   }
   system(\"pause\");
   return 0;
}

 Write a program that manages a list of 2D and 3D shapes. Here is a list of shapes that your program manages: Square, Rectangle, Circle, Sphere, Cone, and Cylin
 Write a program that manages a list of 2D and 3D shapes. Here is a list of shapes that your program manages: Square, Rectangle, Circle, Sphere, Cone, and Cylin
 Write a program that manages a list of 2D and 3D shapes. Here is a list of shapes that your program manages: Square, Rectangle, Circle, Sphere, Cone, and Cylin
 Write a program that manages a list of 2D and 3D shapes. Here is a list of shapes that your program manages: Square, Rectangle, Circle, Sphere, Cone, and Cylin
 Write a program that manages a list of 2D and 3D shapes. Here is a list of shapes that your program manages: Square, Rectangle, Circle, Sphere, Cone, and Cylin
 Write a program that manages a list of 2D and 3D shapes. Here is a list of shapes that your program manages: Square, Rectangle, Circle, Sphere, Cone, and Cylin
 Write a program that manages a list of 2D and 3D shapes. Here is a list of shapes that your program manages: Square, Rectangle, Circle, Sphere, Cone, and Cylin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site