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

Untitled Notepad File Edit Format View Help Could you please assist me with the

ID: 3702295 • Letter: U

Question

Untitled Notepad File Edit Format View Help Could you please assist me with the project below. I have 80% done, but for some reason i a unable to incorpora perimeter into the Rect and Circle classes. Please explain step by step how this should be done. Please complete-by- calculating the area and perimeter of the Circle, Rectangle, and Square classes as indicated on the larger output provided. I was able to output the smaller output below based on the code provided below, but i need help completing the project to where i am able to produce a complete output with Perimeter and area

Explanation / Answer

// shape.h

#ifndef SHAPE_H_

#define SHAPE_H_

class Shape{

public:

               Shape();

               Shape(int newX,int newY);

               int getX() const;

               int getY() const;

               void setX(int newX);

               void setY(int newY);

               void moveTo(int newX,int newY);

               void rMoveTo(int deltaX,int deltaY);

               virtual void display() const;

private:

               int x;

               int y;

};

#endif /* SHAPE_H_ */

//end of shape.h

//shape.cpp

// # include "stafx.h

# include "shape.h"

Shape::Shape()

{

               moveTo(0,0);

}

Shape::Shape(int newX, int newY)

{

               moveTo(newX,newY);

}

int Shape::getX() const

{

               return x;

}

int Shape::getY() const

{

               return y;

}

void Shape::setX(int newX)

{

               x=newX;

}

void Shape::setY(int newY)

{

               y=newY;

}

void Shape::moveTo(int newX, int newY)

{

               setX(newX);

               setY(newY);

}

void Shape::rMoveTo(int deltaX, int deltaY)

{

               moveTo(getX()+deltaX , getY()+deltaY);

}

void Shape::display() const

{}

//end of shape.cpp

// rect.h

#ifndef RECT_H_

#define RECT_H_

# include "shape.h"

class Rect:public Shape

{

public:

               Rect();

               Rect(int newX, int newY,int newWidth, int newHeight);

               int getWidth() const;

               int getHeight() const;

               void setWidth(int newWidth);

               void setHeight(int newHeight);

               void display() const;

               double getArea() const;

               double getPerimeter() const;

private:

               int width;

               int height;

};

#endif /* RECT_H_ */

//end of rect.h

// rect.cpp

// # include "stafx.h"

# include "rect.h"

# include <iostream>

# include <iomanip>

using namespace std;

Rect::Rect() : Shape()

{

               setWidth(2);

               setHeight(1);

}

Rect::Rect(int newX, int newY, int newWidth, int newHeight) : Shape(newX,newY)

{

               setWidth(newWidth);

               setHeight(newHeight);

}

int Rect::getHeight() const

{

               return height;

}

int Rect::getWidth() const

{

               return width;

}

void Rect::setHeight(int newHeight)

{

               height = newHeight;

}

void Rect::setWidth(int newWidth)

{

               width = newWidth;

}

void Rect::display() const

{

               cout<<" Rectangle: ("<<setw(2)<<getX()<<","<<setw(2)<<getY()<<") width: "<<setw(2)<<getWidth()<<" height: "<<setw(2)<<getHeight()

                                             <<" area: "<<setw(8)<<fixed<<setprecision(3)<<getArea()<<" perimeter: "<<setw(8)<<fixed<<setprecision(3)<<getPerimeter()<<endl;

}

double Rect::getArea() const

{

               return ((double)getWidth() * getHeight());

}

double Rect::getPerimeter() const

{

               return((double)2*(getWidth() + getHeight()));

}

//end of rect.cpp

// circle.h

#ifndef CIRCLE_H_

#define CIRCLE_H_

# include "shape.h"

class Circle : public Shape

{

public:

               Circle();

               Circle(int newX, int newY, int newRadius);

               int getRadius() const;

               void setRadius(int newRadius);

               void display() const;

               double getArea() const;

               double getPerimeter() const;

private :

               int radius;

               const double PI = 3.1416;

};

#endif /* CIRCLE_H_ */

//end of circle.h

// circle.cpp

//# include "stafx.h"

# include "circle.h"

# include <iostream>

# include <iomanip>

using namespace std;

Circle::Circle() : Shape()

{

               setRadius(1);

}

Circle::Circle(int newX, int newY, int newRadius): Shape(newX, newY)

{

               setRadius(newRadius);

}

int Circle::getRadius() const

{

               return radius;

}

void Circle::setRadius(int newRadius)

{

               radius = newRadius;

}

void Circle::display() const

{

               cout<<" Circle : ("<<setw(2)<<getX()<<","<<setw(2)<<getY()<<") radius: "<<getRadius()

                              <<" area: "<<setw(8)<<fixed<<setprecision(3)<<getArea()<<" perimeter: "<<setw(8)<<fixed<<setprecision(3)<<getPerimeter()<<endl;

}

double Circle::getArea() const

{

               return((double)PI*getRadius()*getRadius());

}

double Circle ::getPerimeter() const

{

               return((double)2*PI*getRadius());

}

//end of circle.cpp

// square.h

#ifndef SQUARE_H_

#define SQUARE_H_

# include "rect.h"

class Square : public Rect

{

public:

               Square();

               Square(int newX, int newY,int length);

               int getSide() const;

               void setSide(int newLength);

               void display() const;

private:

               int side;

};

#endif /* SQUARE_H_ */

//end of square.h

// square.cpp

// # include "stdafx.h"

# include "square.h"

# include <iostream>

# include <iomanip>

using namespace std;

Square::Square():Rect()

{

               setSide(1);

}

Square::Square(int newX, int newY, int length):Rect(newX,newY,length,length)

{

               setSide(length);

}

int Square::getSide() const

{

               return side;

}

void Square::setSide(int newLength)

{

               side = newLength;

               Rect::setHeight(newLength);

               Rect::setWidth(newLength);

}

void Square::display() const

{

               cout<<" Square : ("<<setw(2)<<getX()<<","<<setw(2)<<getY()<<") length of side : "<<setw(2)<<getSide()<<" area: "<<setw(8)<<fixed<<setprecision(3)<<getArea()<<" perimeter: "<<setw(8)<<fixed<<setprecision(3)<<getPerimeter()<<endl;

}

//end of square.cpp

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