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

I do have a week 3 assignment worked, now I do have to do the following: For thi

ID: 3845938 • Letter: I

Question

I do have a week 3 assignment worked, now I do have to do the following: For this assignment, you will write a new version of the area calculation program from Unit 3 that makes use of inheritance in C++. Add a new Shape base class to the area calculation program that includes data members common to all shapes (such as a shape ID, a shape type, and a unit of measure). You will use the Code::Blocks software to write this application. Write a new version of the area calculation program from Unit 3 that makes use of inheritance in C++. Add a new Shape base class to the area calculation program that includes data members common to all shapes (such as a shape ID, a shape type, and a unit of measure). The Shape base class should also include a virtual getArea() member function. Revise the Circle and Square classes so that they inherit from the Shape base class. Add a third shape to the program that also inherits from the Shape class. The finished program should ask the user to enter the relevant information for each shape and then print the area and other information for each shape. You will use the Code::Blocks software to write this application. Access this software via the Toolwire virtual desktop activity link in this unit. Be sure to organize the code correctly into header (.h) and implementation (.cpp) files. Your code should include meaningful comments and be correctly formatted.

Explanation / Answer

#include <iostream>
#include <conio>
#include <math>
using namespace std;
class shape //Base class
{
protected:
double x,y;
public:
virtual void get_data()=0;
virtual void get_area()=0;
};

class triangle : public shape
{
public:
void get_data(void)
{
cout<<" Enter details for Triangle ";
cout<<"Enter base and height respectively : ";
cin>>x>>y;
}
void get_area(void)
{
cout<<" Area of Triangle ";
double aot;
aot = 0.5 * x * y;
cout<<"Area of Triangle is "<<aot;
}
};

class rectangle : public shape
{
public:
void get_data(void)
{
cout<<" Enter details for Rectangle ";
cout<<"Enter length of two sides : ";
cin>>x>>y;
}
void get_area(void)
{
cout<<" Area of rectangle ";
double aor;
aor = x * y;
cout<<"Area of Rectangle is "<<aor;
}
};

class circle: public shape
{
public:
void get_data(void)
{
cout<<" Enter details for Circle ";
cout<<"Enter radius : ";
cin>>x;
}
void get_area(void)
{
cout<<" Area of Circle ";
double aoc;
aoc =M_PI * x * x;
cout<<"Area of circle is "<<aoc;
}
};

void main()
{
clrscr();
triangle tri;
rectangle rect;
circle cir;
shape *list[2]; //Pointer to base class
list[0]=&tri;
list[1]=&rect;
list[2]=&cir;
int choice;
while(1)
{
clrscr();

cout<<" Give your choice ";
cout<<"1) Area of Triangle ";
cout<<"2) Area of Rectangle ";
cout<<"3) Area of Circle ";
cout<<"4) Exit ";
cout<<"Enter your choice:-";
cin>>choice;
switch(choice)
{
case 1 : list[0]->get_data();
list[0]->get_area();
getch();
break;
case 2 : list[1]->get_data();
list[1]->get_area();
getch();
break;
case 3 : list[2]->get_data();
list[2]->get_area();
getch();
break;

case 4 : goto end;
default: cout<<" Invalid choice Try again ";
getch();
}
}
end:
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote