Question
C++ : Shape, color, triangle, and rectangle class and derived class files. -------------------------------------------------------------------------------------- There are 9 files. main.cpp (given) shape.h / shape.cpp (given) color.h (given)
C++ : Shape, color, triangle, and rectangle class and derived class files.
--------------------------------------------------------------------------------------
There are 9 files.
main.cpp (given)
shape.h / shape.cpp (given)
color.h (given) / color.cpp
triangle.h (given) / triangle.cpp
rectangle.h (given) / rectangle.cpp
--------------------------------------------------------------------------------------
Problems:
- Shape.cpp needs a class file to be made, shape.h. (Need shape.h)
- Color.cpp is a derived class of Color.h. Color class models the color of an item (Need color.cpp)
- Triangle.cpp is a derived class of Triangle.h. Triangle class models triangle with side lengths a, b, c (Need triangle.cpp)
- Rectangle.cpp is a derived class of Rectangle.h. Rectangle class models Rectangle with side lengths l, w (Need rectangle.cpp)
The main.cpp does all the math, but the other files just set up the info to be pulled from. I'm guessing the shape.cpp is an idea of what the other .cpp files should be like. Thanks in advance!
-------------------------------------------------------------------------------------------------------------------------
[shape.cpp]
#include "shape.h"
Shape::Shape() // Initializes private attribute c to <0,0,0> { c = new Color; }
Shape::Shape(int r, int g, int b) // Initializes Color object pointed to by c to
Shape::~Shape() // Deallocates Color object { delete c; }
Color Shape::getColor() const // Returns color of object { return *c; }
double Shape::area() const // Returns default area of 0.0 -- must be a polymorphic function { return 0.0; }
double Shape::perimeter() const // Returns default perimeter of -1.0 -- must be a polymorphic function { return -1.0; }
----------------------------------------------------------------------------------------------------------------------
[color.h]
#include
#ifndef COLOR_H #define COLOR_H
class Color { private: int red; // Amount of red 0-255 int green; // Amount of green 0-255 int blue; // Amount of blue 0-255
public: Color(); // Initializes red, green, and blue to zero void setRed(int rr); // Sets red to rr void setGreen(int gg); // Sets green to gg void setBlue(int bb); // Sets blue to bb
int getRed() const; // Returns red int getGreen() const; // Returns green int getBlue() const; // Returns blue
void print() const // Writes
#endif ------------------------------------------------------------------------------------------
[triangle.h]
#include "shape.h"
#ifndef TRIANGLE_H #define TRIANGLE_H
class Triangle : public Shape { private: double a, b, c; // Side lengths
public: Triangle(); // Initializes a, b, c to 0.0 and red, green, blue to 0
Triangle(double aaa, double bbb, double ccc, // Initializes a, b, c to aaa, bbb, ccc and int rr, int gg, int bb); // red, green, blue to rr, gg, bb respectively
double area() const; // Returns area value computed from a, b, c
double perimeter() const; // Returns perimeter value computed from a, b, c };
#endif ------------------------------------------------------------------------------------------
[rectangle.h]
#include "shape.h"
#ifndef RECTANGLE_H #define RECTANGLE_H
class Rectangle : public Shape { private: double l, w; // Side lengths
public: Rectangle(); // Initializes l, w to 0.0 and red, green, blue to 0
Rectangle(double ll, double ww, // Initializes l, w to ll, ww and int rr, int gg, int bb); // red, green, blue to rr, gg, bb respectively
double area() const; // Returns area value computed from l, w
double perimeter() const; // Returns perimeter value computed from l, w };
#endif
Step 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