I am using vc + + 6.0
Beginner
#include
#include
#include
#include
13//# define IDLen ID field length
11//# define NameLen name field length
5//# define SexLen gender field length
//storage structure of the student's grade
Struct Score
{
Int cp;//C
Int en;//English
Int math;//high number
};
//storage structure of student information
Typedef struct Stu
{
Char id [IDLen];//student id
Char name [NameLen];//name
Char sex [SexLen];//gender
int age;//age
Struct Score Score;//store the result of structure
Double avg.//average
} Student;
//the bidirectional circular linked list node
Typedef struct theNode
{
Struct theNode * prev.//points to the previous node
Int the order;//original order
Student stu. Students in a//node
Struct theNode * next;//pointer to the next node
} the Node;
The head Node *=NULL;//a pointer to the first node
Node * tail=NULL;//a pointer to the end node
Int num=0;//input the total number of
Char choice=0;//the user to select the item
Char dir=0;//user sort direction (1: ascending, 2: descending)
Void InputStudent ();//input student information
Void DisplayMenu ();//display options menu
Void GetOrderDir ();//show the user to select the sort direction
Void SortStudent ();//information to the student stu [] to sort the results into sorted in []
Void OutputStudent ();//output all student information
Node * find (Node *);//query student information
Void main ()
{
InputStudent ();//input student information
While (1)
{
DisplayMenu ();//display menu
If (' 0 '==choice)//select operation "0", then exit the program
{printf (" \ n thanks for use! \n");
Getche ();
exit(0);
}
Else if (=='9' choice)//select "9" operation, the output all the original information
{
Dir='1'.
SortStudent ();//sort student information
OutputStudent ();//output student information
}
Else if (choice> '0' & amp; & Choice<'9')//other operations, according to the selected attributes sorting
{
GetOrderDir ();//show the user to select the sort direction
SortStudent ();//sort student information
OutputStudent ();//output student information
}
Else if (' a '==choice)
{
Find (the head);
}
}
}
//input student information
Void InputStudent ()
{
Node * p=NULL;//points to the new student node
//initialize the head pointer and the tail pointer
Head=(*) malloc (sizeof (Node));
Tail=(*) malloc (sizeof (Node));
The head - & gt; Prev=NULL;
The head - & gt; Next=tail;
Tail - & gt; Prev=head;
Tail - & gt; Next=NULL;
While (1)
{
Printf (" \ n please enter the first % d student information: \ n ", + + num);
P=(*) malloc (sizeof (Node));//enter student allocate storage space for new
p-> The order=num;
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
Printf (" student number (less than 12 characters) : \ t ");
The scanf (" % s ", p - & gt; Stu. Id);
p-> Stu. Id [] IDLen - 1=0;//the last character to add a terminator
Printf (" name (10 characters) : \ t ");
The scanf (" % s ", p - & gt; Stu. Name);
p-> Stu. Name [] NameLen - 1='\ 0';//the last character to add a terminator
Printf (" gender (4 characters) : \ t ");
The scanf (" % s ", p - & gt; Stu. Sex);
p-> Stu. Sex [] SexLen - 1='\ 0';//the last character to add a terminator
Printf (" age (integer) : t \ \ t ");
The scanf (" % d ", & amp; p-> Stu. Age);
Printf (" "C" grade (integer) : \ t ");
The scanf (" % d ", & amp; p-> Stu. Score. Cp);
Printf (" "English" grade (integer) : \ t ");
The scanf (" % d ", & amp; p-> Stu. Score. En);
Printf (" high "number" result (integer) : \ t ");
The scanf (" % d ", & amp; p-> Stu. Score. Math);
p-> Stu. Avg=(p - & gt; Stu. Score. Cp + p - & gt; Stu. Score. En + p - & gt; Stu. Score. Math)/3.0;
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
Node p//the new students added to the list before finally tail
p-> Next=tail;//p after the node point to tail
p-> Prev=tail - & gt; Prev.//p of the nodes of the original tail before the node
Tail - & gt; Prev - & gt; Next=p;//tail after the node before the original node now point p
Tail - & gt; Prev=p;//tail now before the node point to tail
//whether or not to continue enter
Printf (" \ n please select operation: \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
Printf (" input (0) to complete the t \ \ t (any other key) : continue to input \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
If (getche ()=='0')
return;
}
}
//display options menu
Void DisplayMenu ()
{
While (1)
{
Printf (" please select your operating (sort and display the original information or exit) : \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
Printf (" * (1) student id \ \ t t (2) the name gender \ t (3) (4) age \ n ");
Printf (" * (5) (6) English \ \ t t C (7) high (8) average number \ t \ n ");
Printf (" * (9) shows the original input \ t \ n (0) to exit the program ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
Choice=getche ();
If (choice - '0' & lt; 0 | | choice - '0' & gt; 9 & amp; & choice!
='a')Printf (" \ n input error, please input again! \n");
else return;
}
}
//show the user to select the sort direction
Void GetOrderDir ()
{
While (1)
{
Printf (" please choose your sort direction (or return) : \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull