Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Ponto {
- //private:
- int x, y;
- public:
- Ponto(int a, int b) {
- x = a;
- y = b;
- }
- void setX(int v) {x = v;}
- int getX() {return x;}
- void setY(int v) {y = v;}
- int getY() {return y;}
- bool equals(Ponto c) {
- if(c.x == x && c.y == y)
- return true;
- return false;
- }
- float distancia(Ponto c) {
- float r;
- r = sqrt(pow(x - c.x, 2) + pow(y - c.y, 2));
- return r;
- }
- };
- int main () {
- int p1x, p1y, p2x, p2y;
- cout << "Informe os valores de x e y do ponto 1: ";
- cin >> p1x >> p1y;
- cout << "Informe os valores de x e y do ponto 2: ";
- cin >> p2x >> p2y;
- Ponto *p = new Ponto(p1x, p1y);
- Ponto *q = new Ponto(p2x, p2y);
- //(*q).setX(2); (*q).setY(4);
- cout << "\np(" << (*p).getX() << "," << (*p).getY() << ")\nq(" << (*q).getX() << "," << (*q).getY() << ")\n";
- cout << "p equals q: " << (*p).equals(*q) << endl;
- cout << "p dist q: " << (*p).distancia(*q) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement