Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 17.12.2011, 06:10   #1
Gadjett
 
Регистрация: 10.11.2011
Сообщений: 6
Сообщение Необходимо разобраться с кодом. Программа управления автобусным парком.

Суть проблемы- Нужно объяснить преподавателю программу языком, максимально приближенным к его пониманию С++
Особое внимание меня просили уделить к ссылкам на указатели, редактированию "БД" и потом уж всему остальному.
Драть вопросами будут жестоко, так что прошу отнестись с пониманием.

Код:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define L_NAME 64
#define IN 0
#define OUT 1
/* ---------------------------- STRUCT NODE ------------------------------ */
struct node {
    int number, /* (0 <-> 13) */
        route, /* (0 <-> 3]) */
        is_in_park; /* (IN, OUT) */
    char driver[ L_NAME ],
        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 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("1 : Show list the Bus in the park"); 
    puts("2 : Show list the Bus in route");
    puts("4 : To send the Bus on the path");
    puts("5 : To send the Bus in park");
    puts("6 : Exit");
}


/* -------------------------------- MAIN --------------------------------- */

int main(void) {
    char buffer[ L_NAME ];
    struct node *n = NULL;
    int number;
    int error = 999; /* forsomefirecase. (c)promt*/
	puts("__________________");
    list_add( &n, 1, 1, "V. Pupkin" );
    list_add( &n, 2, 3, "G. Zopin" );
    list_add( &n, 3, 3, "Mad Max" );
    list_add( &n, 4, 2, "<BB>" );


    puts( "Print 'h' for help." );

    /* Main Loop. */
    /* while (1) { */
    while (error--) { /* forsomefirecase. (c)promt*/
        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. See 'h'." );
    }

    return 0;
}
Gadjett вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Помочь разобраться с кодом Neolit1819 Фриланс 0 06.05.2011 13:55
Разобраться с кодом. Vlero PHP 2 20.01.2011 12:46
Не могу разобраться с кодом jey7 JavaScript, Ajax 1 17.06.2010 09:38
Просьба разобраться с кодом на С++ deazer Помощь студентам 1 08.11.2007 07:55