0% found this document useful (0 votes)
9 views

Strukt H

The document defines a student struct with fields for name, index number, average grade, extra bonus points, and number of exams passed. It includes functions to load a student, print student details, write a student to a binary file, read from the binary file and print or write details, update a student's grades after passing an exam, search the binary file by index number, and update all students' grades after passing exams.

Uploaded by

Andrea Savic
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Strukt H

The document defines a student struct with fields for name, index number, average grade, extra bonus points, and number of exams passed. It includes functions to load a student, print student details, write a student to a binary file, read from the binary file and print or write details, update a student's grades after passing an exam, search the binary file by index number, and update all students' grades after passing exams.

Uploaded by

Andrea Savic
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#define _CRT_SECURE_NO_WARNINGS

#pragma once
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<time.h>
typedef struct {
char imep[50];
int bri, pi, espb;
float pros;
}student;
student Ucitavanje()
{
student pom;
int godina;
printf("Unesi ime i prezime: ");
if (gets(pom.imep) == NULL)
{
;
}
else {
getchar();
pom.bri = rand() % 900 + 100;
}

printf("\nUnesite godinu koju pohadja student: ");


scanf("%d", &godina);
if (godina != 1)
{
printf("\nUnesite podatke o dosadasnjem ostvarenom uspehu: ");
scanf("%f", &pom.pros);

}
else
pom.pros = 0;

pom.pi = 0;
pom.espb = 0;
return pom;
}

void Ispis(student pom)


{
printf("\nIme i prezime: %s", pom.imep);
printf("\nBroj indeksa: %d", pom.bri);
printf("\nProsek: %f", pom.pros);
printf("\nEspb: %d", pom.espb);
printf("\nPolozeni ispiti: %d", pom.pi);

}
void Ispis2(student pom)
{
FILE* fb = fopen("student.bin", "ab+");

fwrite(&pom, sizeof(pom), 1, fb);

fclose(fb);
}

void IspisUDat()
{
student pom;
FILE* fb = fopen("student.bin", "rb");
FILE* fb2 = fopen("tekst.txt", "w");

while (fread(&pom, sizeof(pom), 1, fb))


{
fprintf(fb2, "\nIme: %s, broj indeksa: %d",pom.imep,pom.bri);
}
fclose(fb);
fclose(fb2);
}
void IspisStand()
{
student pom;
FILE* fb = fopen("student.bin", "rb");

while (fread(&pom, sizeof(pom), 1, fb))


{
fprintf(stdout, "\nIme: %s, broj indeksa: %d", pom.imep, pom.bri);
}
fclose(fb);
}
student AzurIspit(student pom)
{
int ocena;
pom.pi++;
ocena = rand() % 5 + 6;
pom.espb = ocena - 4;
pom.pros = (pom.pros * (pom.pi - 1) + ocena) / pom.pi;
}
void PretragaIndex()
{
student pom;
int indeks;
FILE* fb = fopen("student.bin", "rb");
printf("\nUnesite indeks koji trazite:\n");
scanf("%d", &indeks);

int i, br1, br2=0;


fseek(fb, 0l, SEEK_END);

br1 = ftell(fb) / sizeof(student);


for(i=0;i<br1;i++)
{
fseek(fb, i*sizeof(pom), 0);
fread(&pom, sizeof(pom), 1, fb);
if (indeks == pom.bri)
{
printf("\nIme i prezime: %s", pom.imep);
printf("\nBroj indeksa: %d", pom.bri);
printf("\nProsek: %f", pom.pros);
printf("\nEspb: %d", pom.espb);
printf("\nPolozeni ispiti: %d", pom.pi);
br2++;
}
fseek(fb, i * sizeof(pom), 0);
}
if (br2 == 0)
{
printf("\nNe postoji student sa tim indeksom");
}

fclose(fb);

}
void Azur()
{
student pom;
FILE* fb = fopen("student.bin", "rb+");

int br, i;
fseek(fb, 0l, SEEK_END);
br = ftell(fb) / sizeof(student);
for (i = 0; i < br; i++)
{
fseek(fb, i * sizeof(pom), 0);
fread(&pom, sizeof(pom), 1, fb);
pom = AzurIspit(pom);
fseek(fb, i * sizeof(pom), 0);
fwrite(&pom, sizeof(pom), 1, fb);
}
fclose(fb);
}

You might also like