Home > Back-end >  Simple scheduling problems
Simple scheduling problems

Time:09-29

 # include 
#include
# define N 30
Typedef struct student
{
Long id;
Char name [20].
Int score [4];
} STUDENT;
Void the write (STUDENT stu [], int num, int x);
Void the read (STUDENT s [], int num);
Void print (STUDENT s [], int num);
Void px (STUDENT s [], int num);
Void copy (STUDENT s [], int num);
Int main ()
{
STUDENT s [N].
Int n, num=5;
Printf (" 1: create student information file and output; \ n2: sort by student number and output; \ n3: sort by name and output; Increases the \ n4 interchange student information; Data \ n5: to delete a student; \n");
Do {
The scanf (" % d ", & amp; n);
The switch (n)
{
Case 1:
Read (s, num);
Print (s, num);
break;
Case 2:
Px (s, num);
Print (s, num);
break;
}
} while (n!=6);
return 0;
}
Void the write (STUDENT stu [], int num, int x)
{
The FILE * fp.
Int I, j;
If (x=1)
{
If ((fp=fopen (" E: \ \ c language homework winter vacation \ \ student data ", "w"))==NULL)
{
Printf (" error \ n ");
exit(0);
}
}
The else
{
If ((fp=fopen (" E: \ \ c language homework winter vacation \ \ sno data ", "w"))==NULL)
{
Printf (" error \ n ");
exit(0);
}
}
for(i=0; i{
Fprintf (fp, "% 010 ld % 8 s," stu [I] id, stu [I] name);
for(j=0; j<4. J++)
{
Fprintf (fp, "% 4 d," stu [I] score [j]);
}
Fprintf (fp, "\ n");
}
The fclose (fp);
}
Void the read (STUDENT s [], int num)
{
The FILE * fp.
int i,j;
If ((fp=fopen (" E: \ \ c language homework winter vacation \ \ student data ", "r"))==NULL)
{
Printf (" error \ n ");
exit(0);
}
for(i=0; i{
The fscanf (fp, "% ld", & amp; S [I]. Id);
Fscanf (fp, "% s", s [I] name);
for(j=0; j<4. J++)
{
The fscanf (fp, "% d", & amp; S [I] score [j]);
}
}
The fclose (fp);
}
Void print (STUDENT s [], int num)
{
int i,j;
Printf (" student id \ \ t t \ \ t t name mathematics language English \ t \ n \ t grade ");
for(i=0; i{
Printf (" % 010 10 ld % s ", s [I] id, s [I] name);
for(j=0; j<4. J++)
{
Printf (" % d ", s [I] score [j]);
}
printf("\n");
}
}
Void px (STUDENT s [], int num)
{
int i,j,k;
The STUDENT team;
for(i=0; i{
K=I;
For (j=I + 1; j{
If (s [k]. Id> S [j]. Id)
{
K=j;
}
}
If (k!=I)
{
The team [I]=s;
S [j] [I]=s;
S [j]=team;
}
}
Write (s, num, 2);
}

Sort will appear the
  • Related