Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.52 KB | None | 0 0
  1. #pragma hdrstop
  2. #pragma argsused
  3.  
  4. #ifdef _WIN32
  5. #include <tchar.h>
  6. #else
  7. typedef char _TCHAR;
  8. #define _tmain main
  9. #endif
  10.  
  11. #include <iostream>
  12. #include <cstring>
  13. #include <conio.h>
  14. using namespace std;
  15.  
  16. class Railway
  17. {
  18. char* destination = new char[15];
  19. char* time = new char[15];
  20. int numberOfFreeTickets;
  21. int ticketPrice;
  22. int profit;
  23. public:
  24. Railway()
  25. {
  26. inputInfo();
  27. }
  28.  
  29. void inputInfo()
  30. {
  31. printf("\nDestination: ");
  32. scanf("%s", destination);
  33. printf("Time: ");
  34. scanf("%s", time);
  35. printf("Number of tickets: ");
  36. scanf("%d", &numberOfFreeTickets);
  37. printf("Ticket price: ");
  38. scanf("%d", &ticketPrice);
  39. profit = numberOfFreeTickets * ticketPrice;
  40. }
  41.  
  42. void outputInfo()
  43. {
  44. printf("%15s|", destination);
  45. printf("%15s|", time);
  46. printf("%10d|", numberOfFreeTickets);
  47. printf("%10d|", ticketPrice);
  48. printf("%10d|", profit);
  49. printf("\n");
  50. }
  51.  
  52. void setDestination(char *destination)
  53. {
  54. delete [] this->destination;
  55. this->destination = destination;
  56. }
  57.  
  58. char* getDestination()
  59. {
  60. return destination;
  61. }
  62.  
  63. void setTime(char *time)
  64. {
  65. delete [] this->time;
  66. this->time = time;
  67. }
  68.  
  69. char* getTime()
  70. {
  71. return time;
  72. }
  73.  
  74. void setNumberOfFreeTickets(int numberOfFreeTickets)
  75. {
  76. this->numberOfFreeTickets = numberOfFreeTickets;
  77. profit = numberOfFreeTickets * ticketPrice;
  78. }
  79.  
  80. int getNumberOfFreeTickets()
  81. {
  82. return numberOfFreeTickets;
  83. }
  84.  
  85. void setTicketPrice(int ticketPrice)
  86. {
  87. this->ticketPrice = ticketPrice;
  88. profit = numberOfFreeTickets * ticketPrice;
  89. }
  90.  
  91. int getTicketPrice()
  92. {
  93. return ticketPrice;
  94. }
  95.  
  96. int getProfit()
  97. {
  98. return profit;
  99. }
  100.  
  101. ~Railway()
  102. {
  103. delete [] destination;
  104. delete [] time;
  105. }
  106. };
  107.  
  108.  
  109. class Admin
  110. {
  111. int count;
  112. Railway** Array;
  113.  
  114. void outputHead()
  115. {
  116. printf(" Destination|");
  117. printf(" Time|");
  118. printf(" Count|");
  119. printf(" Price|");
  120. printf(" Profit|");
  121. printf("\n");
  122. }
  123.  
  124. void outputLine()
  125. {
  126. printf("-----------------------------------------------------------------\n");
  127. }
  128.  
  129. public:
  130.  
  131. Admin()
  132. {
  133. count = 0;
  134. }
  135.  
  136. void inputArray()
  137. {
  138. printf("Input number of tickets: ");
  139. scanf("%d", &count);
  140. Array = new Railway*[count];
  141. for(int i = 0; i < count; i++)
  142. Array[i] = new Railway();
  143. }
  144.  
  145. void outputArray()
  146. {
  147. outputHead();
  148. outputLine();
  149. for(int i = 0; i < count; i++)
  150. {
  151. Array[i]->outputInfo();
  152. outputLine();
  153. }
  154.  
  155. }
  156.  
  157. void addElement()
  158. {
  159. count++;
  160. Railway** temp = new Railway*[count];
  161. for(int i = 0; i < count - 1; i++)
  162. temp[i] = Array[i];
  163. temp[count - 1] = new Railway();
  164. delete [] Array;
  165. Array = temp;
  166. }
  167.  
  168. void findByDestination()
  169. {
  170. char destination[15];
  171. printf("\nDestination: ");
  172. scanf("%s", destination);
  173. outputHead();
  174. outputLine();
  175. for(int i = 0; i < count; i++)
  176. {
  177. if(strcmp(destination, Array[i]->getDestination()) == 0)
  178. {
  179. Array[i]->outputInfo();
  180. outputLine();
  181. }
  182. }
  183. }
  184.  
  185. void deleteElement()
  186. {
  187. int i = 0;
  188. char destination[15];
  189. printf("\nDestination: ");
  190. scanf("%s", destination);
  191. while(i < count)
  192. {
  193. if(strcmp(destination, Array[i]->getDestination()) == 0)
  194. {
  195. for(int j = i + 1; j < count; j++)
  196. Array[j - 1] = Array[j];
  197. count--;
  198. }
  199. i++;
  200. }
  201. }
  202.  
  203. void editElement()
  204. {
  205. char time[15];
  206. char* newTime = new char[15];
  207. printf("\nTime: ");
  208. scanf("%s", time);
  209. printf("\nNew Time: ");
  210. scanf("%s", newTime);
  211. for(int i = 0; i < count; i++)
  212. {
  213. if(strcmp(time, Array[i]->getTime()) == 0)
  214. {
  215. Array[i]->setTime(newTime);
  216. }
  217. }
  218. printf("Well done");
  219. }
  220.  
  221. void sortArray()
  222. {
  223. for (int i = 0; i < count - 1; i++)
  224. {
  225. for (int j = i + 1; j < count; j++)
  226. {
  227. if (strcmp(Array[i]->getTime(), Array[j]->getTime()) < 0)
  228. {
  229. Railway* temp = Array[i];
  230. Array[i] = Array[j];
  231. Array[j] = temp;
  232. }
  233. }
  234. }
  235. printf("Well done");
  236. }
  237.  
  238. void menu()
  239. {
  240. while(true)
  241. {
  242. system("cls");
  243. printf("1.Fill array\n2.Output array\n3.Add element\n4.Find by destination\n5.Delete element\n6.Edit element\n7.Sort array\n8.exit\n");
  244. int choose;
  245. scanf("%d", &choose);
  246. switch(choose)
  247. {
  248. case 1:
  249. {
  250. inputArray();
  251. break;
  252. }
  253. case 2:
  254. {
  255. outputArray();
  256. break;
  257. }
  258. case 3:
  259. {
  260. addElement();
  261. break;
  262. }
  263. case 4:
  264. {
  265. findByDestination();
  266. break;
  267. }
  268. case 5:
  269. {
  270. deleteElement();
  271. break;
  272. }
  273. case 6:
  274. {
  275. editElement();
  276. break;
  277. }
  278. case 7:
  279. {
  280. sortArray();
  281. break;
  282. }
  283. case 8:
  284. {
  285. return;
  286. }
  287. }
  288. getch();
  289. }
  290. }
  291.  
  292. ~Admin()
  293. {
  294. delete [] Array;
  295. }
  296. };
  297.  
  298. int main()
  299. {
  300. Admin a;
  301. a.menu();
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement