1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
#include <cmath>
using namespace std;
// Declare Class
class Distance {
double x1, x2, y1, y2;
void setx1 ( double x1 ) { this-> x1 = 10.0;}
void setx2 ( double x2 ) { this-> x2 = 20.0;}
void sety1 ( double y1 ) { this-> y1 = 40.0;}
void sety2 ( double y2 ) { this-> y2 = 50.0;}
public:
Distance( double x1, double x2, double y1, double y2 )
: x1(x1), x2(x2), y1(y1), y2(y2)
{
}
double GetDistance() {return sqrt( pow(x2 - x1, 2) + pow(y2 - y1, 2) );}
//functions
double get_x1() { return x1; }
double get_x2() { return x2; }
double get_y1() { return y1; }
double get_y2() { return y2; }
};
void main ()
{
double length;
double x1, x2, y1, y2;
length = GetDistance(x1,x2,y1,y2);
cout << "distance is" << length << "\n";
|