Current location - Education and Training Encyclopedia - Graduation thesis - Yang c language paper
Yang c language paper
#

include

include

Integer N = 2;; //Global variable. The number of students entered will change its value by itself.

Structural students

{

Number of characters [10];

Role name [10];

Floating score [3]{

System ("CLS");

Printf ("Please exit directly, enter enter, save the input and exit data, and enter the main menu 22 times \ nIt is recommended to exit the amount saved before, otherwise the data will be lost");

Scanf function ("%d",&y);

(== 1)

Exit (0);

Otherwise, if (Y == 2)

Save (stu);

other

();

}

} & lt//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

INT I,J,M,A,Y;

System (* * *

CLS”);

Of printf ("Please enter the number of records added: \ nm =");

Scanf of ("%d", &m)

For (i = n, I am n+m; + +)

{

System ("CLS");

Printf's ("Please enter new classmate with student ID #% d:+1);

Scanf's (""T [I]. NUM);

is(J = 0; ; J + +)

(STRCMP(T [] min, T[J]min)= = 0)// Avoid duplicate student numbers.

{

-

Printf's ("The student of this student already exists, please re-enter:).

Sleep (3000);

Breakthrough;

}

}

When (i = n, I

{

(《CLS》);

Printf's ("Please enter the number of students in% s to increase schools: (separated by spaces) \ Third name, first grade, second grade \ n", t [] num);

//T [i][0]= 0, the score of T[I]. With [ 1] = 0,T [i]。 score[2]= 0;

Scanf function ("%s% f% f% f, T [I]). Name, &t [i]. Score [0], score &t [I] [1], score & t [I] [2]);

Avg.score [0]+t [I] score [1]+[I] [2 points])/3.0;

}

N = N+m// The number of students is equal to the number of students who have already been born, plus the newly added ones.

Printf's ("* * * * * * * * * * * * * * * * * * * * * * * * * * \ n"); & lt/Output ("Add ",enter a carriage return, \ n");

Printf ("Return to the main menu, enter 2, and enter \ n");

("of printf exits the program and enters any carriage return \ n");

Printf's ("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n");

(%d scanf,&a;;

(= = 1)/& gt; add(STU);

Otherwise, if (== 2)

();

other

{

System ("CLS"); ....../& gt; Printf ("Do you want to quit? After entering, enter the car at Exit 2, save the data, and enter the main menu 22 times \ nI I suggest you save some before exiting, otherwise the data will be lost ");

If scanf's ("%d ",&y) (y = = 1)

Exit (0);

Otherwise, if (Y == 2)

Save (stu);

other

Mainly ();

}

}

/ ************ ************************************************** ******************************** /

Integer save(student t[])// file to save data.

{

FILE * FP

CHar [20],ch;

I am a, y;

System ("CLS");

Printf ("Please save to a new file and enter \ nSave the existing file and enter 2 \ n");

Scanf about ("%d", &a)

CH = getchar function()// Receive carriage return, otherwise you will get an error that () function space is allocated.

If (a == 1)

{

Output ("Please enter a new file name: \ n (including extension, no more than 20 characters in length) \ n");

Obtain;

((fopen of FP (s = (s, "w+") = = null)//the file pointed by FP.

{

printf(" this file \ n ");

Exit (0);

}

}

Otherwise, if (== 2)

{

Printf ("Please enter an existing file name: \ N (including extension, no more than 20 characters) \ n");

Obtain;

((FP = FOPEN(" w+")= = NULL)

{

System (CLS”);;

printf(" Please \ n "; };

Exit (0);

}

}

A file written in fprintf(FP) instead of file "%%d \ N", N)//

Yes (I = 0;; I++)

(T [I] of strlen. NUM)! = 0)// If the number of students is not empty, write the data to the specified file.

{

fprintf(FP," % S \ T % S \ T %-5.2f \ T % 5.2f \ T % 5.2f \ T % 5.2f ",

T [I]. number, T []. , T [] [0], T [i] score [1], T [i] score [2], T [i] average);

fprintf(FP," \ n ");

}

other

;

FCLOSE(FP);

System ("CLS"; );

Printf ("Please \ nSave it and you're done! \ n ");

}

/ * ************************************************** ******************************************* /

Invalid reading (student t[])// Reading file data.

{

FILE * FP

Explain y, m, I, x;

CHar [20],ch;

CH = getchar function()// receives the input character, otherwise, the () function space is allocated to s.error..

System ("CLS");

Printf ("Please enter the file name of the read data: \ n (including the extension, within 20 characters) \ n");

Obtain;

((FP = FOPEN ("R"))== NULL)

{

System ("CLS");

printf(" Please this file \ n ");

Sleep (3000)

System ("CLS");

Printf ("Please exit? Exit and enter a carriage return to save the data entered in Exit 2, and enter 22 to return to the main menu \ nI I suggest you save the numbers before exiting, otherwise the data will be lost ");

("%d",&y; of scanf;

(Y == 1)

Exit (0);

Otherwise, if (Y == 2)

Save (

other

();

}

Fscanf(FP," %d ",& x); //Number of students enrolled

(Stu); I = 0; I x, i++)// Read all data.

The name of Fscanf(FP% f% f% f% f of% s% s, T [I] min, T [I], &t [i]. Score [0],

The score is &t [I] [1], &t [I]. Score [2], &t [I]. Average);

FCLOSE(FP);

System ("CLS");

N-= N//n will be set to 0.

n = X;

Printf ("\ nReading completed! \ n ");

}

/ ******** ************************************************** ************************************ /

Menu()// Select menu BR/& gt;; {

Interpret x;

Printf ("Please select the corresponding menu: \ n");

Printf's ("* * * * * * * * * * * * * * * * * * * * * * * * * * \ n");

Of printf ("Please enter a new record, enter 0 and enter \ n");

& gtPrintf ("All students, please enter \ n");

Printf ("Please query the corresponding record, enter 2, enter \ n");

Printf ("Please delete the corresponding record, enter 3, and then enter \ n");

("of printf adds a new record, enter 4 input \ n");

Of Printf ("Record read from file, enter 5, enter \ n");

Printf ("Please average the output from highest to lowest, Input6Input \ n");

Printf ("student number from low to high, and output, input 7 input \ n");

& gt output (the course with the highest score in each course, enter a carriage return \ n ");

("the score of printf is saved to the text input 9 input \ n");

("of printf exits the program, enter 1 1, enter \ n");

printf(" please * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");

("%d" and x) of Scanf;

Returns x;

}

/ ***** ************************************************** *************************************** /

Invalid to_exit()//exit.

{

Interpretation;

System ("CLS");

Printf ("Please exit directly, enter and save the data, exit input 2 and enter the main menu 22 times \ nI suggest you save the number before exiting, otherwise you will lose the data");

("%d",&y; of scanf;

(Y == 1)

Exit (0);

Others (Y == 2)

Save (stu);

other

(); ....../& gt; }

/ ****************************************** ************************************************** * /

Avg _ arrange(student t[])// The average high-to-low sort is invalid.

{

I,J;

Structural student temperature [1]; BR/>; (I = 0; I<n-1; i + +)

(J = I + 1,J & ltn,J + +)

(T [I].AVG <T [J]. Average)

{

TEMP[0]= T[];

T[]= T[J];

Tons [J]. = TEMP[0];

}

List (stu);

}

/ ******************** ************************************************** ************************ /

Invalid num _ arrange(student t[])// The order of the number of students from small to large.

& gt{

Unscramble ij;

Structural student temperature [1];

Yes (I = 0;; I & ltn;; I++)

(J = 0,J & ltN- 1,J + +)

(STRCMP(T [J]). No.,T [j+1]. NUM)>0)

{

Temperature [0] = T [J].

T[J]= T[J+ 1];

= temp [0] in t [j+1];

}

List (t);

}

/ **************************************** ************************************************** **** /

Invalid high (student t[])// the highest score of the search subject.

{

INT I,J,K,

Maximum structure [1];

Maximum value [0] = t [0];

System ("CLS");

Printf ("Please enter the subject you are looking for: 1 or 2 or 3 \ n");

Scanf function (&k of'% d');

(I = 1; I

Maximum value [0] = [0]. Score [k-1] > T [i] [k- 1] has the largest score [0]: [I]

System ("CLS");

Output ("Divide the subjects of% d into:% %5.2f, the number of students is \ n", the highest score of k [0] is [k- 1], and the highest score is [0] num);

}

/ ********************************************* ************************************************* /

()

{

Explained;

( 1)

{

A menu ();

Switch(A)// Select the menu according to the corresponding action.

{

In this example, it is 0: input (stu); Breakthrough;

Case 1: list (stu); Breakthrough;

Case study (STU); Breakthrough;

Case 3: Del (Stu); Breakthrough;

Situation 4: Add (Stu); Breakthrough;

In case, 5: reading (STU); Rest;

Scenario 6: avg _ arrange (stu); Breakthrough;

Case 7: num _ arrange (stu); Breakthrough;

Case 8: Stu; Breakthrough;

Situation: save (stu); Breakthrough;

Default value: to _ exit ();

}

}

}

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *