#主程序界面
from contact import *
cn = cname()
def show_1():
print("-"*40)
print(" 联系人管理系统 ")
print(" 1 搜索联系人 ")
print(" 2 新建联系人 ")
print(" 3 联系人列表 ")
print(" 4 特别关心 ")
print(" 5 黑名单")
print("_"*40)
def show_2():
print("-"*20)
print(" 1 修改联系人信息 ")
print(" 2 删除联系人")
print(" 3 返回")
print(" 4 将联系人添加至特别关心")
print(" 5 将联系人列入黑名单")
print("-" * 20)
def show_3():
print("-"*20)
print(" 1 修改联系人信息 ")
print(" 2 将联系人从特别关心移除")
print(" 3 返回")
print(" 4 删除联系人")
print("-" * 20)
def show_4():
print("-"*20)
print(" 1 修改联系人信息 ")
print(" 2 恢复联系人")
print(" 3 删除联系人")
print(" 4 返回 ")
print("-" * 20)
def show_5():
print("-" * 20)
print(" 1 确定删除 ")
print(" 2 取消删除")
print("-" * 20)
while True:
show_1()
k = input("请输入功能序号:")
if k == '1':
name = input("请输入联系人姓名:")
if cn.sea(name) != 0:
if cn.yon_care(name) != 1:
show_2()
c = input("请输入功能序号:")
if c == '1':
cn.mod(name)
elif c == '2':
cn.dels(name)
elif c == '3':
pass
elif c == '4':
if cn.yon_care(name) == '1':
pass
else :
cn.ins_care(name)
print("添加成功!")
elif c == '5':
cn.ins_bl(name)
else :
print("无此选项!")
else :
show_3()
d = input("请输入功能序号:")
if d == '1':
cn.dels_care(name)
cn.mod(name)
cn.ins_care(name)
elif d == '2':
cn.remove_care(name)
print("已移出特别关心!")
elif d == '3':
pass
elif d == '4':
print("此联系人为特别关心!!!")
print("删除后将无法找回!!!")
show_5()
e = input("请输入功能序号:")
if e == '1':
cn.remoce_care(name)
cn.dels(name)
else:
print("取消删除!")
else:
print("无此选项!")
else :
pass
elif k == '2':
name = input("请输入联系人姓名:")
if cn.yon_contect(name) != 1 and cn.yon_bl(name) != 1:
cn.ins(name)
else :
if cn.yon_contect(name) == 1:
print("联系人已存在!")
elif cn.yon_bl(name) == 1:
print("联系人已存在于黑名单,请勿重复添加!")
print("您可以将联系人从黑名单中移出!")
elif k == '3':
if cn.no_contect != 1:
cn.show_contect()
else :
print("暂无联系人!!!")
elif k == '4':
if cn.no_care() != 1:
cn.show_care()
show_3()
d = input("请输入功能序号:")
if d == '1':
na = input("请输入要修改的联系人的姓名:")
cn.remove_care(na)
cn.mod(name)
cn.ins_care(name)
elif d == '2':
na = input("请输入要移出的联系人的姓名:")
cn.remove_care(na)
print("已移出特别关心!")
elif d == '3':
pass
elif d == '4':
na = input("请输入要删除的联系人的姓名:")
print("此联系人为特别关心!!!")
print("删除后将无法找回!!!")
show_5()
e = input("请输入功能序号:")
if e == '1':
cn.remove_care(name)
cn.dels(name)
else:
print("取消删除!")
else:
print("无此选项!")
else :
print("暂无特别关心联系人!")
elif k == '5':
if cn.no_bl() != 1:
cn.show_bl()
show_4()
q = input("请输入功能序号:")
if q == '1':
w = input("请输入联系人姓名:")
if cn.yon_bl(w) == 1:
cn.mod_bl(w)
else :
print("黑名单中无此联系人")
elif q == '2':
na = input("请输入联系人姓名:")
if cn.yon_bl(na) == 1:
cn.re_bl_ins_con(na)
else:
print("黑名单中无此联系人")
elif q == '3':
na = input("请输入联系人姓名:")
if cn.yon_bl(na) == 1:
cn.dels_bl(na)
else :
print("黑名单中无此联系人")
elif q == '4':
pass
else :
print("无此选项!")
else :
print("黑名单中无联系人!")
else :
print("无此选项请重新输入!")
这是主界面代码 需要调用下面的contact(我存的文件名是这个)
# 结点结构
class Node:
def __init__(self):
self.date1 = 0
self.date2 = 0
self.date3 = 0
self.date4 = 0
self.date5 = 0
self.nextx = None
# 创建一个单链表存储联系人信息
class cname:
def __init__(self):
self.head = Node()
self.head.nextx = None
self.head2 = Node()
self.head2.nextx = None
self.head3 = Node()
self.head3.nextx = None
#判断联系人是否存在
def yon_contect(self,name):
m = self.head
while m != None:
if m.date1 == str(name):
return 1
else :
m = m.nextx
#判断联系人是否为特别关心
def yon_care(self, name):
m = self.head2.nextx
while m != None:
if m.date1 == str(name):
return 1
else:
m = m.nextx
#判断联系人是否在黑名单
def yon_bl(self,name):
m = self.head3
while m != None:
if m.date1 == str(name):
return 1
else :
m = m.nextx
#查询联系人
def sea(self,name):
m = self.head.nextx
while m != None:
if m.date1 == str(name):
print("姓名:", m.date1, end=" ")
print("电话号码:", m.date2, end=" ")
print("住址:", m.date3, end=" ")
print("工作:", m.date4,end=" ")
print("邮箱",m.date5)
break
else :
if m.nextx == None:
print("无此联系人!")
return 0
else :
m = m.nextx
#添加联系人
def ins(self,name):
num = input("请输入联系人电话号码:")
add = input("请输入联系人住址:")
job = input("请输入联系人工作:")
em = input("请输入联系人邮箱")
p = Node()
p.date1 = str(name)
p.date2 = str(num)
p.date3 = str(add)
p.date4 = str(job)
p.date5 = str(em)
p.nextx = self.head.nextx
self.head.nextx = p
print("已添加至联系人列表!")
#联系人列表
def show_contect(self):
m = self.head.nextx
print(" 联系人:")
while m != None:
print("姓名:",m.date1,end=" ")
print("电话号码:",m.date2,end=" ")
print("住址:",m.date3,end=" ")
print("工作:",m.date4,end=" ")
print("邮箱",m.date5)
m = m.nextx
#修改联系人信息
def mod(self,name):
m = self.head.nextx
while m != None:
if m.date1 == str(name):
m.date2 = input("请输入修改后联系人电话号码:")
m.date3 = input("请输入修改后联系人住址:")
m.date4 = input("请输入修改后联系人工作:")
m.date5 = input("请输入修改后联系人邮箱:")
break
else :
m = m.nextx
print("修改成功!")
#删除联系人信息
def dels(self,name):
m = self.head
while m != None:
if m.nextx.date1 == str(name):
m.nextx = m.nextx.nextx
print("删除成功!")
break
else :
m = m.nextx
#判断特别关心
def yor1(self,name):
m = self.head2
while m != None:
if m.date1 == str(name):
print("联系人已是特别关心!")
return 1
else :
m = m.nextx
#添加至特别关心
def ins_care(self,name):
k = self.head
m = self.head2
p = Node()
while k != None:
if k.date1 == str(name):
p.date1 = k.date1
p.date2 = k.date2
p.date3 = k.date3
p.date4 = k.date4
p.date5 = k.date5
p.nextx = m.nextx
m.nextx = p
break
else :
k = k.nextx
#输出特别关心列表
def show_care(self):
m = self.head2.nextx
print(" 特别关心:")
while m != None:
print("姓名:",m.date1,end=" ")
print("电话:",m.date2, end=" ")
print("住址:",m.date3, end=" ")
print("工作:",m.date4, end=" ")
print("邮箱:",m.date5)
m = m.nextx
#移除特别关心
def remove_care(self,name):
m = self.head2
while m.nextx != None:
if m.nextx.date1 == str(name):
m.nextx = m.nextx.nextx
else :
m = m.nextx
#添加至黑名单
def ins_bl(self,name):
k = self.head
m = self.head3
p = Node()
while k != None:
if k.date1 == str(name):
p.date1 = k.date1
p.date2 = k.date2
p.date3 = k.date3
p.date4 = k.date4
p.date5 = k.date5
p.nextx = m.nextx
m.nextx = p
break
else :
k = k.nextx
c = self.head
while c != None:
if c.nextx.date1 == str(name):
c.nextx = c.nextx.nextx
print("添加成功!")
break
else:
c = c.nextx
#输出黑名单
def show_bl(self):
m = self.head3.nextx
print(" 黑名单:")
while m != None:
print("姓名:",m.date1,end=" ")
print("电话号码:",m.date2,end=" ")
print("住址:",m.date3,end=" ")
print("工作:",m.date4,end=" ")
print("邮箱:",m.date5)
m = m.nextx
#修改黑名单中联系人信息
def mod_bl(self,name):
m = self.head3.nextx
while m != None:
if m.date1 == str(name):
m.date2 = input("请输入修改后联系人电话号码:")
m.date3 = input("请输入修改后联系人住址:")
m.date4 = input("请输入修改后联系人工作:")
m.date5 = input("请输入修改后联系人邮箱:")
break
else :
m = m.nextx
print("修改成功!")
#删除黑名单中的联系人
def dels_bl(self,name):
m = self.head3
while m != None:
if m.nextx.date1 == str(name):
m.nextx = m.nextx.nextx
print("删除成功!")
break
else :
m = m.nextx
#恢复联系人
def re_bl_ins_con(self,name):
k = self.head3
m = self.head
p = Node()
while k != None:
if k.date1 == str(name):
p.date1 = k.date1
p.date2 = k.date2
p.date3 = k.date3
p.date4 = k.date4
p.date5 = k.date5
p.nextx = m.nextx
m.nextx = p
break
else :
k = k.nextx
c = self.head3
while c != None:
if c.nextx.date1 == str(name):
c.nextx = c.nextx.nextx
print("恢复成功!")
break
else:
c = c.nextx
#判断黑名单是否为空
def no_bl(self):
if self.head3.nextx == None:
return 1
else :
pass
#判断特别关心是否为空
def no_care(self):
if self.head2.nextx == None:
return 1
else :
pass
#判断联系人列表是否为空
def no_contect(self):
if self.head.nextx == None:
return 1
else :
pass
两个文件放到同一路径 运行前面那个主界面的 就可以了 !