链表版通讯录-C++
/*
功能:通讯录
作者:wind
日期:2013-10-12
*/
#include <iostream>
#include <string>
using namespace std;
class Address
{
public:
Address(string aName,string aTele);
~Address();
void printAddress(Address *head);
void insertAddress(Address *head);
void deleteAddress(Address *head);
Address *next;
private:
string m_aName;
string m_aTele;
};
Address::Address(string aName=" ",string aTele=" "):
m_aName(aName),m_aTele(aTele){};
Address::~Address(){};
Address* creatList(void)
{
Address *head;
head = new Address;
if (!head)
{
exit(0);
}
head->next=NULL;
return head;
}
void Meu(void)
{
cout<<"1.添加记录:"<<endl;
cout<<"2.删除记录:"<<endl;
cout<<"3.浏览记录:"<<endl;
cout<<"4.退出系统:"<<endl;
cout<<"请选择:";
}
void Address::insertAddress(Address *head)
{
Address *p,*q;
string name,tele;
p = head;
q = NULL;
q = new Address;
if (p->next==NULL)
{
cout<<"提示:通讯录中没有记录。"<<endl;
cout<<"联系人:";
cin>>q->m_aName;
cout<<"电话:";
cin>>q->m_aTele;
p->next = q;
q->next = NULL;
p = p->next;
}
else
{
while (p->next)
{
p =p->next ;
}
printAddress(head);
cout<<"联系人:";
cin>>q->m_aName;
cout<<"电话:";
cin>>q->m_aTele;
p->next = q;
q->next = NULL;
p = p->next;
}
}
void Address::deleteAddress(Address *head)
{
int i,n;
Address*p,*q;
p = q = head;
cout<<"请输入记录的序号:";
cin>>n;
for (i=0;i<n;i++)
{
p =q;
q = q->next;
}
if (q)
{
p->next = q->next;
}
}
void Address::printAddress(Address *head)
{
Address*p=head;
int i=1;
while(p->next)
{
p = p->next;
cout<<i<<"."<<p->m_aName<<" "<<p->m_aTele<<endl;
i++;
}
}
int main(void)
{
Address *head;
Address num;
int choice;
head = creatList();
do
{
Meu();
cin>>choice;
switch(choice)
{
case 1:
num.insertAddress(head);
break;
case 2:
num.deleteAddress(head);
num.printAddress(head);
break;
case 3:
num.printAddress(head);
break;
case 4:
break;
}
} while (choice!=4);
delete head;
system("pause");
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
预览
除特别注明外,本站所有文章均为 windcoder 原创,转载请注明出处来自: lian-biao-ban-tong-xun-lu-c
Loading comments...

预览
厉害
好高级~ :smile:
回复 @灰常记忆: 没有啦,当初的作业而已,不想放电脑里占空间了就一点点搬上来了
这个很好,
回复 @猫客工作室: 缪赞了,学生作品而已
c语言哈,都已经忘光光了
回复 @欧美大图吧: 我也差不多了→_→
技术男,初次到访
回复 @微观互联网: 欢迎O(∩_∩)O~
看不懂,赞一个吧。
回复 @PHP二次开发: O(∩_∩)O谢谢
多谢分享,这么好的技术
回复 @圆月博客: 嘿嘿
好熟悉呀
回复 @微历史: 我已经快忘了。。。