Advertisement
Guest User

Untitled

a guest
May 27th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. Листинг программы 1
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #define CLR while (getchar()!='\n')
  6. #define FCLR while (getc(fl)!='\n')
  7.  
  8. struct fion
  9. {
  10. char name[40], surn[40], otch[40];
  11. };
  12.  
  13. struct progress
  14. {
  15. int B[5], srmark;
  16. };
  17.  
  18. struct student
  19. {
  20. fion fio;
  21. char group[40];
  22. progress progr;
  23. student *next;
  24. student *prev;
  25. };
  26.  
  27. void deln(char *s)
  28. {
  29. for (; *s && *s!='\n'; s++);
  30. *s='\0';
  31. }
  32.  
  33. student *AddElem(student *last, FILE *fl)
  34. {
  35. char boo[60];
  36. student *dop;
  37. int sum = 0;
  38.  
  39. dop = new student;
  40. fgets(boo,100,fl);
  41. fgets(dop->fio.surn,100,fl);
  42. deln(dop->fio.surn);
  43. fgets(dop->fio.name,100,fl);
  44. deln(dop->fio.name);
  45. fgets(dop->fio.otch,100,fl);
  46. deln(dop->fio.otch);
  47. fgets(dop->group,100,fl);
  48. deln(dop->group);
  49. for(int i=0; i<5; i++)
  50. {
  51. fscanf(fl,"%d", &dop->progr.B[i]);
  52. sum = sum + dop->progr.B[i];
  53. }
  54. dop->progr.srmark = (int)sum/5;
  55.  
  56. if (!feof(fl))FCLR;
  57.  
  58. if (last==NULL)
  59. {
  60. dop->next = NULL;
  61. dop->prev = NULL;
  62. }
  63. else
  64. {
  65. dop->next = last->next;
  66. dop->prev = last;
  67. last->next = dop;
  68. }
  69. last = dop;
  70. return(last);
  71. }
  72.  
  73. void PrintElem(student *first, char *file)
  74. {
  75. FILE *fl;
  76. int k=1;
  77. fl=fopen(file,"w");
  78. student *dop;
  79. dop = first;
  80. while(dop)
  81. {
  82. fprintf(fl, "\nStudent %d:\n", k++);
  83. fprintf(fl, "FIO: "); fprintf(fl, "%s ", dop->fio.surn); fprintf(fl, "%s ", dop->fio.name); fprintf(fl, "%s\n", dop->fio.otch);
  84. fprintf(fl, "Group: "); fprintf(fl, "%s \n", dop->group);
  85. fprintf(fl, "Marks: ");
  86. for(int i=0;i<5;i++)
  87. fprintf(fl, "%d ", dop->progr.B[i]);
  88. fprintf(fl, "\nAv Mark: "); fprintf(fl, "%d \n", dop->progr.srmark);
  89. dop = dop->next;
  90. }
  91. fclose(fl);
  92. }
  93.  
  94. student *AddList(student *last, int *c, int n)
  95. {
  96. char surn[40];
  97. int sum;
  98. student *curr,*p;
  99. student *dop, *newst=NULL;
  100.  
  101. curr = new student;
  102. curr = last;
  103.  
  104. while(curr)
  105. {
  106. if(curr->progr.srmark>=8)
  107. {
  108. dop = new student;
  109. dop=curr;
  110. if(newst==NULL)
  111. {
  112. dop->next=NULL;
  113. newst=dop;
  114. }
  115. else
  116. {
  117. p->next=dop;
  118. dop->next=NULL;
  119. }
  120. *c=1;
  121. p=dop;
  122. }
  123. curr=curr->prev;
  124. }
  125. return (newst);
  126. }
  127.  
  128. int main()
  129. {
  130. student *catalog = NULL;
  131. student *cat=NULL;
  132. FILE *fl;
  133. int c = 0, n=0, s;
  134.  
  135. if (!(fl=fopen("inp.txt","r")))
  136. {
  137. puts("File not found");
  138. exit(1);
  139. }
  140. fscanf(fl,"%d", &s);
  141. if (!feof(fl))FCLR;
  142. while(!feof(fl) && n!=s)
  143. {
  144. catalog = AddElem(catalog, fl);
  145. n++;
  146. }
  147. fclose(fl);
  148. if(!catalog)
  149. puts("File is empty");
  150. else
  151. {
  152. cat = AddList(catalog, &c, n);
  153. if (c == 0) puts ("No one student with searching surname");
  154. else
  155. PrintElem(cat, "outp.txt");
  156. }
  157. return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement