fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Pet {
  6. public:
  7. Pet(string petName = "Unnamed", int yearsOld = -1);
  8. void Print();
  9.  
  10. private:
  11. string name;
  12. int age;
  13. };
  14.  
  15. Pet::Pet(string petName, int yearsOld) {
  16. name = petName;
  17. age = yearsOld;
  18. }
  19.  
  20. void Pet::Print() {
  21. cout << name << ", " << age << endl;
  22. }
  23.  
  24. int main() {
  25. Pet dog;
  26. Pet cat("Max", 6);
  27.  
  28. cat.Print();
  29. dog.Print();
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Max, 6
Unnamed, -1