junk
This commit is contained in:
parent
21b5d52c5d
commit
6674d44fd0
3 changed files with 19 additions and 1 deletions
|
@ -6,6 +6,13 @@ int main(int argc, char *argv[]) {
|
||||||
Point p = Point(10, 5);
|
Point p = Point(10, 5);
|
||||||
std::cout << p << std::endl;
|
std::cout << p << std::endl;
|
||||||
p.move(5, 5);
|
p.move(5, 5);
|
||||||
|
|
||||||
|
if (p.distance(Point(0, 0)) == p.distanceOrigin()) {
|
||||||
|
std::cout << "Distance is the same" << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Distance is not the same" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << p << std::endl;
|
std::cout << p << std::endl;
|
||||||
std::cout << "Hello, World!" << std::endl;
|
std::cout << "Hello, World!" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "point.hpp"
|
#include "point.hpp"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
Point::Point(int x, int y) {
|
Point::Point(int x, int y) {
|
||||||
this->x = x;
|
this->x = x;
|
||||||
|
@ -23,6 +24,14 @@ void Point::set(int x, int y) {
|
||||||
this->y = y;
|
this->y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Point::distance(Point p) {
|
||||||
|
return sqrt(pow(this->x - p.x, 2) + pow(this->y - p.y, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
float Point::distanceOrigin() {
|
||||||
|
return sqrt(pow(this->x, 2) + pow(this->y, 2));
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, const Point &obj) {
|
std::ostream &operator<<(std::ostream &os, const Point &obj) {
|
||||||
os << "Point: (" << obj.x << ", " << obj.y << ")";
|
os << "Point: (" << obj.x << ", " << obj.y << ")";
|
||||||
return os;
|
return os;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class Point {
|
class __attribute__((__packed__)) Point {
|
||||||
private:
|
private:
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ class Point {
|
||||||
void setX(int x);
|
void setX(int x);
|
||||||
void setY(int y);
|
void setY(int y);
|
||||||
void move(int dx, int dy);
|
void move(int dx, int dy);
|
||||||
|
float distance(Point p);
|
||||||
|
float distanceOrigin();
|
||||||
|
|
||||||
friend std::ostream &operator<<(std::ostream &os, const Point &obj);
|
friend std::ostream &operator<<(std::ostream &os, const Point &obj);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue