Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Листинг программы 1
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define CLR while (getchar()!='\n')
- #define FCLR while (getc(fl)!='\n')
- struct fion
- {
- char name[40], surn[40], otch[40];
- };
- struct progress
- {
- int B[5], srmark;
- };
- struct student
- {
- fion fio;
- char group[40];
- progress progr;
- student *next;
- student *prev;
- };
- void deln(char *s)
- {
- for (; *s && *s!='\n'; s++);
- *s='\0';
- }
- student *AddElem(student *last, FILE *fl)
- {
- char boo[60];
- student *dop;
- int sum = 0;
- dop = new student;
- fgets(boo,100,fl);
- fgets(dop->fio.surn,100,fl);
- deln(dop->fio.surn);
- fgets(dop->fio.name,100,fl);
- deln(dop->fio.name);
- fgets(dop->fio.otch,100,fl);
- deln(dop->fio.otch);
- fgets(dop->group,100,fl);
- deln(dop->group);
- for(int i=0; i<5; i++)
- {
- fscanf(fl,"%d", &dop->progr.B[i]);
- sum = sum + dop->progr.B[i];
- }
- dop->progr.srmark = (int)sum/5;
- if (!feof(fl))FCLR;
- if (last==NULL)
- {
- dop->next = NULL;
- dop->prev = NULL;
- }
- else
- {
- dop->next = last->next;
- dop->prev = last;
- last->next = dop;
- }
- last = dop;
- return(last);
- }
- void PrintElem(student *first, char *file)
- {
- FILE *fl;
- int k=1;
- fl=fopen(file,"w");
- student *dop;
- dop = first;
- while(dop)
- {
- fprintf(fl, "\nStudent %d:\n", k++);
- fprintf(fl, "FIO: "); fprintf(fl, "%s ", dop->fio.surn); fprintf(fl, "%s ", dop->fio.name); fprintf(fl, "%s\n", dop->fio.otch);
- fprintf(fl, "Group: "); fprintf(fl, "%s \n", dop->group);
- fprintf(fl, "Marks: ");
- for(int i=0;i<5;i++)
- fprintf(fl, "%d ", dop->progr.B[i]);
- fprintf(fl, "\nAv Mark: "); fprintf(fl, "%d \n", dop->progr.srmark);
- dop = dop->next;
- }
- fclose(fl);
- }
- student *AddList(student *last, int *c, int n)
- {
- char surn[40];
- int sum;
- student *curr,*p;
- student *dop, *newst=NULL;
- curr = new student;
- curr = last;
- while(curr)
- {
- if(curr->progr.srmark>=8)
- {
- dop = new student;
- dop=curr;
- if(newst==NULL)
- {
- dop->next=NULL;
- newst=dop;
- }
- else
- {
- p->next=dop;
- dop->next=NULL;
- }
- *c=1;
- p=dop;
- }
- curr=curr->prev;
- }
- return (newst);
- }
- int main()
- {
- student *catalog = NULL;
- student *cat=NULL;
- FILE *fl;
- int c = 0, n=0, s;
- if (!(fl=fopen("inp.txt","r")))
- {
- puts("File not found");
- exit(1);
- }
- fscanf(fl,"%d", &s);
- if (!feof(fl))FCLR;
- while(!feof(fl) && n!=s)
- {
- catalog = AddElem(catalog, fl);
- n++;
- }
- fclose(fl);
- if(!catalog)
- puts("File is empty");
- else
- {
- cat = AddList(catalog, &c, n);
- if (c == 0) puts ("No one student with searching surname");
- else
- PrintElem(cat, "outp.txt");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement