Start by using the starter code provided for the Line class. It implements operator overloading so you can use cin/cout with line objects.
A line will be made up of two points.
Create an object to implement a “line” class which allows the programmer to store a line. This class must use the “point” class developed in Part B. 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 vertical
Determine if the line is horizontal
Determine if the line is parallel to another line
Please create proper test cases for this in main() to verify proper functioning.
Note: You should make it easy on yourself and use four integers representing the two ends of the line for the second constructor
Starter Code:
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using namespace std;
// Please complete this Point class.
// The cin/cout operators have been overloaded for you
class Point {
// cout implementation for Point class
friend ostream & operator<<( ostream &output, const
Point &P ){
output << "x: " << P.x << " y: " <<
P.y;
return output;
}
// cin implementation for Point class
friend istream & operator>>( istream &input, Point
&P ){
input >> P.x >> P.y;
return input;
}
public:
Point(){
x = 0;
y = 0;
}
Point(int in_x, int in_y){
x = in_x;
y = in_y;
}
// Add your functions here
private:
int x,y;
};
int main(){
Point P1;
Point P2(7,6);
cout << "Point P1 should have 0,0 as values" <<
endl;
cout << P1 << endl;
cout << "Point P2 should have 7,6 as values" <<
endl;
cout << P2 << endl;
cout << "Enter x and y points: ie 3 4 ";
cin >> P1;
cout << P1 << endl;
return 0;
}
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <cmath>
using namespace std;
// Please complete this Point class.
// The cin/cout operators have been overloaded for you
class Point {
// cout implementation for Point class
friend ostream & operator<<( ostream &output, const
Point &P ){
output << "x: " << P.x << " y: " <<
P.y;
return output;
}
// cin implementation for Point class
friend istream & operator>>( istream &input, Point
&P ){
input >> P.x >> P.y;
return input;
}
public:
Point(){
x = 0;
y = 0;
}
Point(int in_x, int in_y){
x = in_x;
y = in_y;
}
// Add your functions here
int getX()
{
return x;
}
int getY()
{
return x;
}
private:
int x,y;
};
class Line
{
private :
Point p1;
Point p2;
public :
Line(Point p1, Point p2) {
this->p1 = p1;
this->p2 = p2;
}
double getSlope() {
double sl = ((double) p1.getY() - p2.getY()) / ((double) p1.getX()
- p2.getX());
return sl;
}
double getLength() {
return sqrt(pow((p2.getX() - p1.getX()), 2) + pow((p2.getY() -
p1.getY()), 2));
}
bool parallelTo(Line line) {
if (this->getSlope() == line.getSlope())
return true;
return false;
}
bool isVertical(Line other)
{
double slope1=this->getSlope();
double slope2=other.getSlope();
if(slope1 * slope2==-1)
return true;
else
return false;
}
};
int main(){
Point P1;
Point P2(7,6);
cout << "Point P1 should have 0,0 as values" <<
endl;
cout << P1 << endl;
cout << "Point P2 should have 7,6 as values" <<
endl;
cout << P2 << endl;
Point P3(4,4);
Point P4(3,5);
Line l1(P1,P2);
Line l2(P3,P4);
cout<<"Slope of
Line#1:"<<l1.getSlope()<<endl;
cout<<"Slope of
Line#2:"<<l2.getSlope()<<endl;
bool b=l1.parallelTo(l2);
if(b)
{
cout<<"Line#1 is parallel to
Line#2"<<endl;
}
else
{
cout<<"Line#1 is not parallel to
Line#2"<<endl;
}
b=l1.isVertical(l2);
if(b)
{
cout<<"Line#1 is Vertical to
Line#2"<<endl;
}
else
{
cout<<"Line#1 is not Vertical to
Line#2"<<endl;
}
return 0;
}
________________________
Output:

_________________Thank You
Start by using the starter code provided for the Line class. It implements operator overloading so...
Why is the assertion failing? what code can fix the problem and
where should that code be located at?
class Point { public: Point() { myX = myY = 0; } Point(int n, int y) { myx = x; myy = y; } int getX() const { return myX; } int getY() const { return myY; } virtual void read(istream& in) { in >> myX >> myY; } private: int myx, myY; }; class Point3D : Public Point { public:...
This is for c++ Implement the following overloading operator functions: Matrix (int rowSize, int colSize); ~Matrix (); Matrix operator + (Matrix & m); Matrix operator += (Matrix & m); Matrix operator += (const int &num); Matrix operator * (Matrix & m); Matrix operator ++(); friend Matrix operator +(const int &num, const Matrix &m); friend istream& operator>> (istream& in, const Matrix& m); friend ostream &operator<<(ostream &os, const Matrix &m); Test your Matrix class withe following main function: cout << "Matrix 1:"...
please provide full answer with comments this is just begining
course of c++ so don't use advanced tequenicks I'll put main.cpp,
polynomial.h, polynomial.cpp and Cimg.h at the bottom of pictures.
If you help me with this will be greatly thankful thank
you
main.cpp
#include "polynomial.h"
#include "polynomial.h"
#include "polynomial.h"
#include "polynomial.h"
#include <iostream>
using std::cout;
using std::endl;
int main() {
pic10a::polynomial p1;
p1.setCoeff(0, 1.2);
p1.setCoeff(3, 2.2);
p1.setCoeff(7, -9.0);
p1.setCoeff(7, 0.0);
//degree of polynomial is now 3
cout << p1 <<...
NEED ASAP PLEASE HELP
Task:
---------------------------------------------------------------------------------------------------------------------------------
Tasks to complete:
----------------------------------------------------------------------------------------------------------------------------------------
given code:
-----------------------------------------------------------------------------------------------------------------------------------------------
main.cpp
#include <iostream>
#include <iomanip>
#include "fractionType.h"
using namespace std;
int main()
{
fractionType num1(5, 6);
fractionType num2;
fractionType num3;
cout << fixed;
cout << showpoint;
cout << setprecision(2);
cout << "Num1 = " << num1 << endl;
cout << "Num2 = " << num2 << endl;
cout << "Enter the fraction in the form a / b: ";
cin >> num2;
cout << endl;
cout <<...
Write a MyString class that stores a (null-terminated) char* and a length and implements all of the member functions below. Default constructor: empty string const char* constructor: initializes data members appropriately Copy constructor: prints "Copy constructor" and endl in addition to making a copy Move constructor: prints "Move constructor" and endl in addition to moving data Copy assignment operator: prints "Copy assignment" and endl in addition to making a copy Move assignment operator: prints "Move assignment" and endl in addition...
Write a generic function int find_lower_bound(T seq[], int n, const T& value). The function returns the index of the largest element in the given sequence that is less than the given value. If multiple elements satisfy, return the one with smallest index. Return -1 if no such element exists. //main.cpp #include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; #include "source.h" struct Point{ int x,y; bool operator<(const Point& p) { return (x<p.x || (x==p.x&&y<p.y)); } }; int...
(1) Declaration and implementation of complex class, overloading operator +, -, != , /, --(prefix), --(postfix) as friend functions. (2)The program should be in Separating Class Specification, Implementation(complex.h,complex.cpp), and Client Code(Task2.cpp). (3) Run the program and capture screenshots of output. Declaration and implementation of complex class, overloading operator +, -, != , /=, --(prefix), --(postfix) as friend function */ #include "Complex.h" #include <iostream> using namespace std; int main(){ Complex c1(5, 4), c2(2, 10), c3; cout <<...
In the following code, it gets hung up at cout << "Number1 * Number2 = " << number1 * number2 << endl; giving an error of "no math for operator<<" what am i doing wrong? Thank you #include <iostream> #include <cctype> #include <cstdlib> using namespace std; class Rational //class for rational numbers (1/2, 5/9, ect..) { public: Rational(int numerator, int denominator); Rational(int numberator); Rational(); //default friend istream& operator >>(istream& ins,...
Task:
Tasks to complete:
------------------------------------------------------------------------------------------------------------------------------------------
given code:
------------------------------------------------------------------------------------------------------------------------------------------
main.cpp
#include
#include "rectangleType.h"
using namespace std;
// part e
int main()
{
rectangleType rectangle1(10, 5);
rectangleType rectangle2(8, 7);
rectangleType rectangle3;
rectangleType rectangle4;
cout << "rectangle1: " << rectangle1 <<
endl;
cout << "rectangle2: " << rectangle2 <<
endl;
rectangle3 = rectangle1 + rectangle2;
cout << "rectangle3: " << rectangle3 << endl;
rectangle4 = rectangle1 * rectangle2;
cout << "rectangle4: " << rectangle4 << endl;
if (rectangle1 > rectangle2)
cout << "Area...
USING C++: Referring to the header file below named coord2d.h, Implement each of the 8 operator overloads (operators: <<, [], >, <, two versions of +, two versions of *) #ifndef COORD2D_H #define COORD2D_H #include <iostream> using namespace std; //implement a class that keeps track of the coordinates of a point in the X-Y plane class coord2d { //overload the << operator so that if p is of type "coord2d" then "cout<<p"; //will print out (x_coord, y_coord) //e.g. if p.x_coord=3.4,...