Question
Create an object to implement a triangle class which allows the programming to store a triangle object. The object should either the line or point
Create an object to implement a triangle class which allows the programming to store a triangle object. The object should either the line or point class developed previously. The object should have at least two constructors, appropriate set/get functions, and overloaded I/O functions. It should include functions the return the proper value for the following:
Determines if the your object is a triangle
Calculates the area of a triangle
Determines the perimeter of the triangle
Is your triangle a right triangle
Is your triangle is a an equilateral triangle
Using C++ with the code given
#includeusing namespace std; // We have setup class framework for you. Please copy the point // class and/or line class you created to this file. class Triangle { public: private: }; int main() { Triangle T1; return 0; }
point code
#include
using namespace std;
// We have setup class framework for you.
// Please add cin/cout overload first and at the same time add the coordinates
//
// See github example as specified in the assignment handout for exaamples
//
class Point {
public:
Point() {
x = 0;
y = 0;
}
Point(int a,int b) {
x = a;
y = b;
}
friend istream& operator>>(istream &input, Point &p ) {
// Finish me second by adding proper input >> statement
input >> p.x >> p.y;
return input;
}
friend ostream& operator<<(ostream &output, const Point &p ) {
// Finish me thrid by adding proper output << statement
output << "X coordinate is: " << p.x << " and Y coordinate is: " << p.y;
return output;
}
// Please add constructors and other functions here.
private:
// Add me first
int x;
int y;
};
int main() {
Point P1;
cout << "Enter P1: ";
cin >> P1;
cout << "P1: ";
cout << P1;
cout << endl;
return 0;
}
Line code
#include
using namespace std;
// We have setup class framework for you. Please copy the point // class you created to this file.
class Point {
public: Point() { x = 0; y = 0; }
Point(int a,int b) { x = a; y = b; }
friend istream& operator>>(istream &input, Point &p ) { // Finish me second by adding proper input >> statement input >> p.x >> p.y; return input; }
friend ostream& operator<<(ostream &output, const Point &p ) { // Finish me thrid by adding proper output << statement output << "X coordinate is: " << p.x << " and Y coordinate is: " << p.y << endl; return output; }
int getX() { return x; }
int getY() { return y; }
// Please add constructors and other functions here.
private: // Add me first int x; int y; };
class Line {
public: float slope() { if(p2.getX() - p1.getX() == 0) return -1; else return (p2.getY() - p1.getY())/(p2.getX() - p1.getX()); }
float length() { return pow(pow((p2.getY() - p1.getY()),1/2) + pow((p2.getX() - p1.getX()),1/2),2); }
float intercept() { return slope()*p1.getX() + p1.getY(); }
void parallel(Line l) { if(slope() == l.slope()) { cout<<"Lines are parallel" << endl; } else { cout<<"Lines are not parallel"<< endl; } }
void horizontal() { if(slope()==0) cout<<"Line is horizontal."<< endl; else cout<<"Line is not horizontal."<< endl; }
void vertical() { if(slope() == -1) cout<<"Line is vertical."<< endl; else cout<<"Line is not vertical."<< endl; }
void intersect(Line l) { if(slope() != l.slope()) { cout<<"Lines are intersects"<< endl; } else { cout<<"Lines are not intersects"<< endl; } }
friend istream& operator>>(istream &input, Line &l ) { // Finish me second by adding proper input >> statement Point p1 , p2; cout<<" \tX point: "; input>>p1; cout<<" \tY point: "; input>>p2; l.p1 = p1; l.p2 = p2; return input; }
friend ostream& operator<<(ostream &output, const Line &p ) { // Finish me thrid by adding proper output << statement output << "X Point : " << p.p1 << " and Y Point : " << p.p2; return output; } private: Point p1; Point p2; };
int main() { Line L1,L2;
cout << "Enter L1: "; cin >> L1;
cout << "L1: "; cout << L1; cout << endl;
cout<< "Slope of line : " << L1.slope() << endl; cout<< "Length of line : " << L1.length() << endl; cout<< "Y intercept of line : " << L1.intercept() << endl; L1.horizontal() ; L1.vertical();
cout << "Enter L1: "; cin >> L2;
cout << "L2 : "; cout << L2; cout << endl;
L1.parallel(L2) ; L1.intersect(L2);
return 0; }
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