fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Students {
  6. public:
  7. Students(int);
  8. int GetTotal() const { return numStudents; }
  9.  
  10. private:
  11. int numStudents;
  12. };
  13.  
  14. Students::Students(int num) : numStudents(num) {}
  15.  
  16. class Tutor {
  17. public:
  18. Tutor(string);
  19. Tutor(string, int);
  20. void Print() const;
  21.  
  22. private:
  23. string name;
  24. Students students;
  25. };
  26.  
  27. Tutor::Tutor(string tutorName) : name(tutorName), students(0) {}
  28. Tutor::Tutor(string tutorName, int numStudents) : name(tutorName), students(numStudents) {}
  29.  
  30. void Tutor::Print() const {
  31. if (students.GetTotal() == 0){
  32. cout << name << " is solo" << endl;
  33. }
  34. else {
  35. cout << name << " teaches " << students.GetTotal() << " students" << endl;
  36. }
  37. }
  38.  
  39. int main() {
  40. Tutor myTutor("Leo");
  41. Tutor yourTutor("Aya", 4);
  42.  
  43. yourTutor.Print();
  44. myTutor.Print();
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Aya teaches 4 students
Leo is solo