I need help with Part B for this. Below is what I have from part A. #include usi
ID: 3732853 • Letter: I
Question
I need help with Part B for this. Below is what I have from part A.
#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;
}
Then this is the starter code given for part B. C++ LANGUAGE
#include
using namespace std;
// We have setup class framework for you. Please copy the point
// class you created to this file.
class Line {
public:
private:
};
int main() {
Line L1;
// cout << "Enter L1: ";
// cin >> L1;
// cout << "L1: ";
// cout << L1;
// cout << endl;
return 0;
}
Part B: (line_ class.cpp) - Milestone Part B Problem Statement: Create an object to implement a "ine" class which allows the programmer to store a line. This class must use the "point" class developed in Part A. The object should have two constructors, appropriate set/get functions, and overloaded I/O (cin/cout) functions. It should include functions the return the proper value for the following: Determine the slope of a line Determine the length of a line Determine the y-intercept of a line Determine if the line is horizontal Determine if the line is vertical » . Determine if a line is parallel to another line Determine if a line intersects another lineExplanation / Answer
Add to public : in Point class these two functions:
double get_x()
{
return x;
}
double get_y()
{
return y;
}
Then define the Line class as follows:
class Line {
public:
Line(); //default constructor
Line(Point p1, Point p2) //parameterised constructor
{
P1 = p1;
P2 = p2;
}
double get_slope()//for the form y = mx+b
{
double x1,y1,x2,y2,m;
x1 = p1.get_x();
y1 = p1.get_y();
x2 = p2.get_x();
y2 = p2.get_y();
m = (y2 - y1)/(x2-x1);
return m;
}
double get_length()
{
double x1,y1,x2,y2;
x1 = p1.get_x();
y1 = p1.get_y();
x2 = p2.get_x();
y2 = p2.get_y();
length = sqrt((x2-x1)^2+(y2-y1)^2)
return length;
}
double get_y_intercept()
{
double x1,y1,x2,y2,b;
x1 = p1.get_x();
y1 = p1.get_y();
x2 = p2.get_x();
y2 = p2.get_y();
b = y1 - ((y2-y1))/((x2-x1)*x1);
return b;
}
int is_horizontal_or_vertical()
{
double x1,y1,x2,y2,m;
x1 = p1.get_x();
y1 = p1.get_y();
x2 = p2.get_x();
y2 = p2.get_y();
m = (y2 - y1)/(x2-x1);
if(m==0){
return 1;
}
else if(m==1.5708){
return 2;
}
else
{
return 0;
}
}
double check_parallel(Line l){
double x1,y1,x2,y2,m,x11,y11,x21,y21,m1;
x1 = p1.get_x();
y1 = p1.get_y();
x2 = p2.get_x();
y2 = p2.get_y();
m = (y2 - y1)/(x2-x1);
x11 = l.p1.get_x();
y11 = l.p1.get_y();
x21 = l.p2.get_x();
y21 = l.p2.get_y();
m1 = (y21 - y11)/(x21-x11);
if(m = m1)
{
return true;
}
else
{
return m;
}
}
bool check_intersection(Line l)
{
double x1,y1,x2,y2,m,x11,y11,x21,y21,m1;
x1 = p1.get_x();
y1 = p1.get_y();
x2 = p2.get_x();
y2 = p2.get_y();
m = (y2 - y1)/(x2-x1);
x11 = l.p1.get_x();
y11 = l.p1.get_y();
x21 = l.p2.get_x();
y21 = l.p2.get_y();
m1 = (y21 - y11)/(x21-x11);
if(m = -1/m1)
{
return true;
}
else
{
return m;
}
}
double get_A() //accessor function
{
return A;
}
double get_B() //accessor function
{
return B;
}
private:
Point p1, p2; //Point class objects
double A,B; //for Ax+By+C=0
};
int main() {
Line L1;
// cout << "Enter L1: ";
// cin >> L1;
// cout << "L1: ";
// cout << L1;
// cout << endl;
return 0;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.