Hi, please provide a code solution written in the C++ language to the following programming problem. The answer you provide has to include code comments, as it is being explained to a person with no technical background. In your answer, please show which portion of the code is a .cpp and which is a .h (if used). We are asked to separate them out (ie. main.cpp, classname.cpp, headername.h). Please show the output of your program to show it compiled error free. Thanks!
SEE PROGRAMMING PROBLEM BELOW
main.cpp
// This program demonstrates an abstract base class and overriding
a pure virtual function
// This program creates a Circle object and a Rectangle object
(both derived from the
// BasicShape class) and displays their areas
#include <iostream>
#include "Circle.h"
#include "Rectangle.h"
using namespace std;
void displayArea(BasicShape* shape);
int main()
{
// create a Circle object pointer -
cirPtr
// create a Circle object -
cir
// point the pointer to the
object's address
Circle *cirPtr = nullptr;
Circle cir(5, 2, 3.0);
cirPtr = ○
// create a Rectangle object
pointer - recPtr
// create a Rectangle object -
rec
// point the pointer to the
object's address
Rectangle *recPtr = nullptr;
Rectangle rec(7, 8);
recPtr = &rec;
// call the displayArea function
on both shapes to display the area
displayArea(cirPtr);
displayArea(recPtr);
system("pause");
return 0;
}
// this function displays the area of the shape passed to
it
void displayArea(BasicShape* shape)
{
cout << shape->getArea() << endl;
}
Rectangle.h
// This Rectangle class is derived from the BasicShape class. it
has a width and lengh attribute
// used to calculate the area (a virtual function overridden from
the BasicShape class)
#ifndef RECTANGLE_H
#define RECTANGLE_H
#include "BasicShape.h"
class Rectangle : public BasicShape
{
private:
long width;
long length;
public:
// constructor
Rectangle(long, long);
// getters
long getWidth() const;
long getLength() const;
// overriden function from BasicShape class
virtual double calcArea();
};
#endif
BasicShape.cpp
// This BasicShape class is a generic shape with an area, a
function to return the area, and a virtual function
// to be overridden by derived classes to calculate the area
#include "BasicShape.h"
// getter
double BasicShape::getArea() const
{
return area;
}
Circle.cpp
// This Circle class is derived from the BasicShape class. it has a
centerX and CenterY coordinates, as well
// as a radius attributes used to calculate the area (a virtual
function overridden from the BasicShape class)
#include "Circle.h"
// constructor
Circle::Circle(long x, long y, double r)
{
centerX = x;
centerY = y;
radius = r;
calcArea();
}
// getters
long Circle::getCenterX() const
{
return centerX;
}
long Circle::getCenterY() const
{
return centerY;
}
// overriden virtual function from the BasicShape class
double Circle::calcArea()
{
area = 3.14159 * radius * radius;
return area;
}
Circle.h
#ifndef CIRCLE_H
#define CIRCLE_H
#include "BasicShape.h"
class Circle : public BasicShape
{
private:
long centerX;
long centerY;
double radius;
public:
// constructor
Circle(long, long, double);
// getters
long getCenterX() const;
long getCenterY() const;
// overriden function from BasicShape class
virtual double calcArea();
};
#endif
BasicShape.h
#ifndef BASICSHAPE_H #define BASICSHAPE_H class BasicShape { protected: double area; public: // getter double getArea() const; // virtual function to be overriden by derived classes virtual double calcArea() = 0; }; #endif
Rectangle.cpp
#include "Rectangle.h" // constructor Rectangle::Rectangle(long w, long l) { width = w; length = l; calcArea(); } // getters long Rectangle::getWidth() const { return width; } long Rectangle::getLength() const { return length; } // overriden virtual function from the BasicShape class double Rectangle::calcArea() { area = width * length; return area; }
Hi, please provide a code solution written in the C++ language to the following programming problem....
Please Use R programming language to answers these question and please show me the code as well. Thank You 1. Problem: dataset: savings; package : faraway Use R, perform the calculations and answer the following questions (a) Calculate the design matrix X, and all regression coefficients estimates, as shown in (3). (b) Calculate the Residuals standard error , as in (5). (c) ANOVA table: Calculate SST, SSE, SSR, ?2, as in (6). Calculate the ANOVA F-statistic and p-value. (d)...
. Please write a function that will do the following Decryption of a message encrypted with a substitution cipher given cipher text only without any key Please provide comments on each line of code outlining what that line is doing. Note: Only the Function is to be written, all user inputs i.e the text to be decrypted will be entered earlier in the program. Code must be written in C and be able to be compiled using GCC If any...
Java Programming Language: Find the compiling error in the following code segment. Explain what the problem is and how to fix it. public class Mark { private float value; public float Mark(float startValue) { value = startValue; } }
Problem 1: a) Write LEGv8 assembly language programs for the following C program fragments. Please make sure to add any necessary comments. P[20] = P[10] + P[30] + 25; b) Show the machine code that will be generated by the assembly code in Problem 1.a. You can write machine code as decimal numbers. please help me solve this
Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and please add comments for the whole code. Include a class diagrams, and explain the approach you used for the project and how you implemented that, briefly in a few sentences. Please note the following: -Names chosen for classes, functions, and variables should effectively convey the purpose and meaning of the named entity. - Code duplication should be avoided by factoring out common code into...
Please Solve this problem using Visual Basic Programming Language (show design Interface and programming codes): Q. The Interface provides a text box, for the user to enter his or her current salary. The Calculate Button's Click Event Procedure should calculate the new salary amounts using rates of 2% through 6% in increment's of 0.5%. The procedure should display the rates and salary amounts in the lblNewSalary control. Code the procedure using the For....Next statement. Save the work.
C++ language. please provide detailed comments (for beginners) and use easy to understand/trace code. Thank you -------------------------------------------------- Given positive integers n, a, and b, print the first n positive integers that are a multiple of a, b, or both. For example: n = 6, a = 2 and b = 3, you should print: 2 3 4 6 8 9
Please solve the following problem with programming using proper data structures. (Programming Language: Python) A similar application to the parentheses matching problem comes from hypertext markup language (HTML). In HTML, tags exist in both opening and closing forms and must be balanced to properly describe a web document. This very simple HTML document: Example> Hello, world is intended only to show the matching and nesting structure for tags in the language. Write a program that can check an HTML document...
needs to be written in C language. please show that code works in command prompt if possible. 4. write program to take two numerical lists of the same length ended by a sen- 4. a tinel value and store the lists in arrays x and y, each of which has 20 elements. Let n be the actual number of data values in each list. Store the product of corresponding elements oflx and in a third a 2. also of size...
Dining Philosopher problem solution- Vulnerable to starvation in c language or either java - using threads(can use semaphores but with threads) - with proper explanations and comments Please provide output of program and explanation of how to run program.