Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Person{
- public:
- string name, birthDate;
- Person(string name, string date){
- this->name = name;
- this->birthDate = date;
- }
- void print(){
- cout << "Person: {Name: " << name << ", Birth Date: " << birthDate << "}";
- }
- };
- class Teacher : public Person{
- public:
- string category, classes[36];
- Teacher(string name, string date, string category, string classes[], int classesLength) : Person(name, date){
- this->category = category;
- if(classesLength <= 36) for(int i = 0; i < classesLength; i ++) this->classes[i] = classes[i];
- }
- void print(){
- cout << "Teacher: {Name: " << name << ", Birth Date: " << birthDate << ", Category: " << category << ", Classes: ";
- for(int i = 0; i < 36; i++){
- if(classes[i] == "") break;
- else cout << classes[i] << " ";
- }
- cout << "}";
- }
- void next(){
- string newClasses[36];
- int index = 0;
- for(int i = 0; i < 36; i ++){
- if(classes[i] != ""){
- string element = classes[i];
- int c = stoi(element.substr(0, element.length() - 1)) + 1;
- if(c <= 11){
- newClasses[index] = to_string(c) + element.substr(element.length() - 1, 1);
- index++;
- }
- else classes[i] = "";
- }
- }
- for(int i = 0; i < 36; i++) classes[i] = newClasses[i];
- }
- };
- class Pupil : public Person{
- public:
- string project, m_class;
- Pupil(string name, string date, string project, string theClass) : Person(name, date){
- this->project = project;
- this->m_class = theClass;
- }
- void print(){
- cout << "Pupil: {Name: " << name << ", Birth Date: " << birthDate << ", Class: " << m_class << ", Project: " << project << "}";
- }
- };
- void info(Person *people[], int amount){
- cout << "Info: {\n";
- for(int i = 0; i < amount; i++) {
- people[i]->print();
- cout << "\n";
- }
- cout << "}";
- }
- int main(){
- string classes[5] = {"10A", "11B", "5C"};
- Teacher *teacher = new Teacher("Teacher's Name", "10.10.2010", "Biology", classes, 5);
- cout << "Teacher before next():" << endl;
- teacher->print();
- cout << endl << "Teacher after next():" << endl;
- teacher->next();
- teacher->print();
- cout << endl << endl;
- Person* people[] = {new Pupil("Pupil's Name 1", "11.10.2021", "Pupil's project", "10B"), new Pupil("Pupil's Name 2", "11.10.2021", "Pupil's project", "10B"), teacher};
- info(people, 3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement