Question: c++ programming I need some help with a c++ programming homework. The equation of a line in standard form is ax + by = c,
c++ programming
I need some help with a c++ programming homework.
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. Determine if two lines are equal. (Two lines a1x + b1y = c1 and a2x + b2y = c2 are equal if either a1 = a2, b1 = b2, and c1 = c2 or a1 = ka2, b1 = kb2, and c1 = kc2 for some real number k.)
c. Determine if two lines are parallel.
d. Determine if two lines are perpendicular.
e. If two lines are not parallel, then find the point of intersection. Add appropriate constructors to initialize variables of lineType. Also write a program to test your class.
Here is what I have so far, I am just very confused and don't know how to work with this anymore. I would like for you to have most of the same code I am providing you unless it is causing a compile error.
#include
using namespace std;
// Class definition class lineType { private: double a,b,c; public: lineType();//default contrusctor lineType(double,double,double);//overloaded constructor ~lineType();//destructor double getA();//gets double getB(); double getC(); void setA(double);//voids void setB(double); void setC(double); double slope(); bool perpendicular(lineType line); bool parallel(lineType line); bool equal(lineType line);
};
//default contrusctor lineType::lineType() { a=b=c=1; } //overloaded constructor lineType::lineType(double x, double y, double z) { a=x; b=y; c=z; } //destructor lineType::~lineType(){}; //gets double lineType::getA(){return a;} double lineType::getB(){return b;} double lineType::getC(){return c;} //voids void lineType::setA(double x){a=x;} void lineType::setB(double y){b=y;} void lineType::setC(double z){c=z;}
//Slope calculation double lineType::slope() { if (b==0) { cout << "Line is horizontal" << endl; } else { return -a/b; } }
//Check if equal lines bool lineType::equal(lineType line) { if ((a==line.a && b==line.b && c==line.c)||(a/line.a==b/line.b) && (b/line.b==c/line.c)) { cout <<"equal lines" << endl; return true; } else { return false; } }
//Check if parallel lines bool lineType::parallel(lineType line) { if (-a*line.b==-line.a*b) { return true; } else { return false; } }
//Chech if perpendicular lines bool lineType::perpendicular(lineType line) { if(a*line.a==-b*line.b) { return true; } else { return false; }
}
//Main function int main() { lineType line1; lineType line2(3,0,5); lineType line3(6,8,10); //call slope cout << line1.slope() << endl; cout << line2.slope() << endl; cout << line3.slope() << endl;
//call equal cout << line2.equal(line1); cout << line2.equal(line3);
//call parallel line2.parallel(line1); line2.parallel(line3);
//call perpendicular line2.perpendicular(line1); line2.perpendicular(line3); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
