Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #include <cstring>
  2. #include <cstdlib>
  3. #include <iostream>
  4.  
  5. struct Car
  6. {
  7. char nn[10] = "";
  8. // Добавить необходимые поля структуры
  9. int time_all = 0,
  10. time_in = 0;
  11.  
  12. Car() {}
  13.  
  14. Car(int time_in, const char *nn)
  15. {
  16. this->time_in = time_in;
  17. strcpy_s(this->nn, nn);
  18. }
  19. };
  20.  
  21. class DB
  22. {
  23. struct Car **data_ptr = nullptr;
  24. int size = 0,
  25. capacity = 0;
  26.  
  27. public:
  28. DB()
  29. {
  30. data_ptr = new Car*[5];
  31. capacity = 5;
  32. }
  33. // Реализовать методы добавления машинки в массив и поиска.
  34.  
  35. void add(int time_in, const char *nn)
  36. {
  37. add(new Car(time_in, nn));
  38. }
  39.  
  40. void add(Car *car)
  41. {
  42. if (capacity == size)
  43. {
  44. data_ptr = (Car**)realloc(data_ptr, (capacity + 5) * sizeof(Car*));
  45. capacity += 5;
  46. }
  47. data_ptr[size++] = car;
  48. if (size > 1)
  49. {
  50. Car *temp;
  51. int i = size - 2;
  52. while (i >= 0 && _strcmpi(data_ptr[i]->nn, data_ptr[i + 1]->nn) > 0)
  53. {
  54. temp = data_ptr[i];
  55. data_ptr[i] = data_ptr[i + 1];
  56. data_ptr[i + 1] = temp;
  57. --i;
  58. }
  59. }
  60. }
  61.  
  62. void printStat()
  63. {
  64. std::cout << "DB Size: " << size << " DB Capacity: " << capacity << '\n';
  65. }
  66.  
  67. void printDB()
  68. {
  69. for (int i = 0; i < size; ++i)
  70. {
  71. std::cout << "NN: " << data_ptr[i]->nn << "\nTime ALL: "
  72. << data_ptr[i]->time_all << "\nTime IN: " << data_ptr[i]->time_in
  73. << "\n=================\n";
  74. }
  75. }
  76. };
  77.  
  78. struct Command
  79. {
  80. int time = 0;
  81. char car_nn[10];
  82. char type = '!';
  83. };
  84. // 02:31 * hdsgjf
  85. // 0:0 =
  86. Command parser(char *str)
  87. {
  88. Command test;
  89. long h, m;
  90. h = strtol(str, &str, 10);
  91. if (*str != ':') return test;
  92. m = strtol(str + 1, &str, 10);
  93.  
  94. // Проверка на корректность времени
  95.  
  96. ++str;
  97. if (*str == '=' && h == 0 && m == 0)
  98. {
  99. test.type = '=';
  100. return test;
  101. }
  102. if (*str == '*' && *(str + 1) == ' ')
  103. {
  104. test.time = h * 60 + m;
  105. test.type = '*';
  106. strcpy_s(test.car_nn, str + 2);
  107. }
  108. return test;
  109. }
  110.  
  111. void main()
  112. {
  113. DB db;
  114. db.printStat();
  115. db.add(324, "ssssss");
  116. db.add(4354, "dddddd");
  117. db.add(324, "njkdsg4");
  118. db.add(4354, "abcd1234");
  119. db.add(324, "xxxxxxxxx");
  120. db.add(4354, "kkkkkkkk");
  121. db.printStat();
  122. db.printDB();
  123.  
  124. system("pause");
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement