Facebook
From tfrf, 1 Week ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 121
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Superhero{
  5.  
  6.     int strength, speed, intelligence;
  7.  
  8. public:
  9.  
  10.     superhero(int str, int spd, int intel){
  11.  
  12.         strength = str;
  13.         speed = spd;
  14.         intelligence = intel;
  15.     }
  16.  
  17.     int getTotalAttributes(){
  18.  
  19.         return strength + speed + intelligence;
  20.     }
  21.  
  22.     friend bool operator>(Superhero& hero1, Superhero& hero2);
  23.  
  24. };
  25.  
  26. bool operator>(Superhero& hero1, Superhero& hero2){
  27.  
  28.         return hero1.getTotalAttributes() > hero2.getTotalAttributes();
  29.     }
  30.  
  31. int main(){
  32.  
  33.     Superhero superman = Superhero(100, 90, 80);
  34.     Superhero batman = Superhero(80, 70, 100);
  35.  
  36.     if(superman > batman){
  37.  
  38.         cout<<"Superman wins the game"<<endl;
  39.     }
  40.     else{
  41.  
  42.         cout<<"Batman wins the game"<<endl;
  43.     }
  44.  
  45.     return 0;
  46. }
  47.