Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Прочее / Задачи для экзамена по С++ / STR_D(D)
.CPP#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<stdlib.h>
#include<string.h>
#define N 3
struct adress
{ char street[20];
int house,flat;
};
typedef struct
{ char fio[3][20];
struct adress adr;
int year,group;
char sex[2];
} child;
void init(child det[N])
{
for(int i=0;i<N;i++)
{ clrscr();
printf(" ” ¬Ё«Ёп: "); scanf("%s",&det[i].fio[0]);
printf(" €¬п: "); scanf("%s",&det[i].fio[1]);
printf(" ЋвзҐбвў®: "); scanf("%s",&det[i].fio[2]);
printf(" “«Ёж : "); scanf("%s",&det[i].adr.street);
printf(" ь ¤®¬ : "); scanf("%d",&det[i].adr.house);
printf(" Љў авЁа ь: "); scanf("%d",&det[i].adr.flat);
printf(" ‚®§а бв: "); scanf("%d",&det[i].year);
printf(" ь ЈагЇЇл: "); scanf("%d",&det[i].group);
printf(" Џ®«: "); scanf("%s",&det[i].sex);
}
}
int chislo(child det[N])
{
int z=0;
for(int i=0;i<N;i++)
if( (det[i].year>3) && (strcmp(det[i].sex,"¬")==0) && (strcmp(det[i].adr.street,"Џа®бЇҐЄв")==0) )
z++;
return z;
}
child* sort(child det[N],int z)
{
child *ptr;
int k=0;
ptr=(child *)malloc(sizeof(child)*z);
if(ptr==NULL) { printf("Њ «® Ї ¬пвЁ.\n");exit(1); }
for(int i=0;i<N;i++)
if( (det[i].year>3) && (strcmp(det[i].sex,"¬")==0) && (strcmp(det[i].adr.street,"Џа®бЇҐЄв")==0) )
{ strcpy((ptr+k)->fio[0],det[i].fio[0]);
strcpy((ptr+k)->fio[1],det[i].fio[1]);
strcpy((ptr+k)->fio[2],det[i].fio[2]);
(ptr+k)->adr=det[i].adr;
(ptr+k)->year=det[i].year;
(ptr+k)->group=det[i].group;
strcpy((ptr+k)->sex,det[i].sex);
k++;
}
return ptr;
}
void vivod(child *ptr,int z)
{
clrscr(); printf("Ћв‘®авЁа®ў лҐ ¤ҐвЁ:\n\n");
for(int i=0;i<z;i++)
printf("” ¬Ё«Ёп: %s \n",(ptr+i)->fio[0]);
}
main()
{
clrscr();
child * p;
child chel[N];
int num;
init(chel);
num=chislo(chel);
if(num==0) printf("Ќнв ¤нвн© !\n ");
else
{
p=sort(chel,num);
vivod(p,num);
free(p);
}
getch();
}
Соседние файлы в папке Задачи для экзамена по С++