Advertisement
BORUTO-121

studentsAndGrades

Sep 18th, 2021
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.17 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. struct Ocjena {
  5.   char naziv_predmeta[51];
  6.   int ocjena;
  7. };
  8.  
  9. struct Student {
  10.   char ime[21],prezime[21];
  11.   int br_ocjena;
  12.   struct Ocjena ocjene[100];
  13. };
  14.  
  15. int jel_bio_student(struct Student *niz, int vel, struct Student stud){
  16.   int i;
  17.   for(i=0;i<vel;i++)
  18.     if(strcmp(niz[i].ime,stud.ime)==0 && strcmp(niz[i].prezime,stud.prezime)==0 && niz[i].br_ocjena<100){
  19.       strcpy(niz[i].ocjene[niz[i].br_ocjena].naziv_predmeta,stud.ocjene[0].naziv_predmeta);
  20.       niz[i].ocjene[niz[i].br_ocjena].ocjena=stud.ocjene[0].ocjena;
  21.       niz[i].br_ocjena++;
  22.       return 1;
  23.     }
  24.   return 0;
  25. }
  26.  
  27.  
  28. double daj_prosjek_za_predmet(struct Student *niz, int vel, char *predmet){
  29.   int brojac=0,i=0,j;
  30.   double prosjek=0.;
  31.   for(;i<vel;i++){
  32.     for(j=0;j<niz[i].br_ocjena;j++)
  33.       if(strcmp(predmet,niz[i].ocjene[j].naziv_predmeta)==0) brojac++, prosjek+=niz[i].ocjene[i].ocjena;
  34.   }
  35.   return prosjek/brojac;
  36. }
  37.  
  38. ///Ucitavanje ide ok
  39. int ucitaj(struct Student *niz, int vel){
  40.   FILE* ulaz=fopen("input.txt","r");
  41.   if(ulaz==NULL)return 0;
  42.   int i=0;
  43.   while(i<vel && fscanf(ulaz,"%s %s %s %d\n",niz[i].ime,niz[i].prezime,niz[i].ocjene[0].naziv_predmeta,&niz[i].ocjene[0].ocjena)==4){
  44.     //printf("%s %s %s %d\n",niz[i].ime,niz[i].prezime,niz[i].ocjene[0].naziv_predmeta,niz[i].ocjene[0].ocjena);
  45.     if(jel_bio_student(niz,i,niz[i]))continue;
  46.     else {
  47.       niz[i].br_ocjena=1;i++;
  48.     }
  49.   }
  50.   return i;
  51. }
  52.  
  53. void koliko_ima_predemeta(struct Student *niz, int vel){
  54.   int i,j,brojac=0;
  55.   for(i=0;i<vel;i++){
  56.     int bio=0;
  57.     for(j=i+1;j<vel;j++){
  58.       int k;
  59.       for(k=0;k<niz[j].br_ocjena;k++)
  60.         if(strcmp)
  61.     }
  62.   }
  63. }
  64.  
  65. void zapisi(struct Student *niz, int vel){
  66.   FILE* izlaz=fopen("output.txt","w");
  67.   int i,prvi=0,drugi=0;
  68.   ////???? POtrebno ubaciti predmete po alfabetu???, problem poredjenje i pamcenje koja imena su bila
  69.  
  70. }
  71.  
  72. int main(){
  73.   struct Student niz[10];
  74.   int vel=ucitaj(niz,10);
  75.   int i,j;
  76.  for(i=0;i<vel;i++){
  77.     printf("%s %s:",niz[i].ime,niz[i].prezime);
  78.     for(j=0;j<niz[i].br_ocjena;j++)
  79.       printf("%s %d\n",niz[i].ocjene[j].naziv_predmeta,niz[i].ocjene[j].ocjena);
  80.   }
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement