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