Skip to content

Instantly share code, notes, and snippets.

@RGamberini
Created January 19, 2020 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RGamberini/e3a6e69ba62778093288b4bf7adb0bb1 to your computer and use it in GitHub Desktop.
Save RGamberini/e3a6e69ba62778093288b4bf7adb0bb1 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class Point {
float x, y;
public:
Point(float x, float y);
void setValues(float x, float y);
float getX();
float getY();
};
Point::Point(float x, float y) {
this->setValues(x,y);
}
void Point::setValues(float x, float y) {
this->x = x;
this->y = y;
}
float Point::getX() {
return x;
}
float Point::getY() {
return y;
}
class Circle {
float radius;
Point& center;
public:
Circle(float radius, Point& center);
float getRadius();
Point getCenter();
};
Circle::Circle(float radius, Point& center): center(center) {
this->radius = radius;
}
Point Circle::getCenter() {
return center;
}
float Circle::getRadius() {
return radius;
}
int main() {
Point p(1.0f, 1.0f);
Circle circle(3.0f, p);
cout << circle.getCenter().getX() << endl;
p.setValues(2.0f, 2.0f);
cout << circle.getCenter().getX() << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment