Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct student
  4. {
  5. char imie[20];
  6. char nazwisko[30];
  7. double oceny[6];
  8. int numer;
  9. double srednia;
  10. };
  11. struct student srednia(struct student s);
  12. void dopisz(void);
  13. void drukuj(struct student s);
  14. void drukuj_plik(void);
  15. double maksimum(void);
  16. double minimum(void);
  17. struct student *najlepsi(int *ile);
  18. void popraw(void);
  19. int usun(void);
  20. int main()
  21.  
  22. {
  23. char znak;
  24. while(1)
  25. {
  26. printf("w-dopisz\n");
  27. printf("d-drukuj\n");
  28. printf("m-max sr\n");
  29. printf("z-min sr\n");
  30. printf("n-studenci z najwyzsza srednia\n");
  31. printf("p-popraw\n");
  32. printf("u-usun\n");
  33. printf("g-wyjscie\n");
  34. printf("inny-bledny\n");
  35. printf("Podaj znak\n");
  36. scanf("%c",&znak);
  37. switch (znak){
  38. case'w':dopisz();
  39. case'd':drukuj();
  40. case'm':maxsr();
  41. case'z':minsr();
  42. case'n':najlepsi();
  43. case'p':popraw();
  44. case'u':usun();
  45. case'g':break;
  46. }
  47.  
  48. }
  49. }
  50. void dopisz(void){
  51. struct student s;
  52. FILE *p;
  53. int i;
  54. p=fopen("dane.txt","a");
  55. if(p==NULL){
  56. printf("Blad");
  57. exit(1);
  58. }
  59. printf("imie");
  60. fflush(stdin);
  61. scanf("%19s",s.imie);
  62. printf("nazwisko");
  63. fflush(stdin);
  64. scanf("%29s",s.nazwisko);
  65. printf("oceny");
  66. fflush(stdin);
  67. for(i=0;i<6;i++){
  68. printf("[%d]=",i);
  69. scanf("%lf",s.oceny+i);
  70. }
  71. printf("numer");
  72. fflush(stdin);
  73. scanf("%d",&s.numer);
  74. s=srednia(s);
  75. fwrite(&s,sizeof(struct student),1,p);
  76. fclose(p);
  77.  
  78. }
  79. struct student srednia(struct student s){
  80. int i;
  81. double suma=0;
  82. for(i=0;i<6;i++){
  83. suma+=s.oceny[i];}
  84. s.srednia=suma/6;
  85. return s;
  86. }
  87. void drukuj(struct student s)
  88. {
  89. int i;
  90. printf("Nazwisko:%s\n",s.nazwisko);
  91. printf("Imie:%s\n",s.imie);
  92. printf("oceny: \n");
  93.  
  94. for(i=0;i<6;i++){
  95. printf("[%d]=%g\n",*(s.oceny+i));
  96. }
  97. printf("numer %d\n",s.numer);
  98. printf("srednia %g\n",s.srednia);
  99. }
  100.  
  101. void drukuj_plik(void){
  102. struct student s;
  103. FILE *p;
  104. int i=1;
  105. p=fopen("dane.txt","r");
  106. if(p==NULL){
  107. printf("Blad");
  108. exit(1);
  109. }
  110. while(fread(&s,sizeof(struct student),1,p)==1){
  111. printf("student nr: %d\n",i);
  112. i++;
  113. drukuj(s);}
  114. fclose(p);
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement