//
# include "stdafx. H"
#include
#include
#include
#include
#include
# define total (p) (p - & gt; Data. Maths) + (p - & gt; Data. Chinese) + (p - & gt; Data. English)
# define FALSE 0
# define TRUE 1
Struct Info
{
char name[15];/* name */
Float maths;
Float Chinese;
Float English;
};
Typedef int BOOL.
Typedef struct node */* define the address book list node structure/
{
Struct Info data;
Struct node * next;
} Node, * link;
Void the enter (link) l/* input record */
{
The Node * p, * q;
Q=l;
P=(*) malloc (sizeof (Node));/* * application node space/
if(! P)/* not successful application output message */
{
Printf (" the memory malloc fail \ n ");
return;
}
Printf (" input name: ");
The scanf (" % s ", p - & gt; Data. The name);
Printf (" input mathematics performance: ");
The scanf (" % f ", & amp; P - & gt; Data. The maths);
Printf (" input language result: ");
The scanf (" % f ", & amp; P - & gt; Data. Chinese);
English: printf (" input ");
The scanf (" % f ", & amp; P - & gt; Data. English);
P - & gt; Next=NULL;
Q - & gt; Next=p;
Q=p;
}
Void del (link l)
{
The Node * p, * q;
Char s [20];
Q=l;
P=q - & gt; Next;
Printf (" enter name: ");
The scanf (" % s ", s);/* the names of the input to delete */
While (p)
{
If (STRCMP (s, p - & gt; Data. The name)==0)/* find record and input the name matching in */
{
Q - & gt; Next=p - & gt; Next;/* */delete p nodes
Free (p);/* p node space release */
Printf (" delete successfully!" );
break;
}
The else
{
Q=p;
P=q - & gt; Next;
}
}
Getch ();
}
Void the display (Node * p)
{
Printf (" \ t % 15 s ", p - & gt; Data. The name);
Printf (" \ t % 5.2 f ", p - & gt; Data. The maths);
Printf (" \ t % 5.2 f ", p - & gt; Data. Chinese);
Printf (" \ t % 5.2 f ", p - & gt; Data. English);
Printf (" \ t % 5.2 f ", total (p));
}
Void search (link l)
{
Char name [20].
Node * p;
P=l - & gt; Next;
Printf (" enter the name to find: ");
The scanf (" % s ", name); Input the name of the to find/* */
While (p)
{
If (STRCMP (p - & gt; Data. The name, the name)==0)/* find match with the name of the input records */
{
The display (p);/* the function display information */
Getch ();
break;
}
The else
P=p - & gt; Next;
}
}
Void the modify (link l)
{
Char name [20].
Node * p;
P=l - & gt; Next;
BOOL find=FALSE;
Printf (" enter the name to find: ");
The scanf (" % s ", name); Input the name of the to find/* */
While (p)
{
If (STRCMP (p - & gt; Data. The name, the name)==0)/* find match with the name of the input records */
{
The find=TRUE;
The display (p);/* the function display information */
printf("\n");
Printf (" type a new name: ");
The scanf (" % s ", p - & gt; Data. The name);
Printf (" input new math: ");
The scanf (" % f ", & amp; P - & gt; Data. The maths);
Printf (" input of new language result: ");
The scanf (" % f ", & amp; P - & gt; Data. Chinese);
English: printf (" input ");
The scanf (" % f ", & amp; P - & gt; Data. English);
break;
}
The else
P=p - & gt; Next;
}
If (find==FALSE)
{
Printf (" no found \ n ");
Getch ();
}
}
Void list (link l)
{
Node * p;
P=l - & gt; Next;
Printf (" \ t \ \ t t name ");
Printf (" \ t mathematics ");
Printf (" \ t language ");
Printf (" \ t English ");
Printf (" \ t scores ");
printf("\n");
While (p!=NULL)/* from the first node have been traversing the list last */
{
The display (p);
printf("\n");
P=p - & gt; Next;
}
Getch ();
}
Void the save link (l)
{
Node * p;
FILE *fp;
P=l - & gt; Next;
If ((fp=fopen (" f: \ \ adresslist ", "wb"))==NULL)
{
Printf (" can not open the file \ n ");
The exit (1);
}
Printf (" \ nSaving file \ n ");
While (p)/* will node content one by one to disk file */
{
Fwrite (p, sizeof (Node), 1, fp);
P=p - & gt; Next;
}
fclose(fp);
Getch ();
}
Void the load (link l)
{
The Node * p, * r;
FILE *fp;
L - & gt; Next=NULL;
R=l;
If ((fp=fopen (" f: \ \ adresslist ", "rb"))==NULL)
{
Printf (" can not open the file \ n ");
The exit (1);
};
Printf (" \ nLoading file \ n ");
while(! The feof (fp))
{
P=(*) malloc (sizeof (Node));/* * application node space/
if(! P)
{
Printf (" the memory malloc fail!" );
return;
}
If (fread (p, sizeof (Node), 1, fp)!=1)/* read records to the node p */
break;
The else
{
P - & gt; Next=NULL;
R - & gt; Next=p;/* insert list */
R=p;
}
}
fclose(fp);
Getch ();
}
Int menu_select ()
{
int i;
Printf (" \ n \ n \ t * * * * * * * * * * * * * * * * * * * * * * * * * ADDRESS LIST * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ t | * 1. Input record * | \ n ");
Printf (" \ t | * 2. Delete the record * | \ n ");
Printf (" \ t | * 3. The list record * | \ n ");
Printf (" \ t | * 4. The search record * | \ n ");
Printf (" \ t | * 5. Save record * | \ n ");
Printf (" \ t | * 6. The load record * | \ n ");
Printf (" \ t | * 7. Modi record * | \ n ");
Printf (" \ t | * 8. Quit * | \ n ");
Printf (" \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Do
{
Printf (" \ n \ tEnter your choice: ");
The scanf (" % d ", & amp; i);
} while (i<0 | | i> 8);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull