Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////
- // _________________________________________________ //
- // //
- // Лабораторная работа №4.1 //
- // _________________________________________________ //
- // //
- ///////////////////////////////////////////////////////
- #include<stdlib.h>
- #include <string.h>
- #include<iostream>
- #include<cstring>
- #include <stdio.h>
- #define lmax 200
- //пропуск символов до конца строки
- #define CLR while (getchar()!='\n')
- ///// Структура /////
- struct publishers
- {
- char name[50], city[30];
- int year;
- };
- struct book
- {
- char author[20], title[60], nazv[100];
- int price, pages;
- publishers cat2;
- };
- ///// Ввод структуры /////
- void read_cat(int *kol, book cat[])
- { char ch, year[81], price[81], pages[81];;
- *kol=0;
- do
- { printf("Книга # %d\n", ++(*kol));
- do
- {
- printf("Автор..................."); gets(cat->author);
- } while ( strcmp(cat->author, "")==0);
- do
- {
- printf("Название книги ........."); gets(cat->nazv);
- } while ( strcmp(cat->nazv, "")==0);
- do
- {
- printf("Название издательства..."); gets(cat->cat2.name);
- } while ( strcmp(cat->cat2.name, "")==0);
- do
- {
- printf("Город..................."); gets(cat->cat2.city);
- } while ( strcmp(cat->cat2.city, "")==0);
- do
- {
- printf("Год издания............."); scanf("%s", &year); cat->cat2.year=atoi(year);
- } while(atoi(year)==NULL || atoi(year)<1800 || atoi(year)>2017);
- do
- {
- printf("Цена...................."); scanf("%s", &price); cat->price=atoi(price);
- } while(atoi(price)==NULL || atoi(price)<0);
- do
- {
- printf("Количество страниц......"); scanf("%s", &pages); cat->pages=atoi(pages);
- } while(atoi(pages)==NULL || atoi(pages)<0);
- CLR;
- printf("Продолжить? (y/n) ");
- ch=getchar();
- CLR;
- cat++;
- }
- while ((ch=='Y' || ch=='y')&&*kol<lmax);
- printf("\n");
- }
- ///// Функция поиска нужных книг /////
- void find_f(book cat[], book pod[],int kol, int *cheak)
- {
- int i, S, X;
- book *min=cat;
- S=0;
- *cheak = 0;
- for (i=1; i<=kol; i++, min++)
- {
- S = S + min->pages;
- }
- X=S/kol;
- printf("Среднее арифметическое: %d\n",X);
- min = cat;
- for (i=0; i<kol; i++)
- {
- if ( X > min->pages)
- {
- strcpy(min->nazv, cat[i].nazv);
- *cheak++;
- }
- else strcpy(min->nazv, pod[i].nazv);
- min++;
- }
- }
- ///// Вывод нужных книг /////
- void write_find_f(book cat[], int kol)
- {
- int i;
- char s[1]="";
- printf("Подходящие книги:\n");
- for (i=0; i<kol; i++)
- {
- if ( strcmp(cat[i].nazv, s) == 0)
- {
- i++;
- }
- else
- {
- printf("Книга: %s\n", cat[i].nazv);
- }
- }
- }
- ///// Основная часть /////
- int main()
- {
- int kol, count; book cat[lmax], pod[lmax],*min,*puck, cheak;
- printf("\n");
- printf("_____Лаборатораня работа №4_____\n");
- printf("\n");
- read_cat(&kol, cat);
- find_f(cat, pod, kol, &cheak);
- printf("\n");
- if (kol==1) printf("Всего одна книга!\n");
- else
- write_find_f(cat, kol);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment