Question
I need someone to look over the C++ code and find the flaws. I cannot get the program to work. /*********************** shapestest.cpp ***********************/ #include #include
I need someone to look over the C++ code and find the flaws. I cannot get the program to work.
/*********************** shapestest.cpp ***********************/
#include #include "circle.hpp" using namespace std;
int main() { int choice; while (true) { cout > choice; char ch; if (choice == 1) { cout > ch; double r; if (ch == 'y') { cout > r; Circle c1(r); cout > ch; double b, h; if (ch == 'y') { cout > b; cout > h; Triangle t1(b, h); cout > ch; double l, w; if (ch == 'y') { cout > l; cout > w; Rectangle r1(l, w); cout
/*********************** circle.cpp ***********************/
#include "circle.hpp"
Circle::Circle() { radius = 1.0; } Circle::Circle(double r) { radius = r; } double Circle::getRadius() { return radius; } void Circle::setRadius(double r) { radius = r; } double Circle::area() { const double PI = 3.141592; return PI * radius * radius; } double Circle::diameter() { return 2 * radius; } double Circle::circumference() { const double PI = 3.141592; return 2 * PI * radius; } bool Circle::checkRect(Rectangle obj) { if (this->area() == obj.area()) return true; return false; }
/*********************** circle.hpp ***********************/
#include "rectangle.hpp" #include "triangle.hpp"
class Circle { double radius; friend class Rectangle; friend class Triangle;
public: Circle(); Circle(double r); double getRadius(); void setRadius(double r); double area(); double diameter(); double circumference(); bool checkRect(Rectangle obj); };
/*********************** rectangle.cpp ***********************/
#include "rectangle.hpp"
Rectangle::Rectangle() { length = 1.0; width = 1.0; } Rectangle::Rectangle(double l, double w) { length = l; width = w; } double Rectangle::getLength() { return length; } double Rectangle::getWidth() { return width; } void Rectangle::setLength(double l) { length = l; } void Rectangle::setWidth(double w) { width = w; } double Rectangle::area() { return length * width; } double Rectangle::diagonal() { return sqrt(length * length + width * width); } double Rectangle::perimeter() { return (2 * (length + width)); } bool Rectangle::checkSquare() { if (length == width) return true; return false; } bool Rectangle::checkTri(Triangle obj) { if (area() == obj.area()) return true; return false; }
/*********************** rectangle.hpp ***********************/
#include #include "triangle.hpp"
class Rectangle { double length; double width; friend class Triangle; friend class Circle;
public: Rectangle(); Rectangle(double l, double w); double getLength(); double getWidth(); void setLength(double l); void setWidth(double w); double area(); double diagonal(); double perimeter(); bool checkSquare(); bool checkTri(Triangle obj); };
/*********************** triangle.cpp ***********************/
Triangle::Triangle() { base = 1.0; height = 1.0; } Triangle::Triangle(double b, double h) { base = b; height = h; } double Triangle::getBase() { return base; } double Triangle::getHeight() { return height; } void Triangle::setBase(double b) { base = b; } void Triangle::setHeight(double h) { height = h; } double Triangle::area() { return (0.5) * base * height; } // bool Triangle::checkCirc(Circle obj) // { // if (this->area() == obj.area()) // return true; // return false; // }
/*********************** triangle.hpp ***********************/
#include "circle.hpp" #include "rectangle.hpp"
class Triangle { double base; double height; friend class Rectangle; friend class Circle;
public: Triangle(); Triangle(double b, double h); double getBase(); double getHeight(); void setBase(double b); void setHeight(double h); double area(); bool checkCirc(Circle obj); };
This is the supposed outcome:
Choose a figure: 1. Circle 2. Triangle 3. Rectangle 4. Quit 1 do you wish to enter the basic parameters(y): y Enter the radius: 5 Diameter: 10 Area: 78.5398 Circumference: 31.4159 Choose a figure: 1. Circle 2. Triangle 3. Rectangle 4. Quit 2 do you wish to enter the basic parameters(y): y Enter the base: 10 Enter the height: 20 Area: 100 Choose a figure: 1. Circle 2. Triangle 3. Rectangle 4. Quit 3 do you wish to enter the basic parameters(y): y Enter the length: 10 Enter the width: 20 Diagonal: 22.3607 Area: 200 Perimeter: 60 Is it a square? false Choose a figure: 1. Circle 2. Triangle 3. Rectangle 4. Quit 4 Thank youStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started