Can I replace the using namespace std;
from the implementation file with some other syntax in the header file? what would be the best way to include this code in order for cout
to work fine?
Here's my header file:
#ifndef LINE_H
#define LINE_H
#include<iostream>
#include<cmath>
class Line
{
public:
Line();
Line(double x1, double y1, double x2, double y2);
void setLine(double a1, double b1, double a2, double b2);
double getLen();
void printLine();
~Line();
private:
double x1,y1,x2,y2,length;
double Length(double a1, double b1, double a2,double b2);
};
#endif // LINE_H
And here's the implementation file:
#include "Line.h"
using namespace std;
// **********Constructors*****************
Line::Line() {}
Line::Line(double x1, double y1, double x2, double y2){
this-> x1=x1; this-> y1=y1; this->x2=x2; this->y2=y2;
length = Length(x1,y1,x2,y2);
}
// ***********Public Methods***********************
void Line::setLine(double a1, double b1, double a2, double b2){
x1=a1; y1=b1; x2=a2; y2=b2;
length = Length(x1,y1,x2,y2);
}
double Line::getLen(){
return length;
}
void Line::printLine(){
cout<<"("<<x1<<","<<y1<<") --> ("<<x2<<","<<y2<<")"<<endl;
}
// ***********Private Methods***************
double Length(double a1, double b1, double a2,double b2){ //Private method which calculates the distance between 2 points.
return sqrt(pow(b2-b1,2)+pow(a2-a1,2));
}
// ***********Destructor******************
Line::~Line(){}