Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<cmath>
- #define PI 3.14159265358979323846
- using namespace std;
- class Circle{
- private:
- float x, y; // x, y - координати центру круга
- float R; // R - радіус круга
- public:
- // пустий констуктор
- Circle(){
- x = y = 0;
- R = 1;
- cout << " by empty constructor " << endl;
- }
- // констуктор ініціалізації списком
- Circle (float a, float b, float c) : x(a), y(b), R(c){
- cout << " by list constructor " << endl;
- }
- // констуктор копіювання
- Circle(const Circle ©){
- x = copy.x;
- y = copy.y;
- R = copy.R;
- cout << " by copy constructor " << endl;
- }
- // оператор -
- friend Circle operator - (const Circle &x, const Circle &y);
- // оператор >=
- bool operator >= ( Circle &x){
- return (calculateSquare() >= x.calculateSquare());
- }
- // функція вводу полів
- void set(string q);
- // функція друку полів
- void show(string q);
- // функція обробки даних
- float calculateSquare() { return PI * pow(R,2); } // обчислення площі круга
- void showCond(string q, float P){
- if (calculateSquare() < P)
- show(q);
- else
- cout << "Circle " << q << " square > P" << endl << endl;
- }
- };
- int main() {
- Circle C1;
- C1.set("1");
- Circle C2;
- C2.show("2");
- Circle C3 = C2;
- C3.show("3");
- Circle C4;
- C4 = C1 - C3;
- C4.show("4");
- cout << "C4 >= C1: " << (C4 >= C1) << endl;
- cout << " Sguare of circle C1 = " << C1.calculateSquare() << endl;
- cout << " Sguare of circle C2 = " << C2.calculateSquare() << endl;
- cout << " Sguare of circle C3 = " << C3.calculateSquare() << endl;
- cout << " Sguare of circle C4 = " << C4.calculateSquare() << endl;
- int n;
- cout << endl << "Enter count of objects: ";
- cin >> n;
- Circle objs[n];
- for (int i = 0; i < n; i++) {
- objs[i].set(i + "0");
- }
- float P;
- cout << endl << "Enter P: ";
- cin >> P;
- cout << endl << "Result: " << endl;
- for (int i = 0; i < n; i++) {
- cout << "P of circle " << i + 1 << " = " << objs[i].calculateSquare() << endl;
- objs[i].showCond(i + "0", P);
- }
- return 0;
- }
- void Circle :: set(string q) {
- cout << "Please, enter information about circle " << q << ":" << endl;
- cout << " x = ";
- cin >> x;
- cout << " y = ";
- cin >> y;
- cout << " R = ";
- cin >> R;
- cout << endl;
- }
- void Circle :: show(string q) {
- cout << "Info about circle " << q << ":" << endl;
- cout << " x = " << x << endl;
- cout << " y = " << y << endl;
- cout << " R = " << R << endl;
- cout << endl;
- }
- Circle operator - (const Circle &x, const Circle &y){
- Circle c(x.x - y.x, x.y - y.y, x.R - y.R);
- return c ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement