Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Курсовая 2 семестра по программированию
- Томар Киран
- гр. 4308
- СПБГЭТУ "ЛЭТИ"
- 2015 год
- Список контактов a.k.a записная книжка
- TO DO:
- search, setcursor position
- */
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include <Windows.h>
- #include <time.h>
- using namespace std;
- typedef struct user{
- char*LOGIN;
- char*password;
- user*next;
- }Users;
- typedef struct list{
- user*login;
- char*name;
- char*surname;
- char*phonenumber;
- char*email;
- list*next;
- list*prev;
- }ST;
- ST* File(Users*user);
- ST* DeleteContact(ST*head, int n, Users*user);
- char* GetElement();
- ST* AddNewContact(ST* head, Users*user);
- ST* ClearAll(ST* head);
- ST* Swap(ST* p);
- ST* Sorting1(ST* head);
- ST* Sorting2(ST* head);
- Users* Register();
- char* enterpass();
- Users* UserIdentify();
- Users* scanUser();
- Users* login();
- void NewOutPut(ST*head, int n);
- void PrintContacts(ST*p, int i);
- int CounterOfContacts(ST*head);
- void Greeting(char*str);
- void Search(ST*head);
- int main()
- {
- ::SetConsoleTitle(_T("Adress book contacts v 1.0"));
- system("color 0f");
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- time_t t = time(NULL);
- struct tm *t_m = localtime(&t);
- int CurrentTime = t_m->tm_hour, a = 30, b = 10; // a- горизонталь, b - вертикаль
- COORD x = { 30, 10 };
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleCursorPosition(hConsole, x);
- switch (CurrentTime)
- {
- case 0:case 1:case 2:case 3:case 4: case 5:
- {
- char str[] = "Доброй ночи!";
- Greeting(str);
- break;
- }
- case 6:case 7:case 8:case 9:case 10:case 11:
- {
- char str[] = "Доброе утро!";
- Greeting(str);
- break;
- }
- case 12:case 13:case 14:case 15:case 16:case 17:
- {
- char str[] = "Добрый день!";
- Greeting(str);
- break;
- }
- case 18:case 19:case 20:case 21:case 22:case 23:
- {
- char str[] = "Добрый вечер!";
- Greeting(str);
- break;
- }
- }
- _getch();
- system("cls");
- Users*user = UserIdentify();
- ST*head = File(user);
- head = Sorting1(head);
- int active_record = 1, i, max = 6, flag = 0, sorting = 1;
- char symb;
- do
- {
- i = 1;
- system("cls");
- do
- {
- if (i == active_record)
- {
- SetConsoleTextAttribute(hConsole, (WORD)((1 << 3 | 7)));
- }
- else
- {
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4 | 7)));
- }
- if (i == 1)
- printf("1.Вывести список контактов\n");
- if (i == 2)
- printf("2.Добавить новый контакт\n");
- if (i == 3)
- printf("3.Удалить контакт\n");
- if (i == 4)
- printf("4.Изменить порядок отображения контактов\n");
- if (i == 5)
- printf("5.Поиск контактов\n");
- if (i == 6)
- printf("5.Выход");
- i++;
- } while (i < 7);
- SetConsoleTextAttribute(hConsole, (WORD)(0 << 4 | 7));
- cin.clear();
- cin.sync();
- symb = _getch();
- switch (symb)
- {
- case 13:
- {
- if (active_record == 1)
- {
- system("cls");
- int n = CounterOfContacts(head);
- NewOutPut(head, n);
- break;
- }
- if (active_record == 2)
- {
- system("cls");
- head = AddNewContact(head, user);
- if (sorting == 1)
- head = Sorting1(head);
- else
- head = Sorting2(head);
- system("pause");
- break;
- }
- if (active_record == 3)
- {
- system("cls");
- int n;
- if (head != NULL)
- {
- cout << "Введите порядковый номер контакта, который вы хотите удалить(Если 0, то все): ";
- cin >> n;
- }
- if (n == 0)
- head = ClearAll(head);
- else
- head = DeleteContact(head, n, user);
- if (sorting == 1)
- head = Sorting1(head);
- else
- head = Sorting2(head);
- system("pause");
- break;
- }
- if (active_record == 4)
- {
- int active_record = 1, i, max = 3, flag = 0;
- char symb;
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- do
- {
- i = 1;
- system("cls");
- do
- {
- if (i == active_record)
- SetConsoleTextAttribute(hConsole, (WORD)(1 << 3 | 7));
- else
- SetConsoleTextAttribute(hConsole, (WORD)(0 << 4 | 7));
- if (i == 1)
- cout << "Упорядочить в прямом порядке(от А до Я)\n";
- if (i == 2)
- cout << "Упорядочить в обратном порядке(от Я до А)\n";
- if (i == 3)
- cout << "Назад";
- i++;
- } while (i < 4);
- SetConsoleTextAttribute(hConsole, (WORD)(0 << 4 | 7));
- cin.clear();
- cin.sync();
- symb = _getch();
- switch (symb)
- {
- case 13:
- {
- if (active_record == 1)
- {
- system("cls");
- head = Sorting1(head);
- sorting = 1;
- flag = 1;
- break;
- }
- if (active_record == 2)
- {
- system("cls");
- head = Sorting2(head);
- sorting = 2;
- flag = 1;
- break;
- }
- if (active_record == 3)
- {
- system("cls");
- flag = 1;
- break;
- }
- }
- case -32:
- {
- symb = _getch();
- switch (symb)
- {
- case 80:
- {
- if (active_record != max)
- active_record++;
- else
- active_record = 1;
- break;
- }
- case 72:
- {
- if (active_record != 1)
- active_record--;
- else
- active_record = max;
- break;
- }
- default:
- cout << "\nВыберите нужный пункт меню, используя стрелки вверх, вниз и клавишу Enter";
- Sleep(500);
- break;
- }
- break;
- }
- default:
- cout << "\nВыберите нужный пункт меню, используя стрелки вверх, вниз и клавишу Enter";
- Sleep(500);
- break;
- }
- } while (flag != 1);
- break;
- }
- if (active_record == 5)
- {
- system("cls");
- Search(head);
- break;
- }
- if (active_record == 6)
- {
- system("cls");
- system("color 0f");
- COORD x = { 30, 10 };
- SetConsoleCursorPosition(hConsole, x);
- cout << "Спасибо за работу!\n";
- ClearAll(head);
- _getch();
- return 0;
- }
- }
- //Выход из программы по ESC'ейпу
- //case 27:
- //{
- // flag = 1;
- // return NULL;
- // break;
- //}
- case -32:
- {
- symb = _getch();
- switch (symb)
- {
- case 80:
- {
- if (active_record != max)
- active_record++;
- else
- active_record = 1;
- break;
- }
- case 72:
- {
- if (active_record != 1)
- active_record--;
- else
- active_record = max;
- break;
- }
- default:
- {
- puts("\nВыберите нужный пункт меню, используя стрелки вверх, вниз и клавишу Enter");
- Sleep(500);
- break;
- }
- }
- break;
- }
- default:
- {
- puts("\nВыберите нужный пункт меню, используя стрелки вверх, вниз и клавишу Enter");
- Sleep(500);
- break;
- }
- }
- } while (flag != 1);
- system("pause");
- return 0;
- }
- ST* File(Users*user)
- {
- FILE *file;
- ST*start = NULL;
- char buff[256];
- if (user == NULL)
- {
- file = fopen("Temporary", "w");
- if (file == 0)
- {
- printf("Не могу открыть файл '%s'\n", "Temporary");
- return NULL;
- }
- }
- else
- {
- char fname1[4] = "D:\\";
- char fname3[5] = ".txt";
- char *fname2 = user->LOGIN;
- char *fname = (char*)malloc(sizeof(char));
- strcpy(fname, fname1);
- strcat(fname, fname2);
- strcat(fname, fname3);
- file = fopen(fname, "r");
- if (file == 0)
- {
- printf("Не могу открыть файл '%s'\n", fname);
- return NULL;
- }
- }
- if ((fscanf(file, "%s256", buff) != EOF))
- {
- start = new ST();
- start->surname = (char*)malloc(strlen(buff)*sizeof(char));
- strcpy(start->surname, buff);
- start->next = NULL;
- start->prev = NULL;
- }
- else
- {
- cout << "Ошибка в формировании списка!\n";
- return NULL;
- }
- if ((fscanf(file, "%s256", buff) != EOF))
- {
- start->name = (char*)malloc(strlen(buff)*sizeof(char));
- strcpy(start->name, buff);
- }
- else
- {
- cout << "Ошибка в формировании списка!\n";
- return NULL;
- }
- if ((fscanf(file, "%s256", buff) != EOF))
- {
- start->email = (char*)malloc(strlen(buff)*sizeof(char));
- strcpy(start->email, buff);
- }
- else
- {
- cout << "Ошибка в формировании списка!\n";
- return NULL;
- }
- if ((fscanf(file, "%s256", buff) != EOF))
- {
- start->phonenumber = (char*)malloc(strlen(buff)*sizeof(char));
- strcpy(start->phonenumber, buff);
- }
- else
- {
- cout << "Ошибка в формировании списка!\n";
- return NULL;
- }
- while ((fscanf(file, "%s256", buff) != EOF))
- {
- ST*field = start;
- while (field->next != NULL)
- {
- field = field->next;
- };
- ST*tmp = field;
- field->next = new ST();
- field = field->next;
- field->surname = (char*)malloc(strlen(buff)*sizeof(char));
- strcpy(field->surname, buff);
- field->next = NULL;
- field->prev = tmp;
- if ((fscanf(file, "%s256", buff) != EOF))
- {
- field->name = (char*)malloc(strlen(buff)*sizeof(char));
- strcpy(field->name, buff);
- }
- else
- {
- cout << "Ошибка в формировании списка!\n";
- return NULL;
- }
- if ((fscanf(file, "%s256", buff) != EOF))
- {
- field->email = (char*)malloc(strlen(buff)*sizeof(char));
- strcpy(field->email, buff);
- }
- else
- {
- cout << "Ошибка в формировании списка!\n";
- return NULL;
- }
- if ((fscanf(file, "%s256", buff) != EOF))
- {
- field->phonenumber = (char*)malloc(strlen(buff)*sizeof(char));
- strcpy(field->phonenumber, buff);
- }
- else
- {
- cout << "Ошибка в формировании списка!\n";
- return NULL;
- }
- }
- fclose(file);
- return start;
- }
- ST* DeleteContact(ST* head, int n, Users*user)
- {
- if (head == NULL)
- {
- cout << "Список контактов пуст.\n";
- return head;
- }
- ST*p = head;
- int i = 1;
- while (i != n && p != NULL)
- {
- i++;
- p = p->next;
- }
- if (p == NULL)
- {
- cout << "Нет заданного номера контакта.\n";
- }
- else
- {
- if (i == 1)
- {
- head = p->next;
- free(p);
- cout << "Контакт успешно удален!\n";
- }
- else
- {
- if (p->next == NULL)
- {
- p->prev->next = NULL;
- free(p);
- cout << "Контакт успешно удален!\n";
- }
- else
- {
- p->prev->next = p->next;
- p->next->prev = p->prev;
- free(p);
- cout << "Контакт успешно удален!\n";
- }
- }
- }
- if (head != NULL)
- {
- if (user == NULL)
- {
- user = (Users*)malloc(sizeof(Users));
- user->LOGIN = "Temporary";
- }
- ST*start = NULL;
- FILE *file;
- char fname1[4] = "D:\\";
- char fname3[5] = ".txt";
- char *fname2 = user->LOGIN;
- char *fname = (char*)malloc(sizeof(char));
- strcpy(fname, fname1);
- strcat(fname, fname2);
- strcat(fname, fname3);
- file = fopen(fname, "w+");
- if (file == 0)
- return head;
- p = head;
- do
- {
- fputs(p->surname, file);
- fputs(" ", file);
- fputs(p->name, file);
- fputs(" ", file);
- fputs(p->email, file);
- fputs(" ", file);
- fputs(p->phonenumber, file);
- fputs(" ", file);
- p = p->next;
- } while (p != NULL);
- fclose(file);
- }
- return head;
- }
- char* GetElement()
- {
- int len = 0;
- char c, *str = nullptr;
- do
- {
- str = (char*)realloc(str, (len + 1)*sizeof(char));
- scanf("%c", &c);
- str[len++] = c;
- } while (c != '\n');
- str[len - 1] = '\0';
- return str;
- }
- ST*AddNewContact(ST*head, Users*user)
- {
- if (user == NULL)
- {
- user = (Users*)malloc(sizeof(Users));
- user->LOGIN = "Temporary";
- }
- FILE *file;
- char fname1[4] = "D:\\";
- char fname3[5] = ".txt";
- char *fname2 = user->LOGIN;
- char *fname = (char*)malloc(sizeof(char));
- strcpy(fname, fname1);
- strcat(fname, fname2);
- strcat(fname, fname3);
- file = fopen(fname, "a");
- fputs(" ", file);
- if (file == 0)
- {
- printf("Не могу открыть файл '%s'", fname);
- return head;
- }
- cin.clear();
- cin.sync();
- if (head == NULL)
- {
- head = (ST*)malloc(sizeof(ST));
- cout << "Введите Фамилию контакта: ";
- head->surname = GetElement();
- fputs(head->surname, file);
- fputs(" ", file);
- cout << "Введите Имя контакта: ";
- head->name = GetElement();
- fputs(head->name, file);
- fputs(" ", file);
- cout << "Введите E-mail адрес контакта: ";
- head->email = GetElement();
- fputs(head->email, file);
- fputs(" ", file);
- cout << "Введите Номер телефона контакта: ";
- head->phonenumber = GetElement();
- fputs(head->phonenumber, file);
- fputs(" ", file);
- cout << endl;
- head->next = NULL;
- head->prev = NULL;
- return head;
- }
- ST*p = head;
- while (p->next != NULL)
- p = p->next;
- ST*q = (ST*)malloc(sizeof(ST));
- p->next = q;
- q->next = NULL;
- q->prev = p;
- cout << "Введите Фамилию контакта: ";
- q->surname = GetElement();
- fputs(q->surname, file);
- fputs(" ", file);
- cout << "Введите Имя контакта: ";
- q->name = GetElement();
- fputs(q->name, file);
- fputs(" ", file);
- cout << "Введите E-mail адрес контакта: ";
- q->email = GetElement();
- fputs(q->email, file);
- fputs(" ", file);
- cout << "Введите Номер телефона контакта: ";
- q->phonenumber = GetElement();
- fputs(q->phonenumber, file);
- fputs(" ", file);
- cout << endl;
- fclose(file);
- return head;
- }
- ST* ClearAll(ST*head)
- {
- if (head != NULL)
- {
- ST *tmp = head;
- do
- {
- head = tmp->next;
- free(tmp);
- tmp = head;
- } while (tmp != NULL);
- }
- return NULL;
- }
- ST* Swap(ST*p)
- {
- if (p == NULL || p->next == NULL)
- return p;
- ST*q = p;
- if (p->prev == NULL && p->next->next == NULL)
- {
- p = p->next;
- p->next = q;
- p->prev = NULL;
- q->prev = p;
- q->next = NULL;
- return p;
- }
- if (p->prev == NULL)
- {
- p = p->next;
- p->next->prev = q;
- p->prev = NULL;
- q->next = p->next;
- q->prev = p;
- p->next = q;
- return p;
- }
- if (p->next->next == NULL)
- {
- p = p->next;
- p->next = q;
- p->prev = q->prev;
- q->prev->next = p;
- q->prev = p;
- q->next = NULL;
- return p;
- }
- p = p->next;
- p->next->prev = q;
- q->prev->next = p;
- p->prev = q->prev;
- q->next = p->next;
- p->next = q;
- q->prev = p;
- return p;
- }
- ST* Sorting1(ST*head)
- {
- if (head == NULL || head->next == NULL)
- return head;
- bool flag = 1;
- while (flag == 1)
- {
- ST*p = head;
- flag = 0;
- while (p->next)
- {
- if (strcmp(p->surname, p->next->surname) >0)
- {
- if (p->prev == NULL)
- {
- head = Swap(p);
- p = head;
- }
- else
- {
- p = Swap(p);
- }
- flag = 1;
- }
- else if (strcmp(p->surname, p->next->surname) == 0)
- {
- if (strcmp(p->name, p->next->name) > 0)
- if (p->prev == NULL)
- {
- head = Swap(p);
- p = head;
- }
- else
- {
- p = Swap(p);
- }
- }
- p = p->next;
- }
- }
- return head;
- }
- ST* Sorting2(ST*head)
- {
- if (head == NULL || head->next == NULL)
- return head;
- bool flag = 1;
- while (flag == 1)
- {
- ST*p = head;
- flag = 0;
- while (p->next)
- {
- if (strcmp(p->surname, p->next->surname) < 0)
- {
- if (p->prev == NULL)
- {
- head = Swap(p);
- p = head;
- }
- else
- {
- p = Swap(p);
- }
- flag = 1;
- }
- else if (strcmp(p->surname, p->next->surname) == 0)
- {
- if (strcmp(p->name, p->next->name) < 0)
- if (p->prev == NULL)
- {
- head = Swap(p);
- p = head;
- }
- else
- {
- p = Swap(p);
- }
- }
- p = p->next;
- }
- }
- return head;
- }
- Users* Register()
- {
- Users* start;
- Users* field;
- char*login, *password;
- int check;
- do
- {
- check = 0;
- system("cls");
- fflush(stdin);
- cout << "Регистрация\n";
- cout << "Введите логин: ";
- login = GetElement();
- start = scanUser();
- field = start;
- while (field != NULL)
- {
- if (strcmp(field->LOGIN, login) == 0)
- {
- cout << "\nТакой логин уже существует. Попробуйте другой.\n";
- system("pause");
- check = 1;
- }
- field = field->next;
- }
- } while (check == 1);
- cout << "Введите пароль: ";
- password = GetElement();
- FILE* UsH;
- char*fname = "D:\\userbase.txt";
- UsH = fopen(fname, "a");
- fputs("\n", UsH);
- fputs(login, UsH);
- fputs(" ", UsH);
- fputs(password, UsH);
- fclose(UsH);
- Users*head = scanUser();
- return head;
- }
- char* enterpass()
- {
- char* st = new char[1];
- int len = 0;
- char c = _getch();
- _putch('*');
- while (c != '\r')
- {
- char* tmp = new char[len + 2];
- for (int i = 0; i < len; i++)
- {
- tmp[i] = st[i];
- }
- tmp[len] = c;
- len++;
- delete[] st;
- st = tmp;
- c = _getch();
- _putch('*');
- }
- st[len] = '\0';
- return st;
- }
- //08-backspace
- Users* UserIdentify()
- {
- Users* UserInfo;
- int active_record = 1, i, max, flag = 0;
- char symb;
- max = 3;
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- do
- {
- i = 1;
- system("cls");
- do
- {
- if (i == active_record)
- {
- SetConsoleTextAttribute(hConsole, (WORD)((1 << 3 | 7)));
- }
- else
- {
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4 | 7)));
- }
- if (i == 1)
- printf("1.Войти как зарегистрированный пользователь\n");
- if (i == 2)
- printf("2.Войти без регистрации\n");
- if (i == 3)
- printf("3.Зарегистрироваться\n");
- i++;
- } while (i < 4);
- SetConsoleTextAttribute(hConsole, (WORD)(0 << 4 | 7));
- fflush(stdin);
- symb = _getch();
- switch (symb)
- {
- case 13:
- {
- if (active_record == 1)
- {
- UserInfo = login();
- if (UserInfo != NULL)
- return UserInfo;
- break;
- }
- if (active_record == 2)
- {
- return NULL;
- break;
- }
- if (active_record == 3)
- {
- UserInfo = Register();
- while (UserInfo->next != NULL)
- UserInfo = UserInfo->next;
- return UserInfo;
- break;
- }
- }
- case -32:
- {
- symb = _getch();
- switch (symb)
- {
- case 80:
- {
- if (active_record != max)
- active_record++;
- else
- active_record = 1;
- break;
- }
- case 72:
- {
- if (active_record != 1)
- active_record--;
- else
- active_record = max;
- break;
- }
- default:
- {
- puts("\nВыберете нужный пункт меню, используя стрелки вверх, вниз и клавишу Enter");
- Sleep(500);
- break;
- }
- }
- break;
- }
- default:
- {
- puts("\nВыберете нужный пункт меню, используя стрелки вверх, вниз и клавишу Enter");
- Sleep(500);
- break;
- }
- }
- } while (flag != 1);
- }
- Users* login()
- {
- Users*head = scanUser();
- char*LOGIN;
- char*PASS;
- system("cls");
- cout << "Введите логин: ";
- LOGIN = GetElement();
- cout << endl;
- cout << "Введите пароль: ";
- PASS = enterpass();
- do
- {
- if ((strcmp(LOGIN, head->LOGIN) == 0) && (strcmp(PASS, head->password) == 0))
- return head;
- head = head->next;
- } while (head != NULL);
- return NULL;
- }
- Users* scanUser()
- {
- Users*start = NULL;
- FILE *file;
- char buff[256];
- char *fname = "D:\\userbase.txt";
- file = fopen(fname, "r");
- if (file == 0)
- {
- printf("Не могу открыть файл '%s'\n", fname);
- return NULL;
- }
- if ((fscanf(file, "%s256", buff) != EOF))
- {
- start = new Users();
- start->LOGIN = (char*)malloc(strlen(buff)*sizeof(char));
- strcpy(start->LOGIN, buff);
- start->next = NULL;
- }
- else
- {
- cout << "Ошибка в формировании списка!\n";
- return NULL;
- }
- if ((fscanf(file, "%s256", buff) != EOF))
- {
- start->password = (char*)malloc(strlen(buff)*sizeof(char));
- strcpy(start->password, buff);
- }
- else
- {
- cout << "Ошибка в формировании списка!\n";
- return NULL;
- }
- Users*field = start;
- while ((fscanf(file, "%s256", buff) != EOF))
- {
- while (field->next != NULL)
- {
- field = field->next;
- };
- Users*tmp = field;
- field->next = new Users();
- field = field->next;
- field->LOGIN = (char*)malloc(strlen(buff)*sizeof(char));
- strcpy(field->LOGIN, buff);
- field->next = NULL;
- if ((fscanf(file, "%s256", buff) != EOF))
- {
- field->password = (char*)malloc(strlen(buff)*sizeof(char));
- strcpy(field->password, buff);
- }
- else
- {
- cout << "Ошибка в формировании списка!\n";
- return NULL;
- }
- }
- fclose(file);
- return start;
- }
- void NewOutPut(ST*head, int n)
- {
- if (head == NULL)
- {
- cout << "Список контактов пуст!\n";
- system("pause");
- }
- else
- {
- int active_record = 1, i, flag = 0;
- char symb;
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- ST*p;
- do
- {
- p = head;
- i = 1;
- system("cls");
- for (int i = 1; i < n + 1; i++)
- {
- if (i == active_record)
- {
- SetConsoleTextAttribute(hConsole, (WORD)((1 << 3 | 7)));
- }
- else
- {
- SetConsoleTextAttribute(hConsole, (WORD)((0 << 4 | 7)));
- }
- cout << p->surname;
- cout << " ";
- cout << p->name;
- cout << endl;
- p = p->next;
- }
- SetConsoleTextAttribute(hConsole, (WORD)(0 << 4 | 7));
- fflush(stdin);
- p = head;
- symb = _getch();
- switch (symb)
- {
- case 13:
- {
- for (int x = 1; x < n + 1; x++, p = p->next)
- {
- if (active_record == x)
- {
- system("cls");
- PrintContacts(p,x);
- system("pause");
- }
- }
- break;
- }
- case 27:
- {
- flag = 1;
- break;
- }
- case -32:
- {
- symb = _getch();
- switch (symb)
- {
- case 80:
- {
- if (active_record != n)
- active_record++;
- else
- active_record = 1;
- break;
- }
- case 72:
- {
- if (active_record != 1)
- active_record--;
- else
- active_record = n;
- break;
- }
- default:
- {
- puts("\nВыберете нужный пункт меню, используя стрелки вверх, вниз и клавишу Enter");
- Sleep(500);
- break;
- }
- }
- break;
- }
- default:
- {
- puts("\nВыберете нужный пункт меню, используя стрелки вверх, вниз и клавишу Enter");
- Sleep(500);
- break;
- }
- }
- } while (flag != 1);
- }
- }
- void PrintContacts(ST*p,int i)
- {
- cout << "Контакт #" << i << endl;
- cout << "Фамилия: " << p->surname << endl;
- cout << "Имя: " << p->name << endl;
- cout << "E-mail адрес: " << p->email << endl;
- cout << "Номер телефона: " << p->phonenumber << endl;
- }
- int CounterOfContacts(ST*head)
- {
- int n = 0;
- while (head != NULL)
- {
- n++;
- head = head->next;
- }
- return n;
- }
- void Greeting(char* str)
- {
- int b = 10;
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- for (int a = 0; a < 30; a++)
- {
- system("cls");
- COORD d = { a, b };
- SetConsoleCursorPosition(hConsole, d);
- for (int i = 0, j = strlen(str); i < j; i++)
- {
- cout << str[i];
- }
- Sleep(20);
- }
- }
- void Search(ST*head)
- {
- system("cls");
- if (head == NULL)
- {
- cout << "Список контактов пуст.\n";
- system("pause");
- }
- else
- {
- char C;
- int check = 0;
- do
- {
- ST*p = head;
- int flag = 0, flagi = 1, flagj = 1;
- if (check != 0)
- {
- getchar();
- }
- check = 1;
- system("cls");
- cout << "Введите искомое: ";
- C = _getch();
- cout << C << endl;
- while (p != NULL)
- {
- for (int i = 0, j = 0; i < strlen(p->surname) || j < strlen(p->name); i++, j++)
- {
- if (C == p->surname[i] || C == p->name[j])
- {
- cout << p->surname << " " << p->name << endl;
- flag = 1;
- }
- }
- if (p)
- p = p->next;
- }
- if (flag == 0 && C != 27)
- cout << "Ничего не найдено.\n";
- cout << "_________________\nНажмите Enter для продолжения, Enter->ESC для выхода.\n";
- } while (C != 27);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment