fork download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. class Person
  7. {
  8. public:
  9. string ID;
  10. string name;
  11. string surname;
  12. string department;
  13. string email;
  14.  
  15. public:
  16. //get and set functions for ID, Name, Surname, Department, Email properties
  17. string getID()
  18. {
  19. return this->ID;
  20. };
  21.  
  22. void setID(string _ID)
  23. {
  24. this->ID = _ID;
  25. };
  26.  
  27. string getName()
  28. {
  29. return this->name;
  30. };
  31.  
  32. void setName(string _name)
  33. {
  34. this->name = _name;
  35. };
  36.  
  37. string getSurname()
  38. {
  39. return this->surname;
  40. };
  41.  
  42. void setSurname(string _surname)
  43. {
  44. this->surname = _surname;
  45. };
  46.  
  47. string getDepartment()
  48. {
  49. return this->department;
  50. };
  51.  
  52. void setDepartment(string _department)
  53. {
  54. this->department = _department;
  55. };
  56.  
  57. string getEmail()
  58. {
  59. return this->email;
  60. };
  61.  
  62. void setEmail(string _email)
  63. {
  64. this->email = _email;
  65. };
  66. };
  67.  
  68. //inherit Student class from Person class
  69. class Student :public Person
  70. {
  71. private:
  72. static int student_counter;
  73. static Student _S[100];
  74.  
  75. public:
  76. //constructor
  77. Student()
  78. {
  79. };
  80.  
  81. Student(string id, string Name, string Surname, string Department, string Email)
  82. {
  83. setID(id);
  84. setName(Name);
  85. setSurname(Surname);
  86. setDepartment(Department);
  87. setEmail(Email);
  88. }
  89.  
  90. //student add
  91. static void addStudent(string id, string Name, string Surname, string Department, string Email)
  92. {
  93. if (student_counter >= 100)
  94. {
  95. cout << "cant add more students";
  96. }
  97. else
  98. {
  99. Student newS;
  100. newS.setID(id);
  101. newS.setName(Name);
  102. newS.setSurname(Surname);
  103. newS.setDepartment(Department);
  104. newS.setEmail(Email);
  105. _S[student_counter] = newS;
  106. student_counter++;
  107. }
  108. }
  109.  
  110. //display students
  111. static void display()
  112. {
  113. for (int i = 0; i < student_counter; i++)
  114. {
  115. cout << _S[i].getID() << " - ";
  116. }
  117. }
  118. };
  119.  
  120. int Student::student_counter = 0;
  121. Student Student::_S[100];
  122.  
  123. int main()
  124. {
  125. Student::addStudent("ST123456", "Ege", "Inan", "CS", "ege @ gmail.com");
  126. Student::display();
  127. }
Success #stdin #stdout 0.01s 5456KB
stdin
Standard input is empty
stdout
ST123456 -