Advertisement
bartek27210

cos

Jan 20th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct student
  5. {
  6.     char nazwisko[30];
  7.     char imie[20];
  8.     int numer;
  9.     double oceny[5];
  10.     double srednia;
  11. };
  12.  
  13. void dopisz(char *nazwa);
  14. struct student srednia(struct student s);
  15. void drukuj(struct student s);
  16. void wydruk(char *nazwa);
  17. double minimum(char*nazwa);
  18. //double maximum(char*nazwa);
  19. //int usun(char*nazwa);
  20. //struct student*najlepsi(char*nazwa); //i
  21. //void popraw(char*nazwa);
  22.  
  23. int main()
  24. {
  25.  
  26.     char nazwa[20];
  27.     printf("Podaj nazwe pliku: ");
  28.     fflush(stdin);
  29.     scanf("%s", nazwa);
  30.     dopisz(nazwa);
  31.  
  32.     wydruk(nazwa);
  33.     double minimum(nazwa);
  34.  
  35. }
  36.  
  37. void dopisz(char*nazwa)
  38. {
  39.     FILE*plik = fopen(nazwa, "a");
  40.     int i = 0;
  41.     struct student s;
  42.     fflush(stdin);
  43.     printf("Podaj nazwisko ");
  44.     scanf("%s", s.nazwisko);
  45.     fflush(stdin);
  46.     printf("Podaj imie ");
  47.     scanf("%s", s.imie);
  48.     fflush(stdin);
  49.     printf("Podaj numer ");
  50.     scanf("%d", &s.numer);
  51.     fflush(stdin);
  52.     for (i = 0; i<5; i++)
  53.     {
  54.         printf("podaj %d ocene ", i);
  55.         scanf("%lf", &s.oceny[i]);
  56.     }
  57.     s = srednia(s);
  58.     fwrite(&s, sizeof(struct student), 1, plik);
  59.     fclose(plik);
  60. }
  61.  
  62. struct student srednia(struct student s)
  63. {
  64.     int i = 0;
  65.     double suma = 0;
  66.     for (i = 0; i<5; i++)
  67.     {
  68.         suma += *(s.oceny + i);
  69.     }
  70.     s.srednia=suma/5;
  71.     return s;
  72. };
  73.  
  74. void drukuj(struct student s)
  75. {
  76.     printf("\nLista");
  77.     printf("\nNazwisko: %s", s.nazwisko);
  78.     printf("\nImie: %s", s.imie);
  79.     printf("\nNumer: %d", s.numer);
  80.     printf("\nSrednia: %lf", s.srednia);
  81. }
  82.  
  83. void wydruk(char *nazwa)
  84. {
  85.  
  86.     FILE*plik;
  87.     struct student s;
  88.     plik = fopen(nazwa,"r");
  89.     while (fread(&s, sizeof(struct student), 1, plik) == 1)
  90.     {
  91.         drukuj(s);
  92.  
  93.     }
  94.  
  95. }
  96.  
  97. double minimum(char *nazwa)
  98. {
  99.     double minsrednia=6;
  100.     FILE*plik;
  101.     struct student s;
  102.     plik = fopen(nazwa,"r");
  103.     while (fread(&s, sizeof(struct student), 1, plik) == 1)
  104.     {
  105.         if(s.srednia<minsrednia) minsrednia=s.srednia;
  106.     }
  107.    printf("\n min sr:%lf",minsrednia);
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement