03


SUBMITTED BY: mrslimous

DATE: May 24, 2017, 3:32 a.m.

FORMAT: Text only

SIZE: 2.3 kB

HITS: 273

  1. #include<iostream>
  2.  
  3. class Kwadrat{
  4. protected:
  5.     int x;
  6.     int y;
  7.     float bok;
  8.     float pole;
  9. public:
  10.     Kwadrat& operator+=(const Kwadrat& wsk){
  11.         pole+=wsk.pole;
  12.         x=(x+=wsk.x)/2;
  13.         y=(y+=wsk.y)/2;
  14.         return *this;
  15.     };
  16.     Kwadrat& operator+=(const double& wsk){
  17.         pole+=wsk;
  18.         return *this;
  19.     };
  20.     const Kwadrat operator=(const Kwadrat &wsk){
  21.         x=wsk.x;
  22.         y=wsk.y;
  23.         bok=wsk.bok;
  24.         pole=wsk.pole;
  25.         return *this;
  26.     };
  27.  
  28.     const Kwadrat operator++(){
  29.         pole++;
  30.         return *this;
  31.     };
  32.  
  33.     const Kwadrat operator++(int){
  34.         Kwadrat przed(x,y,bok);
  35.         przed.licz_pole();
  36.         pole++;
  37.         return przed;
  38.     };
  39.  
  40.     Kwadrat(int a,int b,float c) :x(a),y(b),bok(c){};
  41.     Kwadrat() : x(1), y(1), bok(1) {};
  42.     void wypis(void);
  43.     void licz_pole(void);
  44.     friend const Kwadrat operator+(const Kwadrat& wsk,const Kwadrat& wsk1);
  45. };
  46.  
  47. void Kwadrat::licz_pole( ){
  48.     pole=bok*bok;
  49. }
  50.  
  51. void Kwadrat::wypis(){
  52.     printf("Polozenie: %d, %d\n dlugosc boku: %.2f, pole: %.2f\n",x,y,bok,pole);
  53. }
  54.  
  55.  
  56. const Kwadrat operator+(const Kwadrat& wsk,const Kwadrat& wsk1){
  57. Kwadrat obiekt;
  58. obiekt.pole=wsk.pole+wsk1.pole;
  59. obiekt.x=(wsk.x+wsk1.y)/2;
  60. obiekt.y=(wsk.y+wsk1.y)/2;
  61. return obiekt;
  62. };
  63.  
  64. int main(){
  65.     Kwadrat Kw1(3,3,1), Kw2(5,5,5), Kw3;
  66.  
  67.     Kw1.licz_pole();
  68.     Kw2.licz_pole();
  69.     Kw3.licz_pole();
  70.  
  71.     printf("Kw1: ");
  72.     Kw1.wypis();
  73.     printf("Kw2: ");
  74.     Kw2.wypis();
  75.     printf("Kw3: ");
  76.     Kw3.wypis();
  77.  
  78. printf("\n\n");
  79. printf("Dodanie pola Kw2 do pola Kw1\n");
  80.     Kw1 += Kw2;
  81.     printf("Nowe pole Kw1\n");
  82.     Kw1.wypis();
  83.  
  84. printf("\n\n");
  85. printf("Dodanie 5 do Kw3\n");
  86. Kw3 +=5;
  87. printf("Nowe pole Kw3\n");
  88. Kw3.wypis();
  89.  
  90. printf("\n\n");
  91. printf("Kw1 = Kw2 + Kw3\n");
  92. Kw1 = Kw2+Kw3;
  93. printf("Nowe dane Kw1\n");
  94. Kw1.wypis();*/
  95.  
  96. printf("\n\n");
  97. printf("Kw1 przedrostkowe\n");
  98. ++Kw1;
  99. Kw1.wypis();
  100.  
  101. printf("Kw2 przyrostkowe\n");
  102. Kw2++;
  103. Kw2.wypis();
  104.  
  105. Kwadrat cos;
  106.  
  107. cos=++Kw2;
  108. printf("Kw przedrostkowe\n");
  109. cos.wypis();
  110.  
  111. Kwadrat wsk;
  112. wsk=Kw2++;
  113. printf("Kw przyrostkowe\n");
  114. wsk.wypis();
  115.  
  116.  
  117.  
  118.  
  119.  
  120. system("pause");
  121. }

comments powered by Disqus