Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdafx.h>
- #include <iostream>
- #include <fstream>
- #include <string.h>
- #include <stdlib.h>
- #include <iomanip>
- #include <conio.h>
- using namespace std;
- struct TUR
- {
- char NameTur[20];
- char NameCountry[20];
- int Duration;
- int Stand;
- int Thenumberofpermits;
- TUR *Next;
- };
- class List
- {
- TUR *Head;
- public:
- List() :Head(NULL) { };
- ~List();
- void ReadFormFile();
- void Add();
- void Show();
- void LoadToFile();
- void Delete();
- void Sort();
- void Search(); ;
- };
- List::~List()
- {
- while (Head != NULL)
- {
- TUR* temp = Head->Next;
- delete Head;
- Head = temp;
- }
- }
- void List::Add()
- {
- TUR st;
- TUR* temp = new TUR;
- temp->Next = Head;
- system("cls");
- cin.ignore();
- cout << "NameTUR:"; cin.getline(st.NameTur, 20);
- cout << "NameCountry:"; cin.getline(st.NameCountry, 20);
- cout << "Duration:"; cin >> st.Duration;
- cout << "Stand:"; cin >> st.Stand;
- cout << "Thenumberofperm:"; cin >> st.Thenumberofpermits;
- strcpy(temp->NameTur, st.NameTur);
- strcpy(temp->NameCountry, st.NameCountry);
- temp->Duration=st.Duration;
- temp->Stand= st.Stand;
- temp->Thenumberofpermits= st.Thenumberofpermits;
- Head = temp;
- }
- void List::ReadFromFile()
- {
- ifstream fin("TUR.txt");
- Vladelec *temp;
- if (fin.is_open())
- {
- cout << "Файл открыт" << endl;
- while (!fin.eof())
- {
- temp = new Vladelec;
- fin >> temp->NameTUR >> temp->NameCountry>> temp->Duration >> temp->Stand >> temp->Thenumberofperm;
- temp->Next = Head;
- Head = temp;
- }
- cout << "Данные получены" << endl;
- fin.close();
- }
- else cout << "Файл не найден" << endl;
- }
- void List::LoadToFile()
- {
- char file_name[30];
- system("cls");
- cout<<"Input file name: ";
- cin >> file_name;
- ofstream fout(file_name);
- if (fout)
- {
- TUR *temp = Head;
- while (temp != NULL)
- {
- fout<< setw(20) << temp->NameTur << setw(20) <<temp->NameCountry<< setw(10)<< temp->Duration << setw(10) << temp->Stand << setw(10)<< temp->Thenumberofpermits << endl;
- temp = temp->Next;
- }
- cout << "File is completed" << endl;
- system ("pause");
- fout.close();
- }
- else cout << "File is not create";
- }
- void List::Show()
- {
- TUR*temp = Head;
- system("cls");
- cout << setw(20) << "Name" << setw(20) << "NameCountry" << setw(20) << "Duration" << setw(10) << "Stand" << setw(10) << "Thenumberofperm" << endl;
- cout<< "_____________________________________________________" << endl << endl;
- while (temp != NULL)
- {
- cout << setw(20) << temp->NameTur;
- cout << setw(20) << temp->NameCountry;
- cout << setw(20) << temp->Duration;
- cout << setw(10) << temp->Stand;
- cout << setw(10) << temp->Thenumberofpermits << endl;
- temp = temp->Next;
- }
- cout << "_____________________________________________________" << endl << endl;
- }
- void List::Delete()
- {
- {
- TUR* temp = Head->Next;
- delete Head;
- Head = temp;
- }
- }
- void List::Search()
- {
- TUR *temp=Head;
- system("cls");
- char s1[20];
- cout << "Input NameTur:" << endl;
- cin >> s1;
- while (temp != NULL)
- {
- if (!strcmp(temp->NameTur, s1))
- {
- cout << setw(20)<<temp->NameTur;
- cout << setw(20)<<temp->NameCountry;
- cout << setw(20)<<temp->Duration;
- cout << setw(10)<<temp->Stand << endl;
- }
- temp = temp->Next;
- }
- system("pause");
- }
- void List::Sort()
- {
- TUR *temp = Head;
- TUR *temp2;
- TUR *tempShow;
- char swap_NameTur[20];
- char swap_NameCountry[20];
- int swap_Duration;
- int swap_Stand;
- int swap_Thenumberofpermits;
- bool flag = 0;
- while (flag == 0)
- {
- flag = 1;
- while (temp->Next != NULL)
- {
- tempShow = Head;
- temp2 = temp->Next;
- if (temp->Stand > temp2->Stand)
- {
- strcpy_s(swap_NameTur, temp->NameTur);
- strcpy_s(temp->NameTur,temp2->NameTur);
- strcpy_s(temp2->NameTur, swap_NameTur);
- strcpy_s(swap_NameCountry, temp->NameCountry);
- strcpy_s(temp->NameCountry, temp2->NameCountry);
- strcpy_s(temp2->NameCountry, swap_NameCountry);
- strcpy_s(swap_Stand = temp->Stand);
- strcpy_s(temp->Stand = temp2->Stand);
- strcpy_s(temp2->Stand = swap_Stand);
- strcpy_s(swap_Duration = temp->Duration);
- strcpy_s(temp->Duration = temp2->Duration);
- strcpy_s(temp2->Duration = swap_Duration);
- strcpy_s(swap_Thenumberofpermits = temp->Thenumberofpermits);
- strcpy_s(temp->Thenumberofpermits = temp2->Thenumberofpermits);
- strcpy_s(temp2->Thenumberofpermits = swap_Thenumberofpermits);
- flag = 0;
- }
- temp = temp->Next;
- }
- if (temp->Next == NULL)
- temp = Head;
- }
- cout << "Сортировка завершена\n";
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- cout.setf(ios::left);
- bool flag = true;
- int choice;
- List spisok;
- while (flag)
- {
- system("cls");
- cout<< endl << " MENU" << endl;
- cout << "____________________________" << endl << endl;
- cout << "| 1: Read from the file |"<< endl;
- cout << "| 2: Show list |" << endl;
- cout << "| 3: Add |" << endl;
- cout << "| 4: Save to the file |"<< endl;
- cout << "| 5: Delete the record |" << endl;
- cout << "| 6: Sort |" << endl;
- cout << "| 7: Search |" << endl;
- cout << "| 8: Exit |" << endl;
- cout << "____________________________" << endl << endl;
- cout << " Make your choice (1-8): ";
- cin >> choice;
- switch (choice)
- {
- case 1: spisok.ReadFormFile();
- system("PAUSE"); break;
- case 2: spisok.Show(); system("PAUSE"); break;
- case 3: spisok.Add(); break;
- case 4: spisok.LoadToFile(); break;
- case 5: spisok.Delete(); break;
- case 6: spisok.Sort(); break;
- case 7: spisok.Search();break;
- case 8: flag = false; break;
- //default: cout << "You are wrong";
- }
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement