Home > Back-end >  Rookie help me this program is to compile a C language book, each student information including: stu
Rookie help me this program is to compile a C language book, each student information including: stu

Time:02-13

# include & lt; Stdio. H>
# include & lt; String. H>
# include & lt; Stdlib. H>
Typedef struct
{
Char name [10].
Int num.
Float c;
} stu.
Void menu ()
{
system("cls");//clear screen
Printf (" \ n \ n \ n \ n \ t \ \ t t * * * * * * * * * * * * * * student achievement management system * * * * * * \ n ");
Printf (" \ t \ \ t t Time: June 6, 2020, \ n ");
Printf (" \ t \ \ t t |==========================================| \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 1. Input information * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 2. The query result * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 3. Modify the information * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 4. Add the student * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 5. Delete the result * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 6. Display result * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 7. Statistics * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * 0. Out of * * * * * * * * * * * * * * * | \ n ");
Printf (" \ t \ \ t t |==========================================| \ n ");
Printf (" \ t \ \ t t | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | \ n ");
Printf (" \ n \ n \ t \ \ t t please choose the corresponding function & lt; The input number & gt; : ");
}
//input information
Void input ()
{
The FILE * fp.
Stu xs./* define a structure variable to read out data from file */
If ((fp=fopen (" d: \ \ work \ \ C grade book \ \ C language TXT ", "wb"))==NULL)
{
Printf (" \ nopen file error ");
getchar();
The exit (1);
Printf (" \ n input format: name, student id C \ n ");
Printf (" when input name for end to end entry \ n ");
While (1)
{
The scanf (" % s ", xs. Name);
If (STRCMP (xs. The name, the "end")==0) break;//to determine whether a name for the LAST and judge by string
The scanf (" % d, % f ", & amp; Xs. Num, & amp; Xs. C);
Fwrite (& amp; Xs, sizeof (stu), 1, fp);//will result information written to the file
}
The fclose (fp);
}
//name definition
Void xingming ()
{
The FILE * fp.
Stu xs.
Char name [10].
Printf (" \ n please enter the need to query the student's name: ");
The scanf (" % s ", name);
If (fp=fopen (" student. Dat ", "rb"))==NULL)
{
Printf (" can 't open the file! \n"); The exit (0);
}
while(! Feof (fp))//judgment documents have arrived at the end, when that failed to read file
{
Fread (& amp; Xs, sizeof (stu), 1, fp);
If (STRCMP (xs. The name, the name)==0)//by name query whether the names of the input, will cycle from the data to find take
{
Printf (" student's information is as follows: \ n ");
Printf (" \ n % 10 s % 6 s % 6 s \ n ", "name", "student id", "C");
Printf (" % s % 6 d % 6.2 f \ n ", xs. The name, xs, num, xs. C,);
break;
}
}
If (feof (fp))
Printf (" ERROR, lookup failure!!!!!! "); Students/* no */
The fclose (fp);
}
//student id defined

Void xuehao ()
{
The FILE * fp.
Stu xs.
Int num.
Printf (" \ n student id, please enter the need to query student ");
The scanf (" % d ", & amp; Num);
If ((fp=fopen (" student. Dat ", "rb"))==NULL)
{
Printf (" can 't open the file "); The exit (0);
}
while(! The feof (fp))
{
Fread (& amp; Xs, sizeof (stu), 1, fp);
If (xs. Num==num)/* by student id when the query to determine the existence of input of student number and will cycle from the data to find take */
{
Printf (" student's information is as follows: \ n ");
Printf (" \ n % 10 s % 6 s % 6 s \ n ", "name", "student id", "C");
Printf (" % s % 6 d % 6.2 f \ n ", xs. The name, xs, num, xs. C);
break;
}
}
If (feof (fp))
Printf (" ERROR, lookup failure!!!!!! ");
The fclose (fp);
}
//query

Void the search ()
{
Char ch1;
system("cls");
Printf (" please choose what way query & lt; No. & gt; : \ n ");
Printf (" 1 - & gt; Name, 2 - & gt; Student number: ");
Ch1=getchar ();/* receive characters with */
The switch (ch1)/* */
{
Case '1' : xingming (); break;
Case '2' : xuehao (); break;
}
Getch ();/* the screen stays at the same time, press any key to return */}
//modify: enter the name of the student, look for the students, if find the modify the student achievement information, and displays the results before and after modification;

Void modify1 ()
{

Stu xs.
The FILE * fp.
Char name [10].
Printf (" \ n please input to modify the student's name: ");
The scanf (" % s ", name);
If ((fp=fopen (" student. Dat ", "rb +"))==NULL)
{
Printf (" can 't open the file! \n"); The exit (0);
}
while(! The feof (fp))
{
Fread (& amp; Xs, sizeof (stu), 1, fp);
If (STRCMP (xs. The name, the name)==0)/* determine whether the names of the input to modify existing */
{
Printf (" student information prior to such modification: \ n ");
Printf (" \ n % s % 6 s % 6 s % 6 s % 6 s % 6 s \ n ", "name", "student id", "C");
Printf (" % s % 6 d % 6.2 f % 6.2 f % 6.2 f % 6.2 f \ n ", xs. The name, xs, num, xs. C);
Printf (" please, in turn, enter C: \ n ");
The scanf (" % f % f % f % f ", & amp; Xs. C);
break;
}
}
if(! The feof (fp))
{
Printf (" \ n the modified student information is as follows: \ n ");
Printf (" \ n % 10 s % 6 s % 6 s \ n ", "name", "student id", "C");
Printf (" % s % 6 d % 6.2 f \ n ", xs. The name, xs, num, xs. C);
Fseek (fp, sizeof (stu), 1); Said retreat,//minus 1 file
the current positionFwrite (& amp; Xs, sizeof (stu), 1, fp);//write again, at the same time to change the cover off before
}
The else
Printf (" \ nERROR, the student does not exist, modified failure!! ");
The fclose (fp);
Getch ();
}
//modify: input the student's student id, look for the students, if find the modify the student achievement information, and displays the results before and after modification;

Void modify2 ()
{
Stu xs.
The FILE * fp.
Int num.
Printf (" \ n please input to modify student student number: ");
The scanf (" % d ", & amp; Num);
If ((fp=fopen (" student. Dat ", "rb +"))==NULL)
{
Printf (" can 't open the file! \n"); The exit (0);
}

while(! The feof (fp))
{
Fread (& amp; Xs, sizeof (stu), 1, fp);
If (xs. Num==num)/* determine whether the names of the input to modify existing */
{
Printf (" modify before the student information is as follows: \ n ");
Printf (" \ n % 10 s % 6 s % 6 s \ n ", "name", "student id", "C");
Printf (" % s % 6 d % 6.2 f \ n ", xs. The name, xs, num, xs. C);
Printf (" \ n please please input C ");
The scanf (" % f % f % f % f ", & amp; Xs. C);
break;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull