Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program in C++ Problem In this assignment, you are going to practice inheritance

ID: 3689923 • Letter: P

Question

Program in C++

Problem In this assignment, you are going to practice inheritance and operator overloading based on your previous work of assignment 10. The requirements are as follows: 1. Write a program that can calculate the area for Rectangle, Circle and Triangle; and calculate the volume for Cubic, Sphere and Cone. The Cubic is a derived class from Rectangle, the Cone and Sphere should be derived class from Circle. Rectangle, Circle and Triangle are derived class from base class Shape 2. The object should be constructed after user's input and store the constructed objects in a linkedlist (from your last assignment) for later use. Print out the constructed object after each construction. (Hint: The objects should be stored in the Node, and you may use base class to represent all derived class for declaring variables in the class Node) Overload the operator + for all derived classes so that when adding two objects of the same class, the operator returns a new object that has the summed area and volume (2D shapes have area only) of the two added objects. The parameters for the new object (e.g. base, height, radius etc.) can be determined arbitrarily based on the area and volume. Overload the operator

Explanation / Answer

Hi below i have written a sample code for your reference using C++ :)

#include "iostream"

#include "conio.h"

using namespace std;

class measure

{

   public:

   void shape(int r);

   void shape(int l,int b);

   void shape(float t,int d,int e);

   void shape(long a);

   void shape(float c, long int g);

   void shape(double j);

   void shape(float h, double f);

};

void measure::shape(int r)

{

   cout<<"area of the circle is "<<3.14*r*r;

}

void measure::shape(int l,int b)

{

   cout<<"area of the rectangle is"<<l*b;

}

void measure::shape(float t,int d,int e)

{

   cout<<"area of the triangle is"<<t*d*e;

}

void measure::shape(long a)

{

   cout<<"area of the square is"<<a*a;

}

void measure::shape(float c, long int g)

{

   cout<<"Volume of the cone is "<<(1/3)*3.14*c*c*g;

}

void measure::shape(double j)

{

   cout<<"Volume of the sphere is "<<(4/3)*3.14*j*j*j;

}

void measure::shape(float h, double f)

{

   cout<<" Volume of the Cylinder is "<<3.14*f*f*h;

}

int main()

{

   int r,d,e,l,b;

   float t,c,h;

   long a;

   int ch;

   double j,f;

   long int g;

   measure obj;

   cout<<" CALCULATION OF AREA AND VOLUME";

   cout<<" 1. area of circle";

   cout<<" 2. area of rectangle";

   cout<<" 3. area of triangle";

   cout<<" 4. area of square";

   cout<<" 5. Volume of the cone";

   cout<<" 6. Volume of the sphere";

   cout<<" 7. Volume of the cylinder";

   cout<<" Enter your choice ";

   cin>>ch;

   switch(ch)

   {

case 1:

cout<<"enter the value of radius of the circle ";

cin>>r;

obj.shape(r);

break;

case 2:

cout<<"enter the sides of rectangle ";

cin>>l>>b;

obj.shape(l,b);

break;

case 3:

cout<<"enter the sides of triangle ";

cin>>d>>e;

obj.shape(0.5,d,e);

break;

case 4:

cout<<"enter the sides of square";

cin>>a;

obj.shape(a);

break;

case 5:

cout<<" Enter the radius of the cone";

cin>>c;

cout<<" Enter the height of the cone";

cin>>g;

obj.shape(c,g);

break;

case 6:

cout<<" Enter the radius";

cin>>b;

obj.shape(b);

break;

case 7:

cout<<" Enter the radius";

cin>>f;

cout<<" Enter the height";

cin>>h;

obj.shape(h,f);

break;

default:

cout<<" The choice entered is a wrong choice";

   }

   getch();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote