Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- class Person
- {
- private:
- static int countPersons;
- int idPerson;
- int priorityPerson;
- public:
- Person(int priorityPerson=3) :idPerson{countPersons++}
- {
- if (priorityPerson < 1 or priorityPerson>3)
- { this->priorityPerson = 3; }
- else
- { this->priorityPerson = priorityPerson; }
- }
- static int getCountPersons() { return countPersons; }
- int getIdPerson(){return idPerson; }
- int getPriorityPerson(){return priorityPerson;}
- void minucСountPersons()
- {
- --countPersons;
- }
- void plusCountPersons()
- {
- ++countPersons;
- }
- void changePriority(int priority)
- {
- priorityPerson=priority;
- }
- };
- int Person::countPersons{ 0 };
- class TableOut
- {
- private:
- Person* persons;
- public:
- TableOut()=default;
- void addPerson(Person& object)
- {
- Person* temp=persons;
- temp[0].plusCountPersons();
- persons=new Person[temp[0].getCountPersons()];
- for (int index{0}; index<temp[0].getCountPersons()-1; ++index) {
- persons[index]=temp[index];
- }
- persons[temp[0].getCountPersons()-1]=object;
- }
- void showStat()
- {
- for (int index{0}; index<persons[0].getCountPersons(); ++index) {
- std::cout<<"Person ID "<<persons[index].getIdPerson()<<". Go out "<<index<<"\n";
- }
- }
- };
- class Printer
- {
- private:
- Person* persons;
- TableOut object;
- int front{0};
- int back;
- public:
- //Construct
- Printer(Person* persons) :persons{ persons }, front{ 0 }, back{persons[0].getCountPersons()-1} {sortPersons(); }
- //Destruct
- ~Printer() { delete[] persons; front = 0, back = 0; }
- //Methods
- void sortPersons();
- void getFront();
- void putBack(int priorityPerson);
- void putBack(const Person* object);
- void showStat()
- {
- object.showStat();
- }
- //Operators
- //NONE
- };
- int main()
- {
- Person* persons=new Person[6]{1,3,1,2,3,3};
- Printer printer{persons};
- printer.getFront();
- printer.showStat();
- printer.putBack(2);
- printer.getFront();
- printer.showStat();
- }
- void Printer::sortPersons()
- {
- for (int index{0}; persons[0].getCountPersons()-1; ++index) {
- int indexForCycleWhile=index+1;
- while(persons[indexForCycleWhile-1].getPriorityPerson()>persons[indexForCycleWhile].getPriorityPerson())
- {
- std::swap(persons[index],persons[index+1]);
- }
- }
- }
- void Printer::getFront()
- {
- if(front!=back){
- Person* temp=persons;
- temp[0].minucСountPersons();
- persons=new Person[temp[0].getCountPersons()];
- for (int index{0}; index<temp[0].getCountPersons(); ++index) {
- persons[index]=temp[index+1];
- }
- object.addPerson(temp[0]);
- }
- }
- void Printer::putBack(int priorityPerson)
- {
- Person* temp=persons;
- temp[0].plusCountPersons();
- persons=new Person[temp[0].getCountPersons()];
- for (int index{0}; index<temp[0].getCountPersons()-1; ++index)
- {
- persons[index]=temp[index];
- }
- persons[temp[0].getCountPersons()-1].changePriority(priorityPerson);
- sortPersons();
- ++back;
- }
- void Printer::putBack(const Person* object)
- {
- Person* temp=persons;
- persons=new Person[temp[0].getCountPersons()+object[0].getCountPersons()];
- int index{0};
- for (; index<temp[0].getCountPersons(); ++index) {
- persons[index]=temp[index];
- }
- for (int indexNull{0}; index<temp[0].getCountPersons()+object[0].getCountPersons(); ++index,++indexNull) {
- persons[index]=object[indexNull];
- ++back;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement