Hi, i wrote this code and it compiles ok but it doesnt do all the operations in
ID: 3640157 • Letter: H
Question
Hi, i wrote this code and it compiles ok but it doesnt do all the operations in the functions
for example isequal is true only if the two lines are exactly the same, isparallel is always true...plz if someone can help i would really appreaciate it!thx!!!
MAIN
#include <iostream>
#include "lineType.h"
using namespace std;
double x,y;
int main()
{
lineType line1;
line1.linecheck();
line1.NonVertical();
lineType line2;
line2.linecheck();
line2.NonVertical();
if(line1.AreEqual(line2)==true)
cout<<"The lines are equal"<<endl;
else
cout<<"The lines are not equal"<<endl;
if(line1.AreParallel(line2)==true)
cout<<"The lines are Parallel"<<endl;
else
cout<<"The lines are not Parallel"<<endl;
if(line1.ArePerpendicular(line2)==true)
cout<<"The lines are Perpendicular"<<endl;
else
cout<<"The lines are not Perpendicular"<<endl;
if(line1.AreParallel(line2)==false)
cout<<line1.Intersection(line2)<<x<<y<<endl;
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////header
#ifndef LINETYPE_H
#define LINETYPE_H
class lineType
{
public:
lineType();
void linecheck();
void NonVertical();
bool AreEqual(lineType line2);
bool AreParallel(lineType line2);
bool ArePerpendicular(lineType line2);
double Intersection(lineType line2);
double getA(){
return a;
}
double getB(){
return b;
}
double getC(){
return c;
}
double getSlope(){
return s;
}
private:
double a;
double b;
double c;
double s;
};
#endif // LINETYPE_H
///////////////////////////////////////////////////////////////////////////////////////////////////////////// linetype.cpp//////////////////////
#include "lineType.h"
#include <iostream>
using namespace std;
lineType::lineType()
{
cout<<"Please input values for a, b and c"<<endl;
cin>>a;
cin>>b;
cin>>c;
}
void lineType::linecheck()
{
while ((a==0)&&(b==0))
{
cout <<"Error a and b are both equal to zero, Please try again"<<endl;
cin >> a>>b>>c;
}
}
void lineType::NonVertical()
{
if(b!=0)
{
s=-a/b;
cout <<"The line is nonvertical and the slope is "<< s <<endl;
}
else
{
cout<<"the line is vertical and undefined"<<endl;
}
}
bool lineType::AreEqual(lineType line2)
{
if(a==line2.getA() && b==line2.getB() && c==line2.getC() || a/line2.getA()==b/line2.getB()==c/line2.getC())
return true;
else
return false;
}
bool lineType::AreParallel(lineType line2)
{
if(a==0 && line2.getB()==0||b==0 && line2.getA()==0)
return false;
else if(s==line2.getSlope()||b==line2.getB()==0)
return true;
else
return false;
}
bool lineType::ArePerpendicular(lineType line2)
{
if((a==0 && line2.getB()==0)||(b==0 && line2.getA()==0)||(s*line2.getSlope()==-1))
return true;
else
return false;
}
double lineType::Intersection(lineType line2)
{
double x,y;
x=((b*line2.getC())-(line2.getB()*c))/((a*line2.getB())-(line2.getA()*b));
return x;
y=((line2.getA()*c)-(a*line2.getC()))/((a*line2.getB())-(line2.getA()*b));
return y;
}
Explanation / Answer
Your conditional checks and line intersection check is wrong. I've messaged you the correct source code. Please rate this reply. I don't want to put the solution here.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.