Guest User

Untitled

a guest
Apr 26th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <conio.h>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. class file
  9. {
  10. public:
  11. char name[64];
  12. char content[256];
  13. int count;
  14. int day, month, year, min, hour;
  15.  
  16. file *next;
  17. };
  18.  
  19. file *add(file *head) //добавление узла в список
  20. {
  21. file *pv = new file;
  22. pv->next = 0;
  23.  
  24. cout << "Name of the file: ";
  25. cin >> pv->name;
  26.  
  27. pv->count = 0;
  28.  
  29. cout << "Input the content of the file: " << endl;;
  30. cin >> pv->content;
  31.  
  32. SYSTEMTIME st;
  33. GetSystemTime(&st);
  34. pv->day = st.wDay;
  35. pv->month = st.wMonth;
  36. pv->year = st.wYear;
  37. pv->hour = st.wHour;
  38. pv->min = st.wMinute;
  39.  
  40. if(head)
  41. {
  42. file *temp = head;
  43. while(temp->next)
  44. temp = temp->next;
  45. temp->next = pv;
  46. }
  47. else
  48. head = pv;
  49. return head;
  50.  
  51. }
  52.  
  53. void print(file *head) //печать списка
  54. {
  55. if(head == 0)
  56. {
  57. system("cls");
  58. cout << "The catalog is empty!";
  59. }
  60. else
  61. {
  62. while(head != 0){
  63. cout << head->name << "t" << "t" << head->day << "." << head->month << "." << head->year << " " << head->hour << ":" << head->min << "t" << "t" << head->count << endl;
  64. head = head->next;
  65. }
  66. }
  67. }
  68.  
  69. void open_cont(file *head) //вывод "внутренностей" файла при вводе имени файла
  70. {
  71. file *ptr = head;
  72. char buff[64];
  73.  
  74. cout << "Input the name of the file: ";
  75. cin >> buff;
  76. bool flag = true;
  77.  
  78. while(head != NULL)
  79. {
  80. if(strstr(ptr->name, buff))
  81. {
  82. system("cls");
  83. ptr->count++;
  84. cout << ptr->content;
  85. flag = false;
  86. }
  87.  
  88. head = head->next;
  89. }
  90. if(flag == true) cout << "No match!";
  91.  
  92. }
  93.  
  94. void clean(file *head) //удаление всего списка
  95. {
  96. if(head != 0)
  97. {
  98. clean(head->next);
  99. delete head;
  100. }
  101. }
  102.  
  103. int main()
  104. {
  105. file *head = 0;
  106.  
  107. char ckey;
  108. do
  109. {
  110. system("cls");
  111. cout << "1 - Open filen";
  112. cout << "2 - Add file to the catalogn";
  113. cout << "3 - Open the catalogn";
  114. cout << "5 - Exitn";
  115.  
  116. ckey = _getch();
  117. system("cls");
  118.  
  119. if(ckey == '1') open_cont(head);
  120.  
  121. else if(ckey == '2') head = add(head);
  122.  
  123. else if(ckey == '3')
  124. {
  125. cout << "Name" << "t" << "t" << "Date" << "t" << "t" << "t" << "Count" << endl;
  126. print(head);
  127. }
  128. else if(ckey == '5')
  129. {
  130. clean(head);
  131. }
  132. else continue;
  133. _getch();
  134.  
  135. } while(ckey != '5');
  136.  
  137. system("pause");
  138. return 0;
  139. }
Add Comment
Please, Sign In to add comment