Uploaded by Mu-Gamer

Lab1 H.W

advertisement
#include<math.h>
using namespace std;
class point
{
private:
float x;
float y;
public :
void setvalue(int,int);
void print();
void coordinate(int,int);
float distance(float,float);
};
Header File (point.h)
void point::setvalue(int x1, int y1 )
{
x=x1;
y = y1;
}
void point::print()
{
cout << endl << "main point coordinates are :" << "x =" << x << "," << "y =" << y << endl;
}
void point::coordinate(int x1,int y1)
{
if (x == x1 && y > y1)
cout << x1 << "," << y1 << " lies below the main point ";
else if (x == x1 && y < y1)
cout << x1 << "," << y1 << " lies above the main point ";
else if (y == y1 && x < x1)
cout << x1 << "," << y1 << " lies right of the main point";
else if (y == y1 && x > x1)
cout << x1 << "," << y1 << " lies left of the main point";
else if (x > x1 && y > y1)
cout << x1 << "," << y1 << " lies below left of main point";
else if (x < x1 && y > y1)
cout << x1 << "," << y1 << " lies below right of the main point";
else if (x < x1 && y < y1)
cout << x1 << "," << y1 << " lies above right of the main point";
else if (x > x1 && y < y1)
cout << x1 << "," << y1 << " lies above left of the main point";
else
cout << x1 << "," << y1 << " lies on the origin";
}
float point::distance(float x1, float y1)
{
float distance;
return distance = sqrt(pow(x1 - x, 2) + pow(y1 - y, 2));
}
#include<iostream>
#include "HW_1.h"
using namespace std;
int main()
{
point A;
point B;
point C;
C++ file (.cpp)
A.setvalue(2,2);
cout << endl << "Distance between two points :" << A.distance(3.0, 5.0) << endl;
A.coordinate(3.0, 5.0);
A.print();
cout << endl << "Distance between two points :" << A.distance(-4.0, 3.0) << endl;
A.coordinate(-4.0, 3.0);
A.print();
cout << endl << "Distance between two points :" << A.distance(-2.0, -1.0) << endl;
A.coordinate(-2.0, -1.0);
A.print();
cout << endl << "Distance between two points :" << A.distance(1.0, -6.0) << endl;
A.coordinate(1.0, -6.0);
A.print();
B.setvalue(1,1);
cout << endl << "Distance between two points :" << B.distance(3.0, 5.0) << endl;
B.coordinate(3.0, 5.0);
B.print();
cout << endl << "Distance between two points :" << B.distance(-4.0, 3.0) << endl;
B.coordinate(-4.0, 3.0);
B.print();
cout << endl << "Distance between two points :" << B.distance(-2.0, -1.0) << endl;
B.coordinate(-2.0, -1.0);
B.print();
cout << endl << "Distance between two points :" << B.distance(1.0, -6.0) << endl;
B.coordinate(1.0, -6.0);
B.print();
C.setvalue(0, 0);
cout << endl << "Distance between two points :" << C.distance(3.0, 5.0) << endl;
C.coordinate(3.0, 5.0);
C.print();
cout << endl << "Distance between two points :" << C.distance(-4.0, 3.0) << endl;
C.coordinate(-4.0, 3.0);
C.print();
cout << endl << "Distance between two points :" << C.distance(-2.0, -1.0) << endl;
C.coordinate(-2.0, -1.0);
C.print();
}
cout << endl << "Distance between two points :" << C.distance(1.0, -6.0) << endl;
C.coordinate(1.0, -6.0);
C.print();
Download