Необходимо написать программу, которая позволит ввести с клавиатуры данные о поездах. Также в программе должен быть предусмотрен поиск по пункту назначения поезда. Какая программа выполняет поставленную задачу?
(Отметьте один правильный вариант ответа.)
Варианты ответа
int main (void){ struct train { char *nazn; int numb; char *time; } tr[3]; int i = 0, sum = 0, ch=0; char str[10], search[10]; while(ch!=121) { printf("\nEnter information about train (Q - quit): \n"); printf("Enter destination of the train: "); gets(tr[i].nazn); printf("Enter number of the train: "); gets(str); tr[i].numb = atoi(str); printf("Enter time of scheduled departure: "); gets(tr[i].time); ++i; printf("Quit? (y/n): "); ch = _getche(); }; printf("\n\nEnter train destination: "); gets(search); for (i=0; i<3; i++) { if (strcmp(tr[i].nazn,search)==0) { printf("\n\tTrain number: %d", tr[i].numb); printf("\n\tTime: %s", tr[i].time); } } if (i>=3) printf("There is no train to this destination"); return 0; }
int main (void){ struct train { char nazn[40]; int numb; char time[10]; } tr[3]; int i = 0, sum = 0, ch=0; char str[10], search[10]; while(ch!=121) { printf("\nEnter information about train (Q - quit): \n"); printf("Enter destination of the train: "); gets(tr[i]->nazn); printf("Enter number of the train: "); gets(str); tr[i]->numb = atoi(str); printf("Enter time of scheduled departure: "); gets(tr[i]->time); ++i; printf("Quit? (y/n): "); ch = _getche(); }; printf("\n\nEnter train destination: "); gets(search); for (i=0; i<3; i++) { if (strcmp(tr[i]->nazn,search)==0) { printf("\n\tTrain number: %d", tr[i]->numb); printf("\n\tTime: %s", tr[i]->time); } } if (i>=3) printf("There is no train to this destination"); return 0; }
int main (void){ struct train { char nazn[40]; int numb; char time[10]; } tr[3]; int i = 0, sum = 0, ch=0; char str[10], search[10]; while(ch!=121) { printf("\nEnter information about train (Q - quit): \n"); printf("Enter destination of the train: "); gets(tr[i].nazn); printf("Enter number of the train: "); gets(str); tr[i].numb = atoi(str); printf("Enter time of scheduled departure: "); gets(tr[i].time); ++i; printf("Quit? (y/n): "); ch = _getche(); }; printf("\n\nEnter train destination: "); gets(search); for (i=0; i<3; i++) { if (strcmp(tr[i].nazn,search)==0) { printf("\n\tTrain number: %d", tr[i].numb); printf("\n\tTime: %s", tr[i].time); } } if (i>=3) printf("There is no train to this destination"); return 0; } (Верный ответ)