PLEASE DO NOT POST CODE ON HERE SEND TO jamanemo4yahoocom PL
*******************PLEASE DO NOT POST CODE ON HERE*******************
SEND TO: jama_nemo4@yahoo.com
PLEASE SEND ME ORGINIAL CODE WITH COMMENTS. PLEASE DO NOT SEND UNORIGINAL CODE.
Thank You!
The goal of this project is to:
1. Understand the principle of abstraction and encapsulation and use them to implement classes.
2. Overload various operators and become aware of their restrictions.
3. Highlights the peculiarities of classes with pointer data members and how to avoid them.
4. Create and work with dynamic two-dimensional arrays.
Problem:
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:
a. If a line is nonvertical, then determine its slope.
b. If two lines are not parallel, then find the point of intersection.
c. Overloads the stream insertion operator, <<, for easy output.
d. Overloads the stream extraction operator, >>, for easy intput. (The line ax + by = c is input as (a, b, c).)
e. Overloads the assignment operator to copy a line into another line.
f. Overloads the unary operator +, as a member function, so that it returns true if a line is vertical; false otherwise.
g. Overloads the unary operator -, as a member function, so that it returns true if a line is horizontal; false otherwise.
h. Overloads the operator ==, as a member function, so that it returns true if two lines are equal; false otherwise.
i. Overloads the operator ||, as a member function, so that it returns true if two lines are parallel; false otherwise.
j. Overloads the operator &&, as a member function, so that it returns true if two lines are perpendicular; false otherwise.
Add appropriate constructors to initialize variables of lineType. Also write a program to test your class
*******************PLEASE DO NOT POST CODE ON HERE*******************
SEND TO: jama_nemo4@yahoo.com
PLEASE SEND ME ORGINIAL CODE WITH COMMENTS. PLEASE DO NOT SEND UNORIGINAL CODE.
Thank You!
Solution
#include<iostream>
using namespace std;
class lineType{
public: float slope;
float a1,b1,c1;
public:float setData(float a1,float b1,float c1){
a1=a1;
b1=b1;
c1=c1;
}
friend ostream &operator<<( ostream &output, //<< overloaded
const lineType &l ) {
output <<\"\ Line\" << l.a1 << \"x+\" << l.b1<<\"y=\"<<l.c1;
return output;
}
friend istream &operator>>( istream &input, lineType &l ) { // >> overloaded
cout<<\"\ Enter the values of a,b,c for line:\";
input>>l.a1>>l.b1>>l.c1;
return input;
}
public:float calcSlope(lineType l1){ //function to calculate slope
if(l1.b1!=0)
{
slope=-l1.a1/l1.b1;
}
return slope;
}
public:float poi(lineType l1,lineType l2){ //function to calculate point of intersection
if(l1.b1*l2.b1!=0 && l1.a1*l2.a1!=0){ //checking for 0
float x,y;
x=(l1.c1/l1.b1-l2.c1/l2.b1) / (l1.a1/l1.b1-l2.a1/l2.b1);
y=l1.c1/l1.b1-(l1.a1/l1.b1)*x;
cout<<\"\ Point of intersection for x is:\"<<x;
cout<<\"\ Point of intersection for y is:\"<<y;
}
}
};
int main(){
float a1,b1,c1,a2,b2,c2;
float slope1,slope2;
lineType l1,l2,temp;
cin>>l1;
cin>>l2;
cout<<l1;
cout<<l2;
slope1=l1.calcSlope(l1);
cout<<\"\ Slope for the line1:\"<<slope1;
slope2=l2.calcSlope(l2);
cout<<\"\ Slope for the line2:\"<<slope2;
if(slope1!=slope2){
temp.poi(l1,l2);
}
}

