Monday, August 24, 2020

When 1+1 is a three or more

Lately I been the learning C++ on http://www.cplusplus.com/, then I catch me eye a silly news, that some times,
1+1=3 Like family and breeding, I get idea to test my new skills on this subject

#include 
using namespace std;

class Pulsu {
  public:
    int Afterbreed;
    int BreedingRate;
    Pulsu () {};
    Pulsu (int x, int y){Afterbreed=x; BreedingRate=y;}
    Pulsu operator + (const Pulsu&);
};

Pulsu Pulsu::operator+ (const Pulsu& p) {
  Pulsu temp;
  //temp.BreedingRate=(BreedingRate+p.BreedingRate)/2;
 if((BreedingRate+p.BreedingRate)%2==0){
     temp.BreedingRate=int ((BreedingRate+p.BreedingRate)/2);
     
 }else{
     temp.BreedingRate=int ((BreedingRate+p.BreedingRate+1)/2);//I notice these must alter to int or else //error
     //it is not int if like 3/2
 }




  if( (Afterbreed-p.Afterbreed)<=0){
      temp.Afterbreed =(Afterbreed*2)+ (Afterbreed*temp.BreedingRate) -(Afterbreed-p.Afterbreed);
      
      }else{
          temp.Afterbreed =(p.Afterbreed*2)+(Afterbreed*temp.BreedingRate) +(Afterbreed-p.Afterbreed);
          
          }
  
  
  return temp;
}



int main () { 
  Pulsu Ratfemales={22,0};//22 is how many and 0 is breedinrate
  Pulsu Ratmales={15,3};
  Pulsu Ratfamily;
  Ratfamily=Ratmales+Ratfemales;
  cout << Ratfamily.Afterbreed <<'\n' ;
  return 0;
}
According https://www.onlinegdb.com/online_c++_compiler  52 is answer.
Yes! and it was no 1+1 but 22+15 and breeding rate 0 and 3

No comments:

Post a Comment

3D BLog has return

Go  to Check    https://thereal3dblog.com/