![]() |
|
|
Регистрация Восстановить пароль |
Регистрация | Задать вопрос |
Заплачу за решение |
Новые сообщения |
Сообщения за день |
Расширенный поиск |
Правила |
Всё прочитано |
![]() |
|
Опции темы | Поиск в этой теме |
![]() |
#1 |
Регистрация: 10.11.2011
Сообщений: 6
|
![]()
Программа управления автопарком:
задание: Составить программу, которая содержит динамическую информацию о наличии автобусов в автобусном парке. Сведения о каждом автобусе включают: □ номер автобуса; □ фамилию и инициалы подателя; □ номер маршрута. Программа должна обеспечивать: □ начальное формирование данных обо всех автобусах в парке в виде списка; □ при выезде каждого автобуса из парка вводится номер автобуса, и программа удаляет данные об этом автобусе из списка автобусов, находящихся в парке, и записывает эти данные в список автобусов, находящихся на маршруте; Листинг: #include <stdio.h> #include <stdlib.h> #include <string.h> #define L_NAME 64 #define IN 0 #define OUT 1 #pragma warning(disable : 4996) //disable error report 4996 (printf) //create bd struct node { int number, /* (0 <-> 13) */ route, /* (0 <-> 3]) */ is_in_park; /* (IN, OUT) */ char driver[ L_NAME ]; char conductor[ L_NAME ]; struct node* next; }; //list add struct node* list_add( struct node **p, const int number, const int route, const char* driver ){ struct node *n = (struct node *)malloc( sizeof(struct node) ); if (n == NULL) { puts( "Can't add new item. Something with memory." ); return NULL; } n->next = *p; /* The previous elm (*p) becomes the "next" element. */ *p = n; /* Add new empty element to the head of the list. */ n->number = number; n->route = route; n->is_in_park = 0; strcpy( n->driver, driver); return *p; } //list and head remove /* Remove head. */ void list_remove(struct node **p) { if (*p != NULL) { struct node *n = *p; *p = (*p)->next; free(n); } } //list search number struct node** list_search_number(struct node **n, const int number) { while (*n != NULL) { if ( (*n)->number == number ) return n; n = &(*n)->next; } return NULL; } //list print void list_print(struct node *n, const int inout) { puts(""); if (n == NULL) printf("List is empty.\n"); while (n != NULL) { if ( inout == IN && n->is_in_park == OUT ); else if ( inout == OUT && n->is_in_park == IN ); else printf( "> n: %i, \tr: %i, \tdr: %s, \ti/o:%i\n", n->number, n->route, n->driver, n->is_in_park ); n = n->next; } } //list change inout void list_inout(struct node *n, const int inout) { int number; struct node *p = n; printf("enter number: "); scanf("%i", &number); if ( list_search_number(&n, number) == NULL ) puts("No such bus."); return; p = *(list_search_number(&n, number)); p->is_in_park = inout; } //menu void help() { puts( "________________________" ); puts( " 1: print list" ); puts( " 2:on the way" ); puts( " 3:in the parking" ); puts( " 4: list_inside" ); puts( " 5: list_outside" ); puts( " 6 : quit !" ); puts( "_________________________" ); } //main int main(void) { char buffer[ L_NAME ]; struct node *n = NULL; int error = 999; /* forsomefirecase. (c)promt*/ list_add( &n, 1, 1, "A. Zhuk" ); list_add( &n, 2, 3, "G. Zopin" ); list_add( &n, 3, 3, "F. Jhonn" ); list_add( &n, 4, 2, "E. Roze" ); puts( "Print 'h' for help." ); /* Main Loop. */ /* while (1) { */ while (error--) { /* forsomefirecase. (c)promt*/ printf( ": " ); scanf( "%s", &buffer ); if ( !strcmp(buffer, "1" ) ) list_print( n, 2 ); else if ( !strcmp(buffer, "2" ) ) list_print( n, OUT ); else if ( !strcmp(buffer, "3" ) ) list_print( n, IN ); else if ( !strcmp(buffer, "4" ) ) list_inout( n, IN ); else if ( !strcmp(buffer, "5" ) ) list_inout( n, OUT ); else if ( !strcmp(buffer, "6" ) ) exit (0); else if ( !strcmp(buffer, "h" ) ) help(); else puts( "No such command. Press'h' for help." ); } return 0; } |
![]() |
![]() |
![]() |
![]() |
||||
Тема | Автор | Раздел | Ответов | Последнее сообщение |
не работает управления окнами. | dell 2011 | Операционные системы общие вопросы | 10 | 14.08.2011 00:15 |
Программа удалённого управления | free6878 | Помощь студентам | 0 | 21.05.2011 17:13 |
Некорректо отображается кирилица и перенос строки (\n) | POPOV | PHP | 7 | 11.11.2010 09:44 |
Программа управления разработками | Kuzya59 | Свободное общение | 0 | 16.03.2010 13:06 |