0Dima_0

Person / Pupil classes 2

Oct 17th, 2021 (edited)
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Person{
  7.   public:
  8.     string name, birthDate;
  9.  
  10.     Person(string name, string date){
  11.       this->name = name;
  12.       this->birthDate = date;
  13.     }
  14.  
  15.     void print(){
  16.       cout << "Person: {Name: " << name << ", Birth Date: " << birthDate << "}";
  17.     }
  18. };
  19.  
  20. class Teacher : public Person{
  21.   public:
  22.     string category, classes[36];
  23.  
  24.     Teacher(string name, string date, string category, string classes[], int classesLength) : Person(name, date){
  25.       this->category = category;
  26.       if(classesLength <= 36) for(int i = 0; i < classesLength; i ++) this->classes[i] = classes[i];
  27.     }
  28.  
  29.     void print(){
  30.       cout << "Teacher: {Name: " << name << ", Birth Date: " << birthDate << ", Category: " << category << ", Classes: ";
  31.       for(int i = 0; i < 36; i++){
  32.         if(classes[i] == " ") break;
  33.         else cout << classes[i] << " ";
  34.       }
  35.       cout << "}";
  36.     }
  37.  
  38.     void next(){
  39.       string newClasses[36];
  40.       int index = 0;
  41.       for(int i = 0; i < 36; i ++){
  42.         string element = classes[i];
  43.         int c = stoi(element.substr(0, element.length() - 1)) + 1;
  44.         if(c < 11){
  45.           newClasses[index] = to_string(c) + element.substr(element.length() - 1, 1);
  46.           index++;
  47.         }
  48.       }
  49.       for(int i = 0; i < index; i++) classes[i] = newClasses[i];
  50.     }
  51. };
  52.  
  53. class Pupil : public Person{
  54.   public:
  55.     string project, m_class;
  56.  
  57.     Pupil(string name, string date, string project, string theClass) : Person(name, date){
  58.       this->project = project;
  59.       this->m_class = theClass;
  60.     }
  61.  
  62.     void print(){
  63.       cout << "Pupil: {Name: " << name << ", Birth Date: " << birthDate << ", Class: " << m_class << ", Project: " << project << "}";  
  64.     }
  65. };
  66.  
  67. int main(){
  68.   string classes[5] = {"10A", "11A", "5B"};
  69.   Teacher teacher = new Teacher("Teacher's Name", "10.10.2010", "Biology", classes, 5)
  70. }
Add Comment
Please, Sign In to add comment