Guest User

Эл

a guest
May 5th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "stack"
  3. #include <iostream>
  4. #include <cstring>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. struct Process
  10. {
  11. char Name[20];
  12. int start_hour;
  13. int start_minute;
  14. int end_hour;
  15. int end_minute;
  16. int time;
  17. Process [club6386|*Next];
  18. };
  19.  
  20. class Stack {
  21. Process *Head;
  22. stack<Process> s;
  23. public:
  24. void add() {
  25. Process st;
  26. system("cls");
  27.  
  28. cout « "Name: "; cin » st.Name;
  29. cout « "start hour :"; cin » st.start_hour;
  30. cout « "start minute"; cin » st.start_minute;
  31. cout « "end hour"; cin » st.end_hour;
  32. cout « "end minute"; cin » st.end_minute;
  33.  
  34. s.push(st);
  35.  
  36. }
  37.  
  38. void remove(char name[]) {
  39. stack<Process> temp = s;
  40. while (!(temp.empty()))
  41. {
  42. if (strcmp(temp.top().Name, name) == 0)
  43. {
  44. temp.pop();
  45. s = temp;
  46. break;
  47. }
  48. temp.pop();
  49. }
  50. }
  51.  
  52. void sort() {
  53. stack<Process> temp1;
  54. stack<Process> temp2;
  55. stack<Process> temp3;
  56.  
  57. temp1 = s;
  58. temp2 = s;
  59.  
  60. temp1.pop();
  61.  
  62. while (!(temp1.empty())) {
  63. if (strcmp(temp1.top().Name, temp2.top().Name) < 0) {
  64. temp3.push(temp2.top());
  65. }
  66. temp1.pop();
  67. temp2.pop();
  68. }
  69. temp3.push(temp2.top());
  70.  
  71. if (temp3.empty()) {
  72. cout « "No need to sort" « endl;
  73. }
  74. else {
  75. s = temp3;
  76. print_all();
  77. }
  78. }
  79.  
  80. void search(char name[]) {
  81. stack<Process> temp = s;
  82. bool find = false;
  83. while (!(temp.empty())) {
  84. if (strcmp(name, temp.top().Name) == 0) {
  85. cout « temp.top().Name « endl;
  86. find = true;
  87. print_one(temp.top());
  88. }
  89. temp.pop();
  90. }
  91. if (!find) {
  92. cout « "Not found" « endl;
  93. }
  94. }
  95.  
  96. int fileLoad(char* filename) {
  97. ifstream fin(filename);
  98.  
  99. if (fin.is_open()) {
  100. Process *temp;
  101. while (!fin.eof()) {
  102. temp = new Process;
  103.  
  104. fin
  105. » temp->Name
  106. » temp->start_hour
  107. » temp->start_minute
  108. » temp->end_hour
  109. » temp->end_minute;
  110.  
  111. s.push(*temp);
  112. }
  113.  
  114. fin.close();
  115. return 1;
  116. }
  117. else {
  118. cout « "No such file: " « filename « ".\n";
  119. return 0;
  120. }
  121. }
  122.  
  123. int fileWrite(char* filename) {
  124. ofstream fout(filename);
  125.  
  126. if (fout) {
  127. stack<Process> temp;
  128. temp = s;
  129. while (!(temp.empty())) {
  130. fout
  131. « temp.top().Name « "\t"
  132. « temp.top().start_hour « "\t"
  133. « temp.top().start_minute « "\t"
  134. « temp.top().end_hour « "\t"
  135. « temp.top().end_minute « "\n";
  136. temp.pop();
  137. }
  138.  
  139. fout.close();
  140. return 1;
  141. }
  142. else {
  143. cout « "No such file \"" « filename « "\".\n";
  144. return 0;
  145. }
  146. }
  147.  
  148.  
  149.  
  150. void print_all() {
  151. stack<Process> temp;
  152. temp = s;
  153. cout « "Name\t\tStart h\t\tStart min\tEnd h\t\tEnd min\n";
  154.  
  155. while (!(temp.empty())){
  156. cout
  157. « temp.top().Name « "\t\t"
  158. « temp.top().start_hour « "\t\t"
  159. « temp.top().start_minute « "\t\t"
  160. « temp.top().end_hour « "\t\t"
  161. « temp.top().end_minute « "\n";
  162. temp.pop();
  163. }
  164. }
  165.  
  166. void print_one(Process pr) {
  167. cout « "Name\t\tStart h\t\tStart min\tEnd h\t\tEnd min\n";
  168.  
  169. cout
  170. « pr.Name « "\t\t"
  171. « pr.start_hour « "\t\t"
  172. « pr.start_minute « "\t\t"
  173. « pr.end_hour « "\t\t"
  174. « pr.end_minute « "\n";
  175. }
  176.  
  177. void time() {
  178. stack<Process> temp = s;
  179. cout « "Name\t\tTime" « endl;
  180. while (!(temp.empty()))
  181. {
  182. cout
  183. « temp.top().Name « "\t\t"
  184. « (temp.top().end_hour * 60 + temp.top().end_minute) - (temp.top().start_hour * 60 + temp.top().start_minute) « endl;
  185. temp.pop();
  186. }
  187. }
  188. };
  189.  
  190.  
  191. int main()
  192. {
  193. cout.setf(ios::left);
  194. bool flag = true;
  195. int choice;
  196. Process process;
  197. Stack obj;
  198. while (flag)
  199. {
  200. cout.setf(ios::left);
  201. system("cls");
  202. cout « " MENU" « endl;
  203. cout « " " « endl;
  204. cout « "1:Read from the file" « endl;
  205. cout « "2:Show list" « endl;
  206. cout « "3:Add process" « endl;
  207. cout « "4:Save to the file" « endl;
  208. cout « "5:Delete the record" « endl;
  209. cout « "6:Search" « endl;
  210. cout « "7:Sort " « endl;
  211. cout « "8:Time" « endl;
  212. cout « "9:Exit" « endl;
  213. cout « " " « endl « endl;
Advertisement
Add Comment
Please, Sign In to add comment