Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstring>
- #include <cstdlib>
- #include <iostream>
- struct Car
- {
- char nn[10] = "";
- // Добавить необходимые поля структуры
- int time_all = 0,
- time_in = 0;
- Car() {}
- Car(int time_in, const char *nn)
- {
- this->time_in = time_in;
- strcpy_s(this->nn, nn);
- }
- };
- class DB
- {
- struct Car **data_ptr = nullptr;
- int size = 0,
- capacity = 0;
- public:
- DB()
- {
- data_ptr = new Car*[5];
- capacity = 5;
- }
- // Реализовать методы добавления машинки в массив и поиска.
- void add(int time_in, const char *nn)
- {
- add(new Car(time_in, nn));
- }
- void add(Car *car)
- {
- if (capacity == size)
- {
- data_ptr = (Car**)realloc(data_ptr, (capacity + 5) * sizeof(Car*));
- capacity += 5;
- }
- data_ptr[size++] = car;
- if (size > 1)
- {
- Car *temp;
- int i = size - 2;
- while (i >= 0 && _strcmpi(data_ptr[i]->nn, data_ptr[i + 1]->nn) > 0)
- {
- temp = data_ptr[i];
- data_ptr[i] = data_ptr[i + 1];
- data_ptr[i + 1] = temp;
- --i;
- }
- }
- }
- void printStat()
- {
- std::cout << "DB Size: " << size << " DB Capacity: " << capacity << '\n';
- }
- void printDB()
- {
- for (int i = 0; i < size; ++i)
- {
- std::cout << "NN: " << data_ptr[i]->nn << "\nTime ALL: "
- << data_ptr[i]->time_all << "\nTime IN: " << data_ptr[i]->time_in
- << "\n=================\n";
- }
- }
- };
- struct Command
- {
- int time = 0;
- char car_nn[10];
- char type = '!';
- };
- // 02:31 * hdsgjf
- // 0:0 =
- Command parser(char *str)
- {
- Command test;
- long h, m;
- h = strtol(str, &str, 10);
- if (*str != ':') return test;
- m = strtol(str + 1, &str, 10);
- // Проверка на корректность времени
- ++str;
- if (*str == '=' && h == 0 && m == 0)
- {
- test.type = '=';
- return test;
- }
- if (*str == '*' && *(str + 1) == ' ')
- {
- test.time = h * 60 + m;
- test.type = '*';
- strcpy_s(test.car_nn, str + 2);
- }
- return test;
- }
- void main()
- {
- DB db;
- db.printStat();
- db.add(324, "ssssss");
- db.add(4354, "dddddd");
- db.add(324, "njkdsg4");
- db.add(4354, "abcd1234");
- db.add(324, "xxxxxxxxx");
- db.add(4354, "kkkkkkkk");
- db.printStat();
- db.printDB();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement