Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please help me using c++! the equation of a line in standard form is ax + by = c

ID: 3773253 • Letter: P

Question

please help me using c++! the equation of a line in standard form is ax + by = c, wherein both a and b cannot be zero, and a, b, and c are real numbers. If b != 0, then –a/b is the slope of the line. If a = 0, then it is a horizontal line, and if b = 0, then it is a vertical line. The slope of a vertical line is undefined. Two lines are parallel if they have the same slope or both are vertical lines. Two lines are perpendicular if either one of the lines is horizontal and the other is vertical or the product of their slopes is –1. Design the class lineType to store a line. To store a line, you need to store the values of a (coefficient of x), b (coefficient of y), and c. Your class must contain the following operations. Implement the class lineType while considering the following: a. Overloads the stream insertion operator, >, for easy intput. (The line ax + by = c is input as (a, b, c).) c. Overloads the assignment operator to copy a line into another line. d. Overloads the unary operator +, as a member function, so that it returns true if a line is vertical; false otherwise. e. Overloads the unary operator -, as a member function, so that it returns true if a line is horizontal; false otherwise. f. Overloads the operator ==, as a member function, so that it returns true if two lines are equal; false otherwise. g. Overloads the operator ||, as a member function, so that it returns true if two lines are parallel; false otherwise. h. Overloads the operator &&, as a member function, so that it returns true if two lines are perpendicular; false otherwise.

Explanation / Answer

LineType.h

#include <iostream>

using namespace std;

class lineType
{
public:  
lineType();
   lineType(double a,double b,double c)
   {  
  
   }
   ~lineType();
  
   friend ostream &operator<<( ostream &output, const lineType &L );
  
   friend istream &operator>>( istream &input, lineType &L );
  
   void operator=(const lineType &L );
   bool operator+(const lineType &L);
   bool operator-(const lineType &L);
   bool operator==(const lineType &L);
   bool operator||(const lineType &L);
   bool operator&&(const lineType &L);
  
private:
double a;
   double b;
   double c;
}

LineType.cpp

class lineType
{
lineType()
{
a=0;
b=0;
c=0;
}
  
   lineType(double a,double b,double c)
   {  
       a=a;
       b=b;
       c=c;
   }
  
   friend ostream lineType::&operator<<( ostream &output, const lineType &L )
   {
output << "a : " << L.a << " b : " << L.b <<"c : "<<L.c;
return output;
}

friend istream lineType::&operator>>( istream &input, lineType &L )
{
input >> L.a >> L.b >>L.c;
return input;
}
   void lineType::operator=(const lineType &L )
   {
a = L.a;
b = L.b;
c = L.c;
}

bool lineType::operator+(const lineType &L)
{
   return (b==0);
}

bool lineType::operator-(const lineType &L)
{
   return (a==0);
}

bool lineType::operator==(const lineType &L)
{
   double slope=(a/b);
   double intercept=(c/b);

   return (slope==(L.a/L.b) && intercept==(L.c/L.b));
}

bool lineType::operator||(const lineType &L)
{
   if(b==0 && L.b==0)
   {
       return true;
   }
   else if(b==0 && L.b!=0 || L.b==0 && b!=0)
   {
       return false;
   }
   return ((a/b)==(L.a/L.b));
}

bool lineType::operator&&(const lineType &L)
{
   if(b==0 && L.b==0)
   {
       return false;
   }
   if (b==0 || L.b==0)
   {
       if(b==0 && L.a==0)
       {
           return true;
       }
       else if(L.b==0 && a==0)
       {
           return true;
       }

   }
   else
   {
       return(((a/b)*(L.a/L.b))==-1);
   }
}
};