Advertisement
irmantas_radavicius

Untitled

Apr 23rd, 2024
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <vector>
  5. #include <cmath>
  6. #include <cctype>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. class Animal {
  12.         string sound;
  13.     public:
  14.         Animal(string sound){
  15.             this->sound = sound;
  16.         }
  17.         void makeSound(){
  18.             cout << sound << endl;
  19.         }
  20. };
  21. class Dog : public Animal {
  22.     public:
  23.         Dog(string sound = "Woof!")
  24.             :Animal(sound)
  25.         {
  26.         }
  27.  
  28. };
  29. class Cat : public Animal {
  30.     public:
  31.         Cat(string sound = "Miaw!")
  32.             :Animal(sound)
  33.         {
  34.         }
  35. };
  36.  
  37. int main(){
  38.  
  39.     Dog dog;
  40.     dog.makeSound();
  41.  
  42.     Cat cat("Mew!");
  43.     cat.makeSound();
  44.  
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement