Home > Back-end >  Turn the Java help c
Turn the Java help c

Time:09-17

Address book management
Problem description
Write a simple address book management program to address book record names, addresses (province, city (county), street), telephone number, zip code and so on four,
The basic requirements
Procedures should provide basic functions are:
1) add: increase a person's records to the directory
2) show that on the screen display all communication record of personnel information, should be able to split screen display,
3) storage: the address book information stored in a file,
4) load: the file information into the program,
5) query: according to the relevant information of name to find someone, if found its name, address, telephone number and postal code,
6) changes: can change a person in addition to the names of other information,
Test data
Program should be input not less than 10 staff address book information, should take into account the personnel can be the same situation,
Implementation tips
Program available a singly linked list to manage the personnel information, each person's name, address, telephone number and postal code to use a class Cperson to implementation, as a linked list the value of the pointer to the Cperson class object, through the linked list traversal can operate on these data,
As a content
In order to accelerate the speed of data locating, adopt the method of common priority on every node of the linked list sorting, namely once operating data of a staff, his data will be the first call to the list of chain, so that after a finite time, often refer to the personnel information will, in the front of the list, although cannot say chain first node must be the most commonly used, but the commonly used node will row in the front part of the chain table lookup to go when the average distance must be short,
# include
# include
# include
# include
# include
using namespace std;
The class Cperson {
Public: void the set () {cin> name> Addr> Tel> Post; }
Void sign (Cperson & amp; S) {
S.n ame=name;
S.a DDR=addr;
S.t el=tel;
Supachai panitchpakdi ost=post; }
String getname ()
{return name; }
Void revise () {
Cout<" Please input to modify the content: "& lt; Addr> Tel> Post;
Cout<" Modify success "& lt; Void disp () {coutPrivate:
string name;
String addr.
Int tel;
Int the post; };
Struct List {Cperson mem; The List * next; };
Void the memory (List * p)
{the List * t; Cperson s; Ofstream output (" address. TXT ", the ios: : binary);
if(! The output)
{cout<" The File always be the opened. "& lt; return; }
T=p - & gt; next;
While (t) {
Nb=t - & gt; Mem. Getname ();
If (na==nb)
{t - & gt; Mem. Revise (); break; } t=t - & gt; next; }
If (t==NULL)
Cout<" Can't find the contact person "& lt; Cout<" Name \ \ t t address telephone number \ t zip code "& lt; While (t)
{t - & gt; Mem. Disp (); T=t - & gt; next; }
Free (t); }
Void dis (List * p)
{the memory (p);
Cperson s;
Ifstream input (" address. TXT ", the ios: : binary); if(! Input) {
Cout<" The File always be the opened. "& lt; Cout<" All the contacts in the address book information: "& lt; While (input) {
Spyware doctor isp (); Input. Read ((char *) & amp; S, sizeof (Cperson)); }
Input. The close (); }
Int main ()
{* per the List;
Per=(struct List *) malloc (sizeof (struct List));
Per - & gt; Next=NULL;
Int sel.
While (1) {
Cout<" \ n \ n ";
Cout<" T \ \ t * * * * * * * * * * * * * * * * * * * address book management system * * * * * * * * * * "& lt; CoutCout<" \ \ t t3: by name query information 4: modifying existing contact information "& lt; Cout<" T \ \ t 5: insert a new contact 6: "exit system & lt; Cout<" Please input your choice: ";
Cin> Sel.
The switch (sel) {
Case 1: {set (per); break; }
Case 2: {dis (per); break; }
Case 3: {che (per); break; }
Case 4: {rev (per); break; }
Case 5: {insert (per); break; }
Case 6: exit (1); }} List * t=per; While (per - & gt; Next! T==NULL) {per; Per=t - & gt; next; Free (t); } free (per); return 0; }
  • Related