Created
January 19, 2020 00:55
-
-
Save RGamberini/e3a6e69ba62778093288b4bf7adb0bb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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