Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct student
- {
- char nume[40];
- char sex;
- float nota;
- }STUDENT;
- void citire(FILE *f,STUDENT s[50],int n) //subpunctul a
- {
- int i;
- if((f=fopen("311AC.bin","wb"))==NULL)
- {
- printf("Fisierul nu poate fi deschis.");
- exit(1);
- }
- for(i=0;i<n;i++)
- {
- printf("Numele elevului nr %d este:",i+1);
- fflush(stdin);
- scanf("%s",s[i].nume);
- printf("Sexul elevului este (M/F):");
- fflush(stdin);
- scanf("%c",&s[i].sex);
- printf("Nota elevului este:");
- fflush(stdin);
- scanf("%f",&s[i].nota);
- }
- fwrite(s,sizeof(STUDENT),n,f);
- fclose(f);
- }
- int cautare(char pers[20],STUDENT s[50],int n) //subpunctul b
- {
- int i,ok=0;
- for(i=0;i<n;i++)
- if(strcmp(s[i].nume,pers)==0)
- ok++;
- return ok;
- }
- void nota(STUDENT s[50],int n,int nr_std[2])
- {
- int i;
- float max=0.0;
- for(i=0;i<n;i++)
- if(s[i].nota>max)
- max=s[i].nota;
- int f=0,b=0;
- for(i=0;i<n;i++)
- if(s[i].nota==max)
- if(s[i].sex=='F')
- f++;
- else
- b++;
- nr_std[0]=f;
- nr_std[1]=b;
- }
- int main()
- {
- FILE *f;
- STUDENT s[100];
- int n,i,ok=0,nr_std[2];
- char pers[50];
- printf("Tastati numarul de studenti:");
- scanf("%d",&n);
- citire(f,s,n);
- if((f=fopen("311AC.bin","rb"))==NULL)
- {
- printf("Fisierul nu poate fi deschis.");
- exit(1);
- }
- fread(s,sizeof(STUDENT),n,f);
- printf("Tastati numele elevui cautat:");
- fflush(stdin);
- scanf("%s",pers);
- ok=cautare(pers,s,n);
- if(ok==0)
- printf("Nu exista.\n");
- else
- printf("Exista.\n");
- fclose(f);
- if((f=fopen("311AC.bin","rb"))==NULL)
- {
- printf("Fisierul nu poate fi deschis.");
- exit(1);
- }
- fread(s,sizeof(STUDENT),n,f);
- nota(s,n,nr_std);
- printf("Numarul de fete care au obtinut nota maxima este %d, iar nr de baieti care au obtinut nota maxima este %d.",nr_std[0],nr_std[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement