1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#ifndef COLORTRIANGLE_H
#define COLORTRIANGLE_H
#include "Triangle.h"
class ColorTriangle : public Triangle{
char color[20];
public:
ColorTriangle(char *clr, char *style, double w, double h) : Triangle(style, w, h){};
void showColor();
};
#endif
#include <iostream>
#include <cstring>
#include "ColorTriangle.h"
using namespace std;
ColorTriangle::ColorTriangle(char *clr, char *style, double w, double h){
strcpy(color, clr);
}
void ColorTriangle::showColor(){
cout << "Color is " << color << "\n";
}
#ifndef TRIANGLE_H
#define TRIANGLE_H
#include "TwoDShape.h"
class Triangle : public TwoDShape{
char style[20];
public:
Triangle();
Triangle(char *str, double w, double h) : TwoDShape(w,h){};
Triangle(double x) : TwoDShape(x){};
double area();
void showStyle();
};
#endif
#include <iostream>
#include <cstring>
#include "Triangle.h"
using namespace std;
Triangle::Triangle(){
strcpy (style, "unknown");
}
Triangle::Triangle(char *str, double w, double h) : TwoDShape(w,h){
strcpy(style, str);
}
Triangle::Triangle(double x) : TwoDShape(x){
strcpy(style, "isosceles");
}
double Triangle::area(){
return getWidth() * getHeight()/2;
}
void Triangle::showStyle(){
cout << "Triangle is " << style << "\n";
}
#ifndef TWODSHAPE_H
#define TWODSHAPE_H
class TwoDShape{
double width;
double height;
public:
TwoDShape();
TwoDShape(double w, double h);
TwoDShape(double x);
void showDim();
double getWidth();
double getHeight();
void setWidth(double w);
void setHeight(double h);
};
#endif
#include <iostream>
#include "TwoDShape.h"
using namespace std;
TwoDShape::TwoDShape(){
width=height=0.0;
}
TwoDShape::TwoDShape(double w, double h){
width=w;
height=h;
}
TwoDShape::TwoDShape(double x){
width=height=x;
}
void TwoDShape::showDim(){
cout << "Width and height are " << width << " and " << height << "\n";
}
double TwoDShape::getWidth() {return width;}
double TwoDShape::getHeight() {return height;}
void TwoDShape::setWidth(double w) {width=w;}
void TwoDShape::setHeight(double h) {height=h;}
|