Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- char *head;
- using namespace std;
- struct client {
- char position[128];
- int prior;
- int date;
- client *next, *prev;
- };
- class printer {
- client *head{};
- client *tail{};
- client *headStat{};
- client *tailStat{};
- public:
- printer() {
- head = nullptr;
- tail = nullptr;
- headStat = nullptr;
- tailStat = nullptr;
- }
- printer(const printer &ob) {
- }
- void addQueque(char *s, int *prior, int time);
- void stat(char *s, int prior, int time);
- void showQueque();
- void showStat();
- };
- void printer::addQueque(char *s, int *prior, int time) {
- client tail{}, head{};
- auto *tmp = new client;
- strcpy(tmp->position, s);
- tmp->prior = prior;
- tmp->date = time;
- tmp->next = nullptr;
- if (head != nullptr) {
- tmp->prev = tail;
- tail->next = tmp;
- tail = tmp;
- } else {
- tmp->prev = nullptr;
- head = tmp;
- tail = tmp;
- }
- }
- void printer::showQueque() {
- client *tmp = head;
- while (tmp) {
- cout << " Должность : " << tmp->position << endl;
- cout << " Приоритет : " << tmp->prior << endl;
- cout << " Время печати(мин) : " << tmp->date << endl;
- tmp = tmp->next;
- cout << endl;
- }
- }
- void printer::stat(char *s, int prior, int time) {
- auto *tmp = new client;
- client *temp = headStat;
- bool flag = false;
- while (temp) {
- if (strcmp(temp->position, s) == 0) {
- flag = true;
- temp->date += time;
- break;
- }
- temp = temp->next;
- }
- if (!flag) {
- strcpy(tmp->position, s);
- tmp->prior = prior;
- tmp->date = time;
- tmp->next = nullptr;
- if (headStat != nullptr) {
- tmp->prev = tailStat;
- tailStat->next = tmp;
- tailStat = tmp;
- } else {
- tmp->prev = nullptr;
- headStat = tmp;
- tailStat = tmp;
- }
- }
- }
- void printer::showStat() {
- client *tmp = headStat;
- while (tmp) {
- cout << " Должность : " << tmp->position << endl;
- cout << " Время печати(мин) : " << tmp->date << endl;
- tmp = tmp->next;
- cout << endl;
- }
- }
- int main() {
- setlocale(0, "Rus");
- int menu = 0;
- char name[128];
- int prior;
- int date;
- printer ob;
- do {
- system("clear"); // cls
- cout << " 1 - Добавить клиента \n";
- cout << " 2 - Показать всех клиентов \n";
- cout << " 3 - Статистика печати \n";
- cout << " 0 - Выход \n";
- cout << " Ваш выбор : ";
- cin >> menu;
- cin.ignore();
- switch (menu) {
- case 1:
- cout << " Введите должность клиента ( директор, менеджер, охраник) : ";
- cin >> name;
- cout << " Введите приоритет ( 1, 2 ,3) :";
- cin >> prior;
- cout << " Введите время печати ( в минутах ) : ";
- cin >> date;
- ob.addQueque(name, prior, date);
- ob.stat(name, prior, date);
- break;
- case 2:
- system("clear"); // cls
- cout << " Все клиенты: \n";
- ob.showQueque();
- break;
- case 3:
- system("clear"); // cls
- cout << " Статистика: \n";
- ob.showStat();
- break;
- case 0:
- cout << " До свидания ! \n";
- break;
- }
- } while (menu != 0);
- }
Add Comment
Please, Sign In to add comment