Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Person{
- public:
- string firstName, secondName, thirdName;
- void print(){
- cout << "Person: { First Name: " << firstName << ", Second Name: " << secondName << ", Third Name: " << thirdName << "}";
- }
- string getString(){
- return "First Name: " + firstName + ", Second Name: " + secondName + ", Third Name: " + thirdName;
- }
- Person(string firstName, string secondName, string thirdName){
- this->firstName = firstName;
- this->secondName = secondName;
- this->thirdName = thirdName;
- }
- };
- class Teacher : public Person{
- public:
- string category;
- string *classes;
- Teacher(string firstName, string secondName, string thirdName, string category, string classes[], int classesLength) : Person(firstName, secondName, thirdName){
- this->category = category;
- this->classes = new string[classesLength];
- for(int i = 0; i < classesLength; i++) this->classes[i] = classes[i];
- }
- void next(){
- int l = sizeof(classes) / sizeof(classes[0]);
- string *newClasses = new string[l]; //array of classes length
- int index = 0;
- for(int i = 0; i < l; 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(0, 1);
- }
- }
- classes = newClasses;
- }
- void print(){
- cout << "Teacher: {" << getString() << ", Category: " << category << ", Classes: ";
- for(int i = 0; i < sizeof(classes) / sizeof(classes[0]); i++) cout << classes[i];
- cout << "}";
- }
- };
- class Pupil : public Person{
- public:
- string grade, project;
- Pupil(string firstName, string secondName, string thirdName, string grade, string project) : Person(firstName, secondName, thirdName){
- this->grade = grade;
- this->project = project;
- }
- void print(){
- cout << "Pupil: {" << getString() << ", Class: " << grade << ", Project: " << project;
- }
- };
- void info(Person people[], int aomountToPint){
- for(int i = 0; i < aomountToPint; i++) people[i].print();
- }
- int main() {
- string classes[] = { "10a", "11b", "1c" };
- Teacher* teacher = new Teacher("A", "B", "C", "Biology", classes, sizeof(classes) / sizeof(classes[0]));
- cout << "Teacher before next()" << endl;
- teacher->print();
- cout << endl << "Teacher after next()" << endl;
- teacher->next();
- teacher->print();
- Person* people[] = {new Pupil("A", "B", "C", "class", "project"), teacher};
- info(*people, 2);
- }
Add Comment
Please, Sign In to add comment