#include <iostream>
using namespace std;
class Triangle
{
private:
double base, height, area;
char color[20];
public:
Triangle() {}
void inputData() {
cout << "Input base:";
cin >> base;
cout << "Input height:";
cin >> height;
cout << "Input color:";
cin >> color;
}
void findArea() {
area = 0.5*base*height;
cout << "The area of the triangle:" << area << '\n';
}
double getArea() const {
return area;
}
const char *getColor() const {
return color;
}
};
class Match_Triangle
{
Triangle t1, t2;
public:
Match_Triangle(const Triangle &t1, const Triangle &t2) : t1(t1), t2(t2) {}
void isMatch() {
string s1 = t1.getColor(), s2 = t2.getColor();
if ((t1.getArea() == t2.getArea()) && (s1 == s2)) {
cout << "Matching Triangle\n";
} else {
cout << "Non-Matching Triangle\n";
}
}
};
int main() {
Triangle t1, t2;
t1.inputData();
t2.inputData();
t1.findArea();
t2.findArea();
Match_Triangle tr = Match_Triangle(t1, t2);
tr.isMatch();
return 0;
}
Output:
Input base:
4
Input height:
5
Input color:
white
Input base:
4
Input height:
5
Input color:
white
The area of the triangle:10
The area of the triangle:10
Matching Triangle
Comments
Leave a comment