Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
mamihk
/
iag0582
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b58c160a
authored
Apr 25, 2017
by
mario mihkelson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
12 nädala töö
parent
b7e31954
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
432 additions
and
0 deletions
progra 2/too.c
too.c
progra 2/too.c
0 → 100644
View file @
b58c160a
#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
l6pptulemus
(
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
);
l6pptulemus
(
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
l6pptulemus
(
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
,
"
\n
20"
);
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
]);
}
}
}
too.c
0 → 100644
View file @
b58c160a
#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
l6pptulemus
(
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
);
l6pptulemus
(
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
l6pptulemus
(
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
,
"
\n
20"
);
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
]);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment