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)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 <iostream>
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<double,double> rhp);
friend point operator+(pair <double,double> lhp, point rhp);
private:
double x;
double y;
};

void point::print() const{
cout << "x,y : (" << this->x << "," << this->y << ")" << endl;
}
point operator+(point lhp, point rhp) {
return point(lhp.x +rhp.x, rhp.y +rhp.y);
}
point operator+(point lhp, pair<double,double> rhp) {
return point(lhp.x + rhp.first, lhp.y +rhp.second);
}
point operator+(pair<double,double> 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]]
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education