Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

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 #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 #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 #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; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

=+what information would you need about the compact disc industry?

Answered: 1 week ago