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

Question

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 <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]]
}

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

#include <iostream>   
#include<math.h>

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 < operator
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

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Databases

Data Structures

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: p.s: see image for question.

A: #include &lt;iostream&gt;using namespace std;double findslope(double x1,double x2,double y1,double y...

Q: Subject:Database

A: T1                               T2                                       T3 Lock-X(B)Read(B) B=B-50...

Q: In Java: Modify the attached program code below According to the question a, b and c a. Replace the ...

A: import java.util.Scanner;class DoublyLinkedList { private Node head;private Node tail;private int s...

Q: Explain the concept of tunneling IPv6 datagrams through IPv4 routers

A: Tunneling mechanism  Tunneling mechanism is the mechanism in which all the routers between two IPv6...

Q: Problem 5 ( Suppose that your hash function resolves collisions using open addressing with double ha...

A: The, answer has given below;

Q: discrete math

A: Note : As per the guidelines we are supposed to answer only one question , please repost other quest...

Q: Write the SQL statements for the following User table. User_id Name City Order_date Purchase_amount ...

A: To create a table in SQL, create table command is used. Ans 1. The required query is: CREATE TABLE U...

Q: Write a program which allocates the integers 1-8 to the squares in the figure above, subject to the ...

A: The code for the given problem is written below in c++ programming language-   #include &lt;cstdlib&...

Q: The Internet has fast become a key instrument for the exercise of the right to freedom of speech. In...

A: Freedom of speech is a principle that encourages an individual's or a community's freedom to express...

Q: Hello, How can I do this : Modify the program and use the strtok function to count the number of wor...

A: Click to see the answer

Q: Let B be a Boolean algebra. Show that (a) a ^0 = 0 (b) a V (a A b) = (c) a V (¬a A b) = a V b.

A: Click to see the answer

Q: Qn 1: Write a C++ program to multiply 2 matrices using multi-dimensional arrays. Program should ask ...

A: Program code:     //inlcuding necessary header files #include &lt;iostream&gt; using namespace std; ...

Q: Description You are contacted by a Birthday Party Clubownerwho wants you to help withmaking a Websit...

A: Click to see the answer

Q: Write one program that does the following: Ask the user for ten (10) grades, and store the data in ...

A: python code:   import randomdef getGrades(gradesarray,size):    for i in range(size):        n=int(i...

Q: Suppose your one-button such that 'B’ or 'b’ of your keyboard is does not work correctly. If you typ...

A: import java.util.Scanner;//importing scanner class public class Main{ public static void main(String...

Q: I need a comparative table of 100BaseT, 1000BaseT, 1000BaseL.X, 1000BaseS.X, 100GBaseT, 10GBaseLR, d...

A: A LAN is a computer network limited to a small area such as an office building, university, or even ...

Q: please answer to number 1  thank youu

A: a) f(n) = 11.2+12.3+...+1n(n+1)f(1) = 11.2 is TrueLet f(k) is truef(k) = 11.2+12.3+...+1k(k+1) =k --...

Q: Java GUI (Calculator) Program

A: // Java program to calculate // double integral value class GFG{  // Change the function according t...

Q: Evaluate the following expressions given below step by step to show the explanation. e1 = (10 * Z Y...

A: The, answer has given below:

Q: Code in C# (OOP Concept) Suppose that Fruit, Apple, Orange, GoldenDelicious, and McIntosh are define...

A: What is an instance(object):- (OVERVIEW) A class defines a type of object, but it is not an object i...

Q: It is a Question from Discrete Mathematics , Topic Nested Quantifiers

A: (a) $\forall x \forall y((x &lt; 0) \wedge(y &lt; 0) \rightarrow(x+y&lt;0))$(b) $\exists x \exists y...

Q: (k) get_topx_areas_of_crimes(2D1ist, x) that takes a 2D-list (database) and an integer x as input. T...

A: Program Plan:- 1. Define the function get_topx_areas_of_crimes(database, x): 2. Find out the total c...

Q: Briefly state the principle following multple access protocol  a). TDMA; B).FDMA; C) Pure ALOHA d)Sl...

A: Solution:  Multiple access protocols  : They are group  of protocols  that operate in Medium Access ...

Q: i) Common Vulnerabilities of Fedora OS (FIVE (5) vulnerabilities).ii) Tools/techniques used to asses...

A: Note: In the question there is multiple parts. According to the guidelines you will get the answers ...

Q: In a POS system, a transaction is based on items purchased by the customer. The following is an exam...

A: Building a Point of Sales (POS) linked list data structure: Class for POSNode: In Point of sales Li...

Q: This is the question -  Write an application in which you declare an array of eight first names. Wri...

A: GIVEN: Create a Java program and declare an array of eight first names. Write a try block. Get the i...

Q: **PLEASE USE C#**Create a program named TipCalculation that includes two overloaded methods named Di...

A: The required C# code is given below:   using System;class TipCalculation {    // method that accept ...

Q: (Fall 2020) (Given 11/24/20 Homework #4 Due: 12/10/20) Following is a data description of a library:...

A: Actually, database is used to stores the data.

Q: (d) create_area_dict(list2D) that takes a 2D-list containing the database as input and creates a dic...

A: def create_area_dict(database):    d={}    for i in range(len(database)):        key=database[i][0] ...

Q: Create a pentagon (5 sided polygon) in code blocks

A: Since it is not mentioned here nor the programming language. Following is a code in c++ using graphi...

Q: The Code must be in Matlab

A: % Defining vectorM = [0 8 11 14 17 ; 0 1 11 14 17 ; 1 2 0 14 4 ];disp('Matrix is')disp(M) % Display ...

Q: 2. Otherwise, search recursively by comparing K with the element located at [n/4]. If it equal, then...

A: Divide-and-conquer, breaks a problem into subproblems that are similar to the original problem, recu...

Q: Develop an assembly language program for 8085 microprocessor to count continuously in hexadecimal fr...

A: Program Plan:- The counter will be set by using register and loading it with starting number and th...

Q: Design an expanding opcode to allow all the following to be encoded in a 32-bit instruction:15 instr...

A: Format 1:

Q: Prepare a "Functionality Requirement Analysis" document which informs technical people about require...

A: Solution: Requirement Analysis can be stated as the process of  defining user expectations to build ...

Q: Write a program which compresses a given string of 1s and 0s and uncompress the string that was comp...

A: Note: Below is the required program in java language. Program Explanation: The code below asks a use...

Q: need help with python. Also, can you explain how we have to do this? Please write codes for prog1.py...

A: Actually, python is easiest programming language. It is a dynamically typed programming language.  

Q: Write microC program to 8 bits up counter using pic16f84a

A: Actually, 1 byte=8 bits.

Q: A typical hash function often consists of the following three steps: Group of answer choices hashing...

A: Click to see the answer

Q: Consider the following set of functional dependency for the relation schema R = (А, В, С, D, E, F, G...

A: Functional Dependency: A functional dependency refers to the connection between any two fields of a ...

Q: Code in C# (OOP Concept) Do a program that does the following: Ask for a number from the user in the...

A: Step 1:-   The first program in the C# programming language and the second program in the C++ progra...