fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Cat {
  6. private:
  7. string name;
  8. int age;
  9.  
  10. public:
  11. Cat(string catName, int catAge) {
  12. name = catName;
  13. age = catAge;
  14. }
  15.  
  16. void meow() {
  17. cout << name << " says: Meow!" << endl;
  18. }
  19.  
  20. void sleep() {
  21. cout << name << " is sleeping... Zzz..." << endl;
  22. }
  23.  
  24. void showInfo() {
  25. cout << "Cat's Name: " << name << " | Age: " << age << " years old" << endl;
  26. }
  27. };
  28.  
  29. int main() {
  30. Cat myCat("Whiskers", 3);
  31. myCat.showInfo();
  32. myCat.meow();
  33. myCat.sleep();
  34.  
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Cat's Name: Whiskers | Age: 3 years old
Whiskers says: Meow!
Whiskers is sleeping... Zzz...