Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <windows.h>
- #include "ShellAPI.h"
- using namespace std;
- struct QUEUE //структура очередь
- {
- string info;
- string street;
- string service;
- int timeH, timeM;
- int number;
- QUEUE *next;
- };
- bool Empty(QUEUE *head)
- {
- if (head == NULL)
- return true;
- else
- return false;
- }
- char menu()
- {
- char choice;
- cout << "Menu\n";
- cout << "1. Add to list.\n";
- cout << "2. Remove from the list\n";
- cout << "3. Show list.\n";
- cout << "4. SaveFile.\n";
- cout << "5. ReadFile.\n";
- cout << "6. Exit.\n";
- cin >> choice;
- system("cls");
- return choice;
- }
- void addElement(QUEUE *&head, QUEUE *&last, int number, string info, string street, string service, int timeH, int timeM)
- {
- QUEUE *temp = new QUEUE;
- temp->number = number;
- temp->info = info;
- temp->street = street;
- temp->service = service;
- temp->timeH = timeH;
- temp->timeM = timeM;
- temp->next = NULL;
- head = temp;
- last = temp;
- }
- void insert(QUEUE *&head, QUEUE *&last, int number, string info, string street, string service, int timeH, int timeM)
- {
- if (Empty(head))
- addElement(head, last, number, info, street, service, timeH, timeM);
- else
- {
- QUEUE *temp = new QUEUE;
- temp->number = number;
- temp->info = info;
- temp->street = street;
- temp->service = service;
- temp->timeH = timeH;
- temp->timeM = timeM;
- temp->next = NULL;
- last->next = temp;
- last = temp;
- }
- }
- void remove(QUEUE *&head, QUEUE *&last)
- {
- if (Empty(head))
- cout << "List was already empty.\n";
- else if (head == last)
- {
- delete head;
- head = NULL;
- last = NULL;
- }
- else
- {
- QUEUE *temp = head;
- head = head->next;
- delete temp;
- }
- }
- void showList(QUEUE *current)
- {
- if (Empty(current))
- cout << "List is empty.\n";
- else
- {
- cout << "List contains: \n";
- while (current != NULL)
- {
- cout <<"Coupon №"<< current->number << endl;
- cout << "Name: " << current->info << endl;
- cout << "Service: " << current->service << endl;
- cout << "Address of the terminal: " << current->street << endl;
- cout << "Time: " << current->timeH <<":"<< current->timeM << endl;
- cout << "\n";
- current = current->next;
- }
- }
- }
- void savefile(QUEUE *current)
- {
- ofstream fout("Queue.txt");
- if (Empty(current))
- cout << "File is empty.\n";
- else
- {
- while (current != NULL)
- {
- fout << "Coupon №" << current->number << endl;
- fout << "Name: " << current->info << endl;
- fout << "Service: " << current->service << endl;
- fout << "Address of the terminal: " << current->street << endl;
- fout << "Time: " << current->timeH << ":" << current->timeM << endl;
- fout << "\n";
- current = current->next;
- }
- }
- }
- int count()
- {
- ifstream fin("Queue.txt", ios_base::in);
- int count = 0;
- string s;
- while (!fin.eof())
- {
- getline(fin, s);
- count++;
- }
- return count;
- }
- int readfile (QUEUE *head, QUEUE *last)
- {
- char ch;
- QUEUE *temp = new QUEUE;
- ifstream fin("Queue.txt");
- for (int i = 0; i < count(); i++)
- {
- //temp = new QUEUE;
- fin >> temp->number;
- getline(fin, temp->info);
- fin.ignore();
- getline(fin, temp->street);
- fin.ignore();
- getline(fin, temp->service);
- fin.ignore();
- fin >> temp->timeH;
- fin >> temp->timeM;
- if (Empty(head))
- {
- head = temp;
- last = temp;
- temp -> next = NULL;
- }
- else
- {
- temp->next = NULL;
- last->next = temp;
- last = temp;
- }
- fin.close();
- return 1;
- }
- /*QUEUE *temp = new QUEUE;
- ifstream fin("Queue.txt");
- if (!fin.is_open())
- cout << "file cant open\n";
- else
- {
- while (fin.get(ch))
- cout << ch;
- getline(fin, temp->info);
- fin.ignore();
- getline(fin, temp->street);
- fin.ignore();
- getline(fin, temp->service);
- fin.ignore();
- fin >> temp->timeH;
- fin >> temp->timeM;
- //insert(head, QUEUE *&last, int number, string info, string street, string service, int timeH, int timeM);
- }
- fin.close();
- */
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- QUEUE *current;
- QUEUE *head = NULL;
- QUEUE *last = NULL;
- int choose;
- char choice;
- int number = 0;
- string info;
- string street;
- string service;
- int timeH, timeM;
- do
- {
- choice = menu();
- switch (choice)
- {
- case '1':
- system("cls");
- cout << "Enter the name: ";
- number = number;
- number++;
- street = "Vyazemskaya 12";
- cin.get();
- getline(cin, info);
- system("cls");
- cout << "Select a service:\n1. Card\n2. Payment \n";
- while ((!(cin >> choose)) || (choose < 1) || (choose > 2))
- {
- cin.clear();
- while (cin.get() != '\n')
- continue;
- cout << "Enter the number 1 or 2: ";
- }
- if (choose == 1)
- service = "Card";
- else
- service = "Payment";
- system("cls");
- cout << "Enter the time (hours): ";
- while ((!(cin >> timeH)) || (timeH < 0) || (timeH > 24))
- {
- cin.clear();
- while (cin.get() != '\n')
- continue;
- cout << "Enter the hours 0-24: ";
- }
- system("cls");
- cout << "Enter the time (minutes): ";
- while ((!(cin >> timeM)) || (timeM < 0) || (timeM > 60))
- {
- cin.clear();
- while (cin.get() != '\n')
- continue;
- cout << "Enter the hours 0-60: ";
- }
- system("cls");
- insert(head, last, number, info, street, service, timeH, timeM);
- break;
- case '2': remove(head, last);
- break;
- case '3': showList(head);
- break;
- case '4': savefile(head);
- break;
- case '5': readfile(head, last);
- break;
- case '6': cout << "Exit\n";
- }
- } while (choice != '6');
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement