Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you write a test driver that can run this code? // Shape.h #include class Shape { public: Shape(); virtual ~Shape() {} void SetFillColor(std::string fill_color);

Can you write a test driver that can run this code?

// Shape.h

#include

class Shape {

public:

Shape();

virtual ~Shape() {}

void SetFillColor(std::string fill_color);

std::string GetFillColor();

void SetBorderColor(std::string border_color);

std::string GetBorderColor();

virtual float Area() = 0;

virtual float Perimeter() = 0;

protected:

std::string shape_type_;

int num_sides_;

std::string fill_color_;

std::string border_color_;

void SetShapeType(std::string shape_type);

void SetNumSides(int num_sides);

};

// Shape.cpp

#include "Shape.h"

Shape::Shape() : shape_type_("Shape"), num_sides_(0), fill_color_("White"), border_color_("Black") {}

void Shape::SetFillColor(std::string fill_color) {

fill_color_ = fill_color;

}

std::string Shape::GetFillColor() {

return fill_color_;

}

void Shape::SetBorderColor(std::string border_color) {

border_color_ = border_color;

}

std::string Shape::GetBorderColor() {

return border_color_;

}

void Shape::SetShapeType(std::string shape_type) {

shape_type_ = shape_type;

}

void Shape::SetNumSides(int num_sides) {

num_sides_ = num_sides;

}

// Triangle.h

#include "Shape.h"

class Triangle : public Shape {

public:

Triangle();

Triangle(int side1, int side2, int side3);

void SetSide1(int side);

int GetSide1();

void SetSide2(int side);

int GetSide2();

void SetSide3(int side);

int GetSide3();

float Area() override;

float Perimeter() override;

private:

int side1_;

int side2_;

int side3_;

};

// Triangle.cpp

#include "Triangle.h"

#include

Triangle::Triangle() : Shape(), side1_(0), side2_(0), side3_(0) {

SetShapeType("Triangle");

SetNumSides(3);

}

Triangle::Triangle(int side1, int side2, int side3) : Shape(), side1_(side1), side2_(side2), side3_(side3) {

SetShapeType("Triangle");

SetNumSides(3);

}

void Triangle::SetSide1(int side) {

side1_ = side;

}

int Triangle::GetSide1() {

return side1_;

}

void Triangle::SetSide2(int side) {

side2_ = side;

}

int Triangle::GetSide2() {

return side2_;

}

void Triangle::SetSide3(int side) {

side3_ = side;

}

int Triangle::GetSide3() {

return side3_;

}

float Triangle::Area() {

float s = (side1_ + side2_ + side3_) / 2.0f;

return sqrt(s * (s - side1_) * (s - side2_) * (s - side3_));

}

float Triangle::Perimeter() {

return side1_ + side2_ + side3_;

}

// Circle.h

#include "Shape.h"

class Circle : public Shape {

public:

Circle();

Circle(int radius, std::string fill_color, std::string border_color);

void SetRadius(int radius);

int GetRadius();

void SetFillColor(std::string fill_color) override;

std::string GetFillColor() override;

void SetBorderColor(std::string border_color) override;

std::string GetBorderColor() override;

float Area() override;

float Perimeter() override;

private:

int radius_;

}

// Circle.cpp

#include "Circle.h"

#include

Circle::Circle() : Shape(), radius_(0), fill_color_(""), border_color_("") {

SetShapeType("Circle");

SetNumSides(0);

}

Circle::Circle(int radius, std::string fill_color, std::string border_color) : Shape(), radius_(radius), fill_color_(fill_color), border_color_(border_color) {

SetShapeType("Circle");

SetNumSides(0);

}

void Circle::SetRadius(int radius) {

radius_ = radius;

}

int Circle::GetRadius() {

return radius_;

}

void Circle::SetFillColor(std::string fill_color) {

fill_color_ = fill_color;

}

std::string Circle::GetFillColor() {

return fill_color_;

}

void Circle::SetBorderColor(std::string border_color) {

border_color_ = border_color;

}

std::string Circle::GetBorderColor() {

return border_color_;

}

float Circle::Area() {

return M_PI * radius_ * radius_;

}

float Circle::Perimeter() {

return 2 * M_PI * radius_;

}

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

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions

Question

The scope and aim of positive psychology.

Answered: 1 week ago