develop a class shapes 2d to represent all 2d geometric shapes excluding line. class should represent the name of the object (a string) the color of the objects (color) and methods that all subclasses should implement (abstract methods) including:

Respuesta :

This is the UML diagram for the development of the program, in which Shapes 2D is the superclass and Circle, Square, Triangle, Rectangle, Rhombus, and Parallelogram are subclasses.

​​​​​​​This is the program in C++ demonstrating the above classes.

#include<iostream>

using namespace std;

class shapes

{

public:

   string name;

   string color;

   virtual void getAttributes()=0;

};

class Circle: public shapes

{

public:

   float radius;

   Circle(string n,string c, float r)

   {

       name=n;

       color=c;

       radius=r;

   }

   float getPerimeter()

   {

       return(2*(3.142)*radius);

   }

   float getArea()

   {

       return((3.142)*(radius*radius));

   }

   void getAttributes()

   {

       cout<<"Name  :"<<name<<endl;

       cout<<"Color :"<<color<<endl;

   }

};

class Square:public shapes

{

public:

   float side;

   Square(string n,string c, float s)

   {

       name=n;

       color=c;

       side=s;

   }

   float getPerimeter()

   {

       return(4*side);

   }

   float getArea()

   {

       return(side*side);

   }

   void getAttributes()

   {

       cout<<"Name  :"<<name<<endl;

       cout<<"Color :"<<color<<endl;

   }

};

class Triangle:public shapes

{

public:

   float base;

   float height;

   float side1;

   float side2;

   float side3;

   Triangle(string n,string c)

   {

       name=n;

       color=c;

   }

   float getPerimeter()

   {

       cout<<"Enter side1\n";

       cin>>side1;

       cout<<"Enter side2\n";

       cin>>side2;

       cout<<"Enter side3\n";

       cin>>side3;

       return(side1+side2+side3);

   }

   float getArea()

   {

       cout<<"Enter base\n";

       cin>>base;

       cout<<"Enter height\n";

       cin>>height;

       return((0.5)*base*height);

   }

   void getAttributes()

   {

       cout<<"Name  :"<<name<<endl;

       cout<<"Color :"<<color<<endl;

   }

};

class Rectangle:public shapes

{

public:

   float length;

   float breadth;

   Rectangle(string n,string c, float l,float b)

   {

       name=n;

       color=c;

       length=l;

       breadth=b;

   }

   float getPerimeter()

   {

       return(2*(length+breadth));

   }

   float getArea()

   {

       return(length*breadth);

   }

   void getAttributes()

   {

       cout<<"Name  :"<<name<<endl;

       cout<<"Color :"<<color<<endl;

   }

};

class Rhombus:public shapes

{

public:

   float diagonal1;

   float diagonal2;

   float side;

   Rhombus(string n,string c)

   {

       name=n;

       color=c;

   }

   float getPerimeter()

   {

       cout<<"Enter Side\n";

       cin>>side;

       return(4*side);

   }

   float getArea()

   {

       cout<<"Enter diagonal 1\n";

       cin>>diagonal1;

       cout<<"Enter diagonal 2\n";

       cin>>diagonal2;

       return((0.5)*diagonal1*diagonal2);

   }

   void getAttributes()

   {

       cout<<"Name  :"<<name<<endl;

       cout<<"Color :"<<color<<endl;

   }

};

class Parallelogram:public shapes

{

public:

   float base;

   float height;

   Parallelogram(string n,string c, float b,float h)

   {

       name=n;

       color=c;

       base=b;

       height=h;

   }

   float getPerimeter()

   {

       return(2*(base+height));

   }

   float getArea()

   {

       return(base*height);

   }

   void getAttributes()

   {

       cout<<"Name  :"<<name<<endl;

       cout<<"Color :"<<color<<endl;

   }

};

int main()

{

   int choice;

   while(1)

   {

       cout<<"\n\nEnter your choice :";

       cout<<"\n1 for Circle\n";

       cout<<"2 for Square\n";

       cout<<"3 for Triangle\n";

       cout<<"4 for Rectangle\n";

       cout<<"5 for Rhombus\n";

       cout<<"6 for Parallelogram\n";

       cin>>choice;

       system("cls");

       switch(choice)

       {

       case 1:

           {

               float r;

               cout<<"Enter radius\n";

               cin>>r;

               Circle c("Circle","Yellow",r);

               c.getAttributes();

               cout<<"Perimeter : "<<c.getPerimeter()<<endl;

               cout<<"Area : "<<c.getArea()<<endl;

           }break;

       case 2:

           {

               float side;

               cout<<"Enter side\n";

               cin>>side;

               Square s("Square","Red",side);

               s.getAttributes();

               cout<<"Perimeter : "<<s.getPerimeter()<<endl;

               cout<<"Area : "<<s.getArea()<<endl;

           }break;

       case 3:

           {

               Triangle t("Triangle","Green");

               t.getAttributes();

               cout<<"Perimeter : "<<t.getPerimeter()<<endl;

               cout<<"Area : "<<t.getArea()<<endl;

           }break;

       case 4:

           {

               float l,b;

               cout<<"Enter Length and breadth\n";

               cin>>l>>b;

               Rectangle r("Rectangle","Blue",l,b);

               r.getAttributes();

               cout<<"Perimeter : "<<r.getPerimeter()<<endl;

               cout<<"Area : "<<r.getArea()<<endl;

           }break;

       case 5:

           {

               Rhombus r("Rhombus","Purple");

               r.getAttributes();

               cout<<"Perimeter : "<<r.getPerimeter()<<endl;

               cout<<"Area : "<<r.getArea()<<endl;

           }break;

       case 6:

           {

               float b,h;

               cout<<"Enter base\n";

               cin>>b;

               cout<<"Enter height\n";

               cin>>h;

               Parallelogram p("Parallelogram","Pink",b,h);

               p.getAttributes();

               cout<<"Perimeter : "<<p.getPerimeter()<<endl;

               cout<<"Area : "<<p.getArea()<<endl;

           }break;

       }

   }

}

To learn more about objects and classes,

https://brainly.com/question/21113563

#SPJ4