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)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 6SA
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning