Commit 18f308e8 by trkall

tudengi KKH yl, .txt failid vb corrupted!

parent a861c772
2014S
G.BECKETT - 0.00
P.BOLDEN - 4.00
D.BRIGGS - 0.00
D.COX - 2.67
G.DENT - 5.00
B.ELMORE - 2.50
R.ESPINOSA - 3.94
S.GRAVES - 2.14
S.GRUBBS - 4.00
M.HOOD - 1.50
A.MALLORY - 5.00
M.MERRILL - 4.38
R.MOORE - 4.43
A.RODGERS - 5.00
P.SHIELDS - 4.31
E.THORNTON - 4.50
A.VARNEY - 2.52
K.WHITT - 3.76
C.WILBURN - 3.43
E.YOR - 2.24
2015K
G.BECKETT - 3.52
P.BOLDEN - 2.52
D.BRIGGS - 2.19
D.COX - 2.86
G.DENT - 3.24
B.ELMORE - 2.29
R.ESPINOSA - 4.76
S.GRAVES - 2.10
S.GRUBBS - 3.24
M.HOOD - 2.95
A.MALLORY - 4.24
M.MERRILL - 4.00
R.MOORE - 3.71
A.RODGERS - 4.52
P.SHIELDS - 2.62
E.THORNTON - 4.48
A.VARNEY - 4.29
K.WHITT - 4.76
C.WILBURN - 2.71
E.YOR - 2.62
2015S
G.BECKETT - 4.24
P.BOLDEN - 2.12
D.BRIGGS - 4.20
D.COX - 3.60
G.DENT - 4.00
B.ELMORE - 2.08
R.ESPINOSA - 2.80
S.GRAVES - 3.80
S.GRUBBS - 4.52
M.HOOD - 3.80
A.MALLORY - 3.20
M.MERRILL - 4.16
R.MOORE - 4.32
A.RODGERS - 4.24
P.SHIELDS - 3.84
E.THORNTON - 3.36
A.VARNEY - 2.08
K.WHITT - 3.80
C.WILBURN - 2.88
E.YOR - 2.84
2016K
G.BECKETT - 3.13
P.BOLDEN - 3.92
D.BRIGGS - 4.00
D.COX - 4.33
G.DENT - 3.46
B.ELMORE - 4.79
R.ESPINOSA - 4.88
S.GRAVES - 4.08
S.GRUBBS - 3.46
M.HOOD - 3.08
A.MALLORY - 3.42
M.MERRILL - 4.33
R.MOORE - 2.83
A.RODGERS - 3.25
P.SHIELDS - 2.21
E.THORNTON - 2.42
A.VARNEY - 1.33
K.WHITT - 3.21
C.WILBURN - 4.17
E.YOR - 4.88
149378IASB G.BECKETT
149380IASB P.BOLDEN
149384IASB D.BRIGGS
149385IASB D.COX
149389IASB G.DENT
149395IASB B.ELMORE
149396IASB R.ESPINOSA
149401IASB S.GRAVES
149404IASB S.GRUBBS
149405IASB M.HOOD
149406IASB A.MALLORY
149410IASB M.MERRILL
149411IASB R.MOORE
149417IASB A.RODGERS
149421IASB P.SHIELDS
149425IASB E.THORNTON
149430IASB A.VARNEY
149434IASB K.WHITT
149438IASB C.WILBURN
149439IASB E.YOR
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct
{
char kursus[6];
char kood[11];
char aine[8];
double EAP;
int hinne;
}grades;
typedef struct
{
char kood[11];
char nimi[255];
double KKH[4];
double koguhinne[4];
double koguained[4];
}stud;
void kaalutud(grades *n, stud *m, int, int);
grades *Readgrades(int*, char*);
stud *Readstudents(int*, char*);
void nullimine(stud *m, int);
void arvutus(stud *m, int);
void v2ljastus(stud *m, int);
int main(void)
{
int nrStud;
int nrGrades;
char File1Name[] = {"grades3.txt"};
char File2Name[] = {"stud.txt"};
grades *n=Readgrades(&nrGrades,File1Name);
stud *m=Readstudents(&nrStud,File2Name);
nullimine(m, nrStud);
kaalutud(n, m, nrGrades, nrStud);
arvutus(m, nrStud);
v2ljastus(m, nrStud);
free(n);
free(m);
return 0;
}
void kaalutud(grades *n, stud *m, int nrGrad, int nrStud)
{
int i = 0;
int j = 0;
int k = 0;
int kontroll = 0;
do
{
do
{
for(j=0;j<=nrStud;j++)
{
if(strcmp((n+i)->kood, (m+j)->kood) == 0)
{
(m+j)->koguhinne[k] += (n+i)->hinne * (n+i)->EAP;
(m+j)->koguained[k] += (n+i)->EAP;
nrGrad--;
break;
}
}
kontroll = strcmp((n+i)->kursus, (n+(i+1))->kursus);
i++;
}while(kontroll == 0);
k++;
}while(nrGrad != 0);
}
stud *Readstudents(int *Total, char *FileName)
{
int i=0;
stud buf;
stud *pTemp=NULL;
stud *pArr=NULL;
FILE *fi=fopen(FileName,"r");
if(fi==NULL)
{
exit(1);
}
while(fscanf(fi,"%s%s",buf.kood, buf.nimi)!=EOF)
{
pTemp=(stud*)realloc(pArr,sizeof(stud)*(i+1));
if( pTemp == NULL)
{
printf("Memory Allocation Failed");
fclose(fi);
free(pArr);
exit(1);
}
else
{
pArr=pTemp;
strcpy((pArr + i)-> kood,buf.kood);
strcpy((pArr + i)-> nimi,buf.nimi);
i++;
}
}
fclose(fi);
*Total=i;
return pArr;
}
grades *Readgrades(int *Total, char *FileName)
{
int i=0;
grades buf;
grades *pTemp=NULL;
grades *pArr=NULL;
FILE *fi=fopen(FileName,"r");
if(fi==NULL)
{
exit(1);
}
while(fscanf(fi,"%s%s%s%lf%d",buf.kursus, buf.kood, buf.aine, &buf.EAP, &buf.hinne)!=EOF)
{
pTemp=(grades*)realloc(pArr,sizeof(grades)*(i+1));
if( pTemp == NULL)
{
printf("Memory Allocation Failed");
fclose(fi);
free(pArr);
exit(1);
}
else
{
pArr=pTemp;
(pArr+i)->EAP=buf.EAP;
(pArr+i)->hinne=buf.hinne;
strcpy((pArr + i)-> kursus,buf.kursus);
strcpy((pArr + i)-> kood,buf.kood);
strcpy((pArr + i)-> aine,buf.aine);
i++;
}
}
fclose(fi);
*Total=i;
return pArr;
}
void nullimine(stud *m, int nrStud)
{
int i;
nrStud--;
while(nrStud != -1)
{
for(i = 0;i < 4; i++)
{
(m+nrStud)->KKH[i] = 0;
(m+nrStud)->koguained[i] = 0;
(m+nrStud)->koguhinne[i] = 0;
}
nrStud--;
}
}
void arvutus(stud *m, int nrStud)
{
int i;
int j;
for(i=0;i<nrStud;i++)
{
for(j=0;j<4;j++)
{
(m+i)->KKH[j] = (m+i)->koguhinne[j] / (m+i)->koguained[j];
if((m+i)->koguained[j] == 0)
{
(m+i)->KKH[j] = 0;
}
printf("%.2lf\n", (m+i)->KKH[j]);
}
}
}
void v2ljastus(stud *m, int nrStud)
{
int i;
int j;
int x = 0;
FILE* F = fopen("output.txt", "w");
for(j=0;j<4;j++)
{
fprintf(F, "\n20");
fprintf(F, "%d", 14+x);
if(j%2 == 0)
{
fprintf(F, "S\n\n");
x++;
} else
{
fprintf(F, "K\n\n");
}
for(i=0;i<nrStud;i++)
{
fprintf(F, "%s - %.2lf\n", (m+i)->nimi, (m+i)->KKH[j]);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment