cout< Point a(2,4);Point b(5,6); Rectangle Y(a,b); cout << "Perimetr = "< cout<<"Yuza = "< return 0; } Natija: perimetr = 200 yuza = 2400 perimetr = 10 yuza = 6 #include using namespace std; class Point { public: Point(int x1 = 0,int y1 = 0) { x = x1;y = y1; } int GetX() const {return x;} int GetY() const {return y;} private: int x; int y; }; class Rectangle { public: Rectangle(int x1,int y1,int x2,int y2): p1(x1,y1),p2(x2,y2) { a = x2-x1; b = y2-y1; }; Rectangle(Point a1,Point a2):p1(a1),p2(a2) { a = a2.GetX() - a1.GetX(); b = a2.GetY() - a1.GetY(); }; int Per() { return 2*(a+b); } int Sq() {return a*b; } private: Point p1,p2; int a,b; }; int main() { Rectangle X(10, 20, 50, 80); cout << "Perimetr = "< cout << "Yuza = "< cout< Point a(2,4);Point b(5,6); Rectangle Y(a,b); cout << "Perimetr = "< cout<<"Yuza = "< return 0; }
Do'stlaringiz bilan baham: |