Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Dog {
  5.  
  6.  private:
  7.  
  8.  string name;
  9.  int age;
  10.  string color;
  11.  
  12.  public:
  13.  
  14.  Dog(){
  15.  name = "";
  16.  age = 0;
  17.  color = "";
  18.  }
  19.  Dog(string name, int age, string color){
  20.  this->name = name;
  21.  this->age = age;
  22.  this->color = color;
  23.  }
  24.  string getName() { return name; }
  25.  
  26.  void bark(){
  27.  cout << name << " is barking!.." << endl;
  28.  }
  29.  
  30.  void bark(Dog d){
  31.  cout << name << " is barking at " << d.getName() << "... !" << endl;
  32.  }
  33.  
  34.  void bark(Dog d1, Dog d2){
  35.  cout << name << " is barking at " << d1.getName()
  36.  << " and " << d2.getName() << "... !" << endl;
  37.  }
  38. };
  39.  
  40. class Cat {
  41.  private:
  42.  
  43.  string name;
  44.  int age;
  45.  string color;
  46.  
  47.  public:
  48.  
  49.  Cat(){
  50.  name = "";
  51.  age = 0;
  52.  color = "";
  53.  }
  54.  Cat(string name, int age, string color){
  55.  this->name = name;
  56.  this->age = age;
  57.  this->color = color;
  58.  }
  59.  string getName() { return name; }
  60.  
  61.  void scratch(){
  62.  cout << name << " is barking!.." << endl;
  63.  }
  64.  
  65.  void scratch(Dog d){
  66.  cout << name << " is scratching " << d.getName() << "... !" << endl;
  67.  }
  68.  
  69.  void scratch(Dog d, Cat c){
  70.  cout << name << " is scratching " << d.getName()
  71.  << " and " << c.getName() << "... !" << endl;
  72.  }
  73. };
  74.  
  75. //----------------------------------------------- MAIN
  76. int main() {
  77.  cout << "\n\n";
  78.  
  79.  Dog d1("Pluto", 3, "Brown");
  80.  Dog d2("Max", 2, "Black");
  81.  Dog d3("Lucy", 13, "White");
  82.  
  83.  Cat c1("Mini", 1, "Gray");
  84.  Cat c2("Daisy", 2, "Yellow");
  85.  
  86.  d1.bark();
  87.  d2.bark();
  88.  
  89.  d1.bark(d2);
  90.  d2.bark(d1);
  91.  
  92.  d3.bark(d2, d1);
  93.  
  94.  c1.scratch(d1, c2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement