lineTypeUse.cpp
#include <iostream>
#include "lineType.h"
using namespace std;
int main()
{
Line L1(3, 3, 5);
cout << "Line 1:"<<endl;
L1.NonVertical();
cout << "Line 2:"<<endl;
Line L2(2, 1, 5);
L2.NonVertical();
if (L1.isParallel (L2, L1.slope()))
cout<< "Two lines are parallel"<< endl;
else
cout<<"Not parallel"<<endl;
L1.isPerpendicular(L2, L1.slope());
if (!L1.isParallel(L2, L1.slope()))
L1.doubleersection(L2);
system("pause");
}
lineType.h
#ifndef LINE_H
#define LINE_H
class Line{
private:
double a;
double b;
double c;
public:
Line(double x, double y, double z);
double getA();
double getB();
double getC();
double slope();
void NonVertical();
bool isEqual(Line L2);
bool isParallel(Line& L2, double s1) const;
void isPerpendicular(Line& L2, double s1) const;
void doubleersection(Line& L2) const;
};
#endif
lineTypeImp.cpp
#include <iostream>
#include "lineType.h"
using namespace std;
Line::Line(double x, double y, double z)
{
a=x;
b=y;
c=z;
}
double Line::getA()
{
return a;
}
double Line::getB()
{
return b;
}
double Line::getC()
{
return c;
}
double Line::slope()
{
return -a/b;
}
void Line::NonVertical()
{
if (b!=0)
cout<<"Slope is:"<< slope()<<endl;
else
cout<<"Vertical"<<endl;
}
bool Line::isEqual(Line L2)
{
if ( (a==L2.getA()&& b==L2.getB() &&
c==L2.getC())
|| (a/L2.getA()==b/L2.getB()==c/L2.getC()))
return true;
else
return false;
}
bool Line::isParallel(Line& L2, double s1) const
{
if ((s1==L2.slope())
|| (b==0 && L2.getA()==0))
return true;
else
return false;
}
void Line::isPerpendicular(Line& L2, double s1) const
{
if (((a==0 && L2.getB()==0)
|| (L2.getA()==0 && b==0))
|| (L2.slope()* s1==-1))
cout<<"Two lines are Perpendicular"<<endl;
}
void Line::doubleersection(Line& L2) const
{
double x,y;
x=((b*L2.getC()) - (L2.getB()*c)) /
((a*L2.getB()) - (L2.getA()*b));
y=((L2.getA()*c)-(a*L2.getC())) /
((a*L2.getB())-(L2.getA()*b));
cout<<"doubleersection podouble: ("<<x<<", "<<y<<")"<<endl;
}
我在一起编译文件时遇到此错误
Undefined symbols for architecture x86_64:
"Line::NonVertical()", referenced from:
_main in lineTypeUse-c3101c.o
"Line::slope()", referenced from:
_main in lineTypeUse-c3101c.o
"Line::Line(double, double, double)", referenced from:
_main in lineTypeUse-c3101c.o
"Line::isParallel(Line&, double) const", referenced from:
_main in lineTypeUse-c3101c.o
"Line::doubleersection(Line&) const", referenced from:
_main in lineTypeUse-c3101c.o
"Line::isPerpendicular(Line&, double) const", referenced from:
_main in lineTypeUse-c3101c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是我使用的cmpiling命令
g ++ -o lineTypeImp.cpp lineTypeUse.cpp
如果有人能提供帮助我真的很感激