Need code in C++. I have answer till part 7,please go through the code and correct it if you find any mistakes. If not answer the last 4 parts(8,9,10,11) Create a class called Line with the...



Need code in C++. I have answer till part 7,please go through the code and correct it if you find any mistakes. If not answer the last 4 parts(8,9,10,11)


Create a class called Line with the followings:
1. Private members: p1 and p2 as pointer to Point objects (code provided below), slope and length as double variables
2. Define setter and getter functions.
3. Define a default constructor that allocate dynamic memory for points and
set everything to 0.
4. Overload a constructor that allocates memory for points, initilize them
with given arguments, and calculate the slope and length.
5. Overload a destructor, a copy constructor and a copy assignment operator.
6. Create a function called ”parallel” that return true when given lines are
parallel and returns false otherwise
7. Overload the less than (<) and="" greater="" than="" (="">) and equality (==) oper-
ators (compare the length)
8. Write a functions that reads lines in the format provided in the lines.txt
from the file and stores them in a vector named Lines.
9. Sort the objects of Lines vector in descending order.
10. Extend the functionality of cin and cout for this class
11. Write a separate file to extensively test your code as you learned in unit
testing lessens.


#include
using namespace std;


#ifndef POINT_H
#define POINT_H


class point {
public:
point(double X = 0, double Y = 0) : x(X), y(Y) {}
void setX(double x) {this->x = x ;}
double getX() const {return this->x ;}
void setY(double y) {this->y = y ;}
double getY() const {return this->y ;}
void print() const;
friend point operator+(point lhp, point rhp);
friend point operator+(point lhp, pair rhp);
friend point operator+(pair lhp, point rhp);
private:
double x;
double y;
};


void point::print() const{
cout < "x,y="" :="" ("="">< this-="">x < ","="">< this-="">y < ")"=""><>
}
point operator+(point lhp, point rhp) {
return point(lhp.x +rhp.x, rhp.y +rhp.y);
}
point operator+(point lhp, pair rhp) {
return point(lhp.x + rhp.first, lhp.y +rhp.second);
}
point operator+(pair lhp, point rhp) {
return point(lhp.first+rhp.x , lhp.second +rhp.y);
}




#endif


lines.txt


lines:
{
[line1:[102.0,0.9],[97.0,1.0]],
[line2:[103.0,0.8],[98.0,1.0]],
[line3:[104.0,0.7],[99.0,1.0]],
[line4:[105.0,0.6],[100.0,1.0]]
}


This is the code that I have till now(for first 7 parts)


#include
#include


using namespace std;


struct Point{


int x;
int y;




};


// Class definition starts here
class Line{


Point p1,p2;
double slope;
double length;


public:


void setPoint(Point p1,Point p2){
this->p1 = p1;
this->p2 = p2;
}


void setSlope(double slope){
this->slope = slope;
}


void setLength(double length){
this-> length = length;
}


Point getPoint1(){
return p1;
}


Point getPoint2(){
return p2;
}


double getSlope(){
return slope;
}


double getLength(){
return length;
}


Line(){


p1.x=0;
p2.x = 0;
p2.y=0;
p1.y = 0;
slope =0;
length = 0;


}




Line(Point p1, Point p2){


length = sqrt(pow((p1.x-p2.x),2)+pow((p1.y-p2.y),2));
slope = (p2.y-p1.y)/(p2.x-p1.x);


}


Line(const Line &l){
p1 = l.p1;
p2 = l.p2;
slope = l.slope;
length = l.length;
}


Line parallel(){


Point p[2];
Point p3,p4;
p3=p1;
p4=p2;


p3.x = p1.x + 1;
p4.x = p2.x + 1;


Line l(p3,p4);




return l;


}


// overloaded <>
bool operator <(const line&="" l)="">
if(length < l.length)="">
return true;
}
if(length== l.length && slope < l.slope)="">
return true;
}


return false;
}


}; // Class definition ends here

Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here