#include<iostream>
class Kwadrat{
protected:
int x;
int y;
float bok;
float pole;
public:
Kwadrat& operator+=(const Kwadrat& wsk){
pole+=wsk.pole;
x=(x+=wsk.x)/2;
y=(y+=wsk.y)/2;
return *this;
};
Kwadrat& operator+=(const double& wsk){
pole+=wsk;
return *this;
};
const Kwadrat operator=(const Kwadrat &wsk){
x=wsk.x;
y=wsk.y;
bok=wsk.bok;
pole=wsk.pole;
return *this;
};
const Kwadrat operator++(){
pole++;
return *this;
};
const Kwadrat operator++(int){
Kwadrat przed(x,y,bok);
przed.licz_pole();
pole++;
return przed;
};
Kwadrat(int a,int b,float c) :x(a),y(b),bok(c){};
Kwadrat() : x(1), y(1), bok(1) {};
void wypis(void);
void licz_pole(void);
friend const Kwadrat operator+(const Kwadrat& wsk,const Kwadrat& wsk1);
};
void Kwadrat::licz_pole( ){
pole=bok*bok;
}
void Kwadrat::wypis(){
printf("Polozenie: %d, %d\n dlugosc boku: %.2f, pole: %.2f\n",x,y,bok,pole);
}
const Kwadrat operator+(const Kwadrat& wsk,const Kwadrat& wsk1){
Kwadrat obiekt;
obiekt.pole=wsk.pole+wsk1.pole;
obiekt.x=(wsk.x+wsk1.y)/2;
obiekt.y=(wsk.y+wsk1.y)/2;
return obiekt;
};
int main(){
Kwadrat Kw1(3,3,1), Kw2(5,5,5), Kw3;
Kw1.licz_pole();
Kw2.licz_pole();
Kw3.licz_pole();
printf("Kw1: ");
Kw1.wypis();
printf("Kw2: ");
Kw2.wypis();
printf("Kw3: ");
Kw3.wypis();
printf("\n\n");
printf("Dodanie pola Kw2 do pola Kw1\n");
Kw1 += Kw2;
printf("Nowe pole Kw1\n");
Kw1.wypis();
printf("\n\n");
printf("Dodanie 5 do Kw3\n");
Kw3 +=5;
printf("Nowe pole Kw3\n");
Kw3.wypis();
printf("\n\n");
printf("Kw1 = Kw2 + Kw3\n");
Kw1 = Kw2+Kw3;
printf("Nowe dane Kw1\n");
Kw1.wypis();*/
printf("\n\n");
printf("Kw1 przedrostkowe\n");
++Kw1;
Kw1.wypis();
printf("Kw2 przyrostkowe\n");
Kw2++;
Kw2.wypis();
Kwadrat cos;
cos=++Kw2;
printf("Kw przedrostkowe\n");
cos.wypis();
Kwadrat wsk;
wsk=Kw2++;
printf("Kw przyrostkowe\n");
wsk.wypis();
system("pause");
}