#include <iostream>
#include <cmath>
class Circle {
public:
double x;
double y;
double r;
Circle(double i, double j, double n){
x = i;
y = j;
r = n;
}
// Set the position of the center
void set_pos(double i, double j) {
x = i;
y = j;
}
// Calculate the perimeter of the circle
double perimeter() {
return 2 * M_PI * r;
}
};
//TODO: Add a method to calculate the area of the circle
class Rectangle {
public:
double x;
double y;
double w; // width
double h; // height
Rectangle (double rx, double ry, double rw, double rh){
x = rx;
y = ry;
w = rw;
h = rh;
}
// Set the position of the top left corner
void set_pos(double i, double j) {
x = i;
y = j;
}
// Calculate the perimeter of the rectangle
double perimeter() {
return 2 * (w + h);
}
};
// TODO: Add a method to calculate the area of the rectangle
int main() {
Circle c{0, 0, 1};
std::cout << c.perimeter() << std::endl;
c.set_pos(1, 1);
std::cout << "Coordinates of the center: (" << c.x << ", " << c.y << ")" << std::endl;
Rectangle r{0, 0, 1, 2};
std::cout << r.perimeter() << std::endl;
r.set_pos(-1, -1);
std::cout << "Coordinates of the top left corner: (" << r.x << ", " << r.y << ")" << std::endl;
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: