Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- #include <time.h>
- #include <limits.h>
- using namespace std;
- #define CLR while(getchar()!='\n')
- #define kmax 10
- #define lmax 81
- #define FCLR while(getc(fin)!='\n')
- struct publisher_house
- {
- int year;
- char title[lmax],city[lmax];
- };
- struct book
- {
- char name[lmax],author[lmax];
- int price;
- int str;
- publisher_house ph;
- };
- void removen(char *s){
- for(;*s && *s!='\n';s++);
- *s='\0';
- }
- bool enter(int *num, book *b){
- char filename[20];
- FILE *f;
- printf("Enter the file name\n");
- gets(filename);
- *num = 0;
- if (!(f=fopen(filename,"r"))){
- puts("File not found\n");
- return false;
- }
- else{
- while(!feof(f)){
- fgets(b->name,100,f); removen(b->name);
- if(b->name[0]=='\0') {
- printf("File is empty\n");
- return false;
- }
- else{
- (*num)++;
- fscanf(f,"%d", &b->price);
- fscanf(f,"%d", &b->str); CLR;
- fgets(b->author, 50, f); removen(b->author);
- fscanf(f,"%d", &b->ph.year); CLR;
- fgets(b->ph.title, 50, f); removen(b->ph.title);
- fgets(b->ph.city, 50, f);
- b++;
- }
- }
- }
- return true;
- }
- void print(int n, book *cm, bool f){
- printf("\nPublishers, producing the cheapest books of more than 100 pages:\n");
- for (int i=0;i<n;i++, cm++)
- printf("Name of publisher house: %s\n", cm->ph.title);
- printf("End of list\n");
- printf("Press any key to conrinue...\n");
- getchar();
- }
- int find(int num,book *b, book *cm)
- {
- int i,j,f,numc;
- book *b1=b;
- int minstr=100;
- int minprice = b->price;
- for (i = 0; i < num; i++,b++)
- if (b->price < minprice) minprice = b->price;
- for(i=0;i<num;i++,b++)
- {
- f=1;
- if(b->str<minstr||b->price!=minprice) f=0;
- if(f==1)
- {
- *cm = *b1;
- numc++;
- cm++;
- }
- }
- return numc;
- }
- int main()
- {
- int num, numc;
- book b[20], cm[20], *ub = b;
- if(enter(&num, ub)) {
- print(num, b, false);
- numc = find(num, ub, cm);
- if (numc == 0) printf("Подходящие книги не найдены");
- else print(numc, cm, true);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement