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

Inheritance and Dynamic Memory Assignment Context By successfully completing thi

ID: 3744770 • Letter: I

Question

Inheritance and Dynamic Memory

Assignment Context

By successfully completing this assignment, you will demonstrate your proficiency in the following course competencies and objectives:

Competency 1: Define business problems that can be solved using basic programming concepts and standards.

Define the requirements for an application.

Describe the stakeholders needed to further define an application.

Competency 2: Analyze intermediate object-oriented programming.

Analyze the behavior of object-oriented programming constructs.

Explain how an application works.

Competency 3: Apply collaboration strategies in developing software components.

Describe a collaboration plan for working with stakeholders.

Competency 4: Design a program that applies intermediate programming concepts and constructs.

Write a program that applies object-oriented programming constructs.

Competency 5: Communicate effectively.

Communicate effectively in a business environment.

Assignment Overview

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. Access this software via the Toolwire virtual desktop activity link in this unit.

Assignment Instructions

Part 1: Write the 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.

please provide a working code that is separated by function. cpp and .h that is copy and pasteable.

I need the new code to be like the one i have posted with header file example circle.h and implementation files example circle.cpp

My code from the previous assignment is below:

CODE :

circle.h :

#ifndef CIRCLE_H
#define CIRCLE_H

struct Circle { // circle structure class

public:   Circle();   // declaration
void setRadius(double r);   // setting the radius
double getRadius();   // getting the radius
double Area();   // get the area calculated
void Display(); // display the datda

protected:   double Radius; // radius value declared

private:

};

#endif


square.h :

#ifndef SQUARE_H
#define SQUARE_H

struct Square { // square structure class

public : Square(); // declaration
void setLength(double l); // setting the length
double getLength(); // getting the length
double Area(); // get the area calculated
void Display(); // display the data

protected : double Length; // length value declaration

private:
};

#endif

circle.cpp :


#include <iostream>
#include "circle.h"

using namespace std;

const double PI = 3.14159; // initialisng the global values
Circle::Circle() {   // method declaration

Radius = 0; // initialisng the radius value

}

void Circle::setRadius(double r) {  

Radius = r <= 0 ? 1 : r; // checking the input value

}

double Circle::getRadius() {  

return Radius; //getting and setting the value

}

double Circle::Area(){  
return Radius * Radius * PI; // returning the area
}

void Circle::Display(){   // display the data

cout << " Circle Properties";  
cout << " Radius = " << getRadius();  
cout << " Area = " << Area() << " ";
}

square.cpp :

#include <iostream>
#include "square.h"

using namespace std;


Square::Square(){ // method declaration

Length = 0; // length initialisng

}

void Square::setLength(double l) {

Length = l <= 0 ? 1 : l; // checking the data

}

double Square::getLength() {  

return Length; // returning the length

}

double Square::Area() {  

return Length*4; // returning the area

}
void Square::Display(){   // display the data

cout << " Square Properties";  
cout << " Length = " << getLength();  
cout << " Area = " << Area() << " ";
}

main.cpp :


#include "circle.h"
#include <iostream>
#include "square.h" // including the header files

using namespace std;

int main(){  

int radius,length;

Circle circle; // Displaying a circle using the default value of the radius  
circle.Display();  
Circle circ; // circle with a value supplied for the radius  

cout << "Enter the radius value :" << endl; // taking the value from the user
cin >> radius;

circ.setRadius(radius);  
circ.Display();  

Square square; // Displaying a square
square.Display();
Square squ; // square with a value supplied for the length  

cout << "Enter the length value :" << endl;
cin >> length;

squ.setLength(length); // of the base class  
squ.Display();

return 0;
}

Explanation / Answer

Note: Plz tel me if u need any modifications in this code.Thank You

_____________

Shape.h

#ifndef SHAPE_H

#define SHAPE_H

using namespace std;

class Shape

{

public:

Shape(int id,string type,string unit);

int getId();

void setId(int id);

string getType();

void setType(string type);

string getUnit();

void setUnit(string unit);

// declaring pure virtual function

virtual double calArea() = 0;

private:

// Declaring variables

int Id;

string type;

string unit;   

};

#endif

_____________

Shape.cpp

#include <iostream>

using namespace std;

#include "Shape.h"

Shape::Shape(int id, string type, string unit) {

this->Id = id;

this->type = type;

this->unit = unit;

}

int Shape::getId() {

return Id;

}

void Shape::setId(int id) {

Id = id;

}

string Shape::getType() {

return type;

}

void Shape::setType(string type) {

this->type = type;

}

string Shape::getUnit() {

return unit;

}

void Shape::setUnit(string unit) {

this->unit = unit;

}

  

________________

Circle.h

#ifndef CIRCLE_H
#define CIRCLE_H

#include "Shape.h"

class Circle:public Shape
{
public:
Circle(int id,string type,string unit,double radius);
// Function declarations
double getRadius();
void setRadius();
double calArea();

private:
// Declaring variables
double radius;

};
#endif

______________

Circle.cpp

#include <iostream>
#include "Circle.h"
#include "Shape.h"
using namespace std;

Circle::Circle(int id,string type,string unit,double radius):Shape(id,type,unit)
{
this->radius=radius;
}
// Function declarations
double Circle::getRadius()
{
return radius;
}
void Circle::setRadius()
{
this->radius=radius;
}
double Circle::calArea()
{
return 3.14159 * radius*radius;
}

________________

Rectangle.h

#ifndef RECTANGLE_H
#define RECTANGLE_H

#include "Shape.h"

class Rectangle:public Shape
{
public:
Rectangle(int id,string type,string unit,double length,double width);
// Function declarations
double getLength();
void setLength();
double getWidth();
void setWidth();
double calArea();
private:
// Declaring variables
double length;
double width;

};
#endif

______________

Rectangle.cpp

#include <iostream>

#include "Rectangle.h"
using namespace std;

Rectangle::Rectangle(int id,string type,string unit,double length,double width):Shape(id,type,unit)
{
this->length=length;
this->width=width;
}
// Function declarations
double Rectangle::getLength()
{
return length;
}
void Rectangle::setLength()
{
this->length=length;
}
double Rectangle::getWidth()
{
return width;
}
void Rectangle::setWidth()
{
this->width=width;
}
double Rectangle::calArea()
{
return length*width;
}

_________________

Square.h

#ifndef SQUARE_H

#define SQUARE_H

#include "Shape.h"

class Square:public Shape

{

public:

Square(int id,string type,string unit,double side);

// Function declarations

double getSide();

void setSide();

double calArea();

private:

// Declaring variables

double side;

};

#endif

______________

Square.cpp