Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <conio.h>
- #define CURYEAR 2017
- #define CURMONTH 12
- #define CURDAY 18
- #define SIZENAME 30
- #define COUNTOFSUBJECTS 7
- #define COUNTOFSTUDENTS 10
- struct DataBirth {
- int iDay, iMonth, iYear;
- };
- struct Student {
- char cSurname[SIZENAME];
- char cName[SIZENAME];
- struct DataBirth SStudentBirthday;
- int iMarks[COUNTOFSUBJECTS];
- double AverageMark;
- int Age;
- };
- void ReadStudentInfo(FILE* Info, struct Student Group[]) {
- int i = 0, iSum = 0;
- double dbAverage = 0;
- while (!feof(Info)) {
- if ((fscanf(Info, "%s %s %d %d %d", &Group[i].cSurname, &Group[i].cName,
- &Group[i].SStudentBirthday.iDay, &Group[i].SStudentBirthday.iMonth,
- &Group[i].SStudentBirthday.iYear)) > 0) {
- for (int j = 0; j < COUNTOFSUBJECTS; j++) {
- fscanf(Info, "%d", &(Group[i].iMarks[j]));
- iSum += (Group[i].iMarks[j]);
- }
- dbAverage /= COUNTOFSUBJECTS;
- Group[i].AverageMark = dbAverage;
- i++;
- }
- }
- }
- double FindTheAverageAge(struct Student Group[]) {
- int iSum = 0, i;
- double dbAverageAge;
- for (i = 0; i < COUNTOFSTUDENTS; i++) {
- Group[i].Age = CURYEAR - Group[i].SStudentBirthday.iYear;
- if (((Group[i].SStudentBirthday.iMonth > CURMONTH)
- || (Group[i].SStudentBirthday.iMonth == CURMONTH))
- && (Group[i].SStudentBirthday.iDay > CURDAY)) {
- Group[i].Age--;
- }
- i++;
- }
- for (i = 0; i < COUNTOFSTUDENTS; i++) {
- iSum += Group[i].Age;
- }
- dbAverageAge = iSum / COUNTOFSTUDENTS;
- return dbAverageAge;
- }
- void Swap(struct Student Group[], int Pos1, int Pos2) {
- struct Student Temp;
- Temp = Group[Pos1];
- Group[Pos1] = Group[Pos2];
- Group[Pos2] = Temp;
- }
- void SortingByAverageMark(struct Student Group[]) {
- int j;
- for (int i = 1; i < COUNTOFSTUDENTS; i++)
- {
- for (j = i; j >= 0 && Group[j - 1].AverageMark > Group[j].AverageMark; j--)
- {
- Swap(Group, j - 1, j);
- }
- }
- }
- int FindTheCountOfStudentByAvrgAge(struct Student Group[], double dbAverageAge) {
- int i, iCount = 0;
- for (i = 0; i < COUNTOFSTUDENTS; i++) {
- if (Group[i].Age > dbAverageAge) {
- iCount++;
- }
- }
- return iCount;
- }
- void PrintStudent(FILE* Out, struct Student *SB) {
- fprintf(Out, "%10s %10s %2d %2d %4d", SB->cSurname, SB->cName,
- (SB->SStudentBirthday.iDay), (SB->SStudentBirthday.iMonth),
- (SB->SStudentBirthday.iYear));
- for (int i = 0; i < COUNTOFSUBJECTS; i++) {
- fprintf(Out, " %d ", (SB->iMarks[i]));
- }
- fprintf(Out, " %0.1lfn", SB->AverageMark);
- }
- void main(void) {
- struct Student Group[COUNTOFSTUDENTS];
- double dbAverageAge;
- int i, iCount;
- FILE* Info = fopen("studentinfo.txt", "r");
- FILE* Output = fopen("output.txt", "w");
- SortingByAverageMark(Group);
- dbAverageAge = FindTheAverageAge(Group);
- iCount = FindTheCountOfStudentByAvrgAge(Group, dbAverageAge);
- for (i = 0; i < iCount; i++) {
- PrintStudent(Output, Group);
- }
- fclose(Info); //!!!
- fclose(Output);
- }
Add Comment
Please, Sign In to add comment