Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <limits.h>
  7.  
  8. using namespace std;
  9.  
  10. #define CLR while(getchar()!='\n')
  11. #define kmax 10
  12. #define lmax 81
  13. #define FCLR while(getc(fin)!='\n')
  14.  
  15. struct publisher_house
  16. {
  17. int year;
  18. char title[lmax],city[lmax];
  19. };
  20.  
  21. struct book
  22. {
  23. char name[lmax],author[lmax];
  24. int price;
  25. int str;
  26. publisher_house ph;
  27. };
  28.  
  29. void removen(char *s){
  30. for(;*s && *s!='\n';s++);
  31. *s='\0';
  32. }
  33.  
  34. bool enter(int *num, book *b){
  35.  
  36. char filename[20];
  37. FILE *f;
  38.  
  39. printf("Enter the file name\n");
  40. gets(filename);
  41.  
  42. *num = 0;
  43.  
  44. if (!(f=fopen(filename,"r"))){
  45. puts("File not found\n");
  46. return false;
  47. }
  48. else{
  49. while(!feof(f)){
  50. fgets(b->name,100,f); removen(b->name);
  51. if(b->name[0]=='\0') {
  52. printf("File is empty\n");
  53. return false;
  54. }
  55. else{
  56. (*num)++;
  57. fscanf(f,"%d", &b->price);
  58. fscanf(f,"%d", &b->str); CLR;
  59. fgets(b->author, 50, f); removen(b->author);
  60. fscanf(f,"%d", &b->ph.year); CLR;
  61. fgets(b->ph.title, 50, f); removen(b->ph.title);
  62. fgets(b->ph.city, 50, f);
  63. b++;
  64. }
  65. }
  66. }
  67. return true;
  68. }
  69.  
  70.  
  71. void print(int n, book *cm, bool f){
  72.  
  73. printf("\nPublishers, producing the cheapest books of more than 100 pages:\n");
  74.  
  75. for (int i=0;i<n;i++, cm++)
  76. printf("Name of publisher house: %s\n", cm->ph.title);
  77.  
  78. printf("End of list\n");
  79. printf("Press any key to conrinue...\n");
  80. getchar();
  81. }
  82.  
  83.  
  84. int find(int num,book *b, book *cm)
  85. {
  86. int i,j,f,numc;
  87. book *b1=b;
  88. int minstr=100;
  89. int minprice = b->price;
  90. for (i = 0; i < num; i++,b++)
  91. if (b->price < minprice) minprice = b->price;
  92.  
  93. for(i=0;i<num;i++,b++)
  94. {
  95. f=1;
  96.  
  97. if(b->str<minstr||b->price!=minprice) f=0;
  98. if(f==1)
  99. {
  100. *cm = *b1;
  101. numc++;
  102. cm++;
  103. }
  104. }
  105. return numc;
  106.  
  107. }
  108.  
  109. int main()
  110. {
  111. int num, numc;
  112. book b[20], cm[20], *ub = b;
  113.  
  114. if(enter(&num, ub)) {
  115. print(num, b, false);
  116. numc = find(num, ub, cm);
  117. if (numc == 0) printf("Подходящие книги не найдены");
  118. else print(numc, cm, true);
  119. }
  120.  
  121. return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement