Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct student
- {
- char imie[20];
- char nazwisko[30];
- double oceny[6];
- int numer;
- double srednia;
- };
- struct student srednia(struct student s);
- void dopisz(void);
- void drukuj(struct student s);
- void drukuj_plik(void);
- double maksimum(void);
- double minimum(void);
- struct student *najlepsi(int *ile);
- void popraw(void);
- int usun(void);
- int main()
- {
- char znak;
- while(1)
- {
- printf("w-dopisz\n");
- printf("d-drukuj\n");
- printf("m-max sr\n");
- printf("z-min sr\n");
- printf("n-studenci z najwyzsza srednia\n");
- printf("p-popraw\n");
- printf("u-usun\n");
- printf("g-wyjscie\n");
- printf("inny-bledny\n");
- printf("Podaj znak\n");
- scanf("%c",&znak);
- switch (znak){
- case'w':dopisz();
- case'd':drukuj();
- case'm':maxsr();
- case'z':minsr();
- case'n':najlepsi();
- case'p':popraw();
- case'u':usun();
- case'g':break;
- }
- }
- }
- void dopisz(void){
- struct student s;
- FILE *p;
- int i;
- p=fopen("dane.txt","a");
- if(p==NULL){
- printf("Blad");
- exit(1);
- }
- printf("imie");
- fflush(stdin);
- scanf("%19s",s.imie);
- printf("nazwisko");
- fflush(stdin);
- scanf("%29s",s.nazwisko);
- printf("oceny");
- fflush(stdin);
- for(i=0;i<6;i++){
- printf("[%d]=",i);
- scanf("%lf",s.oceny+i);
- }
- printf("numer");
- fflush(stdin);
- scanf("%d",&s.numer);
- s=srednia(s);
- fwrite(&s,sizeof(struct student),1,p);
- fclose(p);
- }
- struct student srednia(struct student s){
- int i;
- double suma=0;
- for(i=0;i<6;i++){
- suma+=s.oceny[i];}
- s.srednia=suma/6;
- return s;
- }
- void drukuj(struct student s)
- {
- int i;
- printf("Nazwisko:%s\n",s.nazwisko);
- printf("Imie:%s\n",s.imie);
- printf("oceny: \n");
- for(i=0;i<6;i++){
- printf("[%d]=%g\n",*(s.oceny+i));
- }
- printf("numer %d\n",s.numer);
- printf("srednia %g\n",s.srednia);
- }
- void drukuj_plik(void){
- struct student s;
- FILE *p;
- int i=1;
- p=fopen("dane.txt","r");
- if(p==NULL){
- printf("Blad");
- exit(1);
- }
- while(fread(&s,sizeof(struct student),1,p)==1){
- printf("student nr: %d\n",i);
- i++;
- drukuj(s);}
- fclose(p);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement