我的密码.cpp
来自「通讯录是一个完美的程序希望大家能够喜欢多多下载」· C++ 代码 · 共 865 行 · 第 1/2 页
CPP
865 行
cout<<setw(35)<<"电话号码:\t"<<current_ptr->phone_num<<endl;
cout<<setw(35)<<"创建时间:\t"<<current_ptr->year<<'-'<<current_ptr->month<<'-';
cout<<current_ptr->day<<'\t'<<current_ptr->hour<<':';
cout<<current_ptr->minute<<endl<<setw(38)<<"************\n";
p1=current_ptr->last;
if(verify_delete())
{
cin.ignore(1,'\n');
delete_node(p1);
cout<<"\n\n"<<setw(38)<<"记录已被删除!\n";
}
else
{cin.ignore(1,'\n');
cout<<"\n\n"<<setw(38)<<"记录未被删除!\n";
}
}
else{ cout<<"\n\n"<<setw(45)<<"SORRY,未找到您所需要的记录!\n";
}}
label0: cout<<"\n\n\n\n"<<setw(36)<<"需要继续删除...\n";}while(verify_delete()&&head_ptr!=NULL);
system("cls");
if(head_ptr==NULL)
{cin.ignore(6,'\n');cout<<"\n\n\n\n"<<setw(45)<<"SORRY!电话为空,您无法继续删除记录!\n";cout<<setw(38)<<"键入Enter继续...";
cin.get(pause);system("cls");return;}
}
else{system("cls");cout<<setw(39)<<"*********\n"<<setw(37)<<"SORRY!\n"<<setw(40)<<"电话簿为空!\n";
cout<<setw(40)<<"无记录可删!\n"<<setw(39)<<"*********\n";cout<<setw(38)<<"键入Enter继续...";
cin.get(pause);system("cls");return;}
}
int action::verify_delete() //确定函数,确认用户当前所进行的操作
{ char YesNo;
cout<<setw(35)<<"*********\n"<<setw(37)<<"确定吗(Y/N)\t";
cin>>YesNo;
if(YesNo=='Y'||YesNo=='y') return 1;
else return 0;
}
void action::delete_node(friend_node*p1) //删除节点函数,当delete_record()函数执行时调用其进行删除节点
{
if(current_ptr==head_ptr)
delete_head_of_list();
else
{ if(current_ptr->next==head_ptr)
delete_end_of_list(p1);
else
delete_from_middle_of_list(p1);}
}
void action::delete_head_of_list() //删除链表的头
{
current_ptr=head_ptr;
if(head_ptr->next!=head_ptr)
{ head_ptr=current_ptr->next;
tail_ptr->next=head_ptr;
head_ptr->last=tail_ptr;
delete current_ptr;
current_ptr=head_ptr;
}
else
{ head_ptr=NULL;
tail_ptr=NULL;
delete current_ptr;
current_ptr=NULL;
}
}
void action::delete_end_of_list(friend_node*p1) //删除为节点
{ friend_node*pq;
pq=current_ptr;
delete pq;
p1->next=head_ptr;
head_ptr->last=p1;
tail_ptr=p1;
current_ptr=head_ptr;
}
void action::delete_from_middle_of_list(friend_node*p1)
{ p1->next=current_ptr->next;
current_ptr->next->last=p1;
delete current_ptr;
current_ptr=p1;
}
void action::delete_list() //程序退出时进行调用,删除内存中的双向链表
{ friend_node*temp_ptr;
current_ptr=head_ptr;
if(head_ptr->next!=head_ptr){
do{ temp_ptr=current_ptr->next;
tail_ptr->next=temp_ptr;
temp_ptr->last=tail_ptr;
delete current_ptr;
current_ptr=temp_ptr;
}while(temp_ptr!=NULL&&temp_ptr!=tail_ptr);
delete current_ptr;
}
else{ current_ptr=NULL;
tail_ptr=NULL;
delete head_ptr;
head_ptr=NULL;
}
}
void action::edit_record()
{ system("cls");
friend_node*p3,*pq;
pq=NULL;
p3=new friend_node;
if(head_ptr==NULL){system("cls");cout<<setw(39)<<"*********\n"<<setw(37)<<"SORRY!\n"<<setw(40)<<"电话簿为空!\n";
cout<<setw(40)<<"无记录可删!\n"<<setw(39)<<"*********\n";cout<<setw(38)<<"键入Enter继续...";
cin.get(pause);system("cls");}
else{do{
cin.ignore(9,'\n');
system("cls");
char search_string[36];
current_ptr=head_ptr;
cin.ignore(36,'\n');
cout<<"\n\n\n"<<setw(48)<<"请键入需要修改的联系人的姓名:";
cin.get(search_string,36);
cin.ignore(36,'\n');
if(strcmp(current_ptr->name,search_string)==0)
{cout<<"\n\n"<<setw(35)<<"找到记录\n"<<setw(38)<<"************\n";
cout<<setw(30)<<"姓名:"<<"\t\t"<<current_ptr->name<<endl;
cout<<setw(35)<<"电话号码:\t"<<current_ptr->phone_num<<endl;
cout<<setw(35)<<"创建时间:\t"<<current_ptr->year<<'-'<<current_ptr->month<<'-';
cout<<current_ptr->day<<'\t'<<current_ptr->hour<<':';
cout<<current_ptr->minute<<endl<<setw(38)<<"************\n";
if(verify_delete())
{
cin.ignore(30,'\n');
cout<<setw(45)<<"请键入修改后的姓名:\t";
cin.get(p3->name,36);
cin.ignore(36,'\n');
cout<<setw(49)<<"请键入修改后的电话号码:";
cin.get(p3->phone_num,12);
cin.ignore(20,'\n');
time_date=time(0);
current_time=localtime(&time_date);
p3->year=current_time->tm_year+1900;
p3->month=current_time->tm_mon+1;
p3->day=current_time->tm_mday;
p3->hour=current_time->tm_hour;
p3->minute=current_time->tm_min;
if(verify_delete())
{
delete_head_of_list();
insert_node(p3);
cout<<setw(38)<<"记录已被修改成功!\n";cin.ignore(30,'\n');
}
else
{cout<<setw(37)<<"记录未被修改!\n";cin.ignore(30,'\n');}
}
goto label3;
}
else
{if(head_ptr!=NULL&&head_ptr->next!=NULL)
{
current_ptr=current_ptr->next;
while((current_ptr!=head_ptr)&&(strcmp(current_ptr->name,search_string)!=0))
current_ptr=current_ptr->next;
if(current_ptr!=head_ptr)
{
cout<<"\n\n"<<setw(35)<<"找到记录\n"<<setw(38)<<"************\n";
cout<<setw(30)<<"姓名:"<<"\t\t"<<current_ptr->name<<endl;
cout<<setw(35)<<"电话号码:\t"<<current_ptr->phone_num<<endl;
cout<<setw(35)<<"创建时间:\t"<<current_ptr->year<<'-'<<current_ptr->month<<'-';
cout<<current_ptr->day<<'\t'<<current_ptr->hour<<':';
cout<<current_ptr->minute<<endl<<setw(38)<<"************\n";
if(verify_delete())
{
cin.ignore(30,'\n');
cout<<setw(45)<<"请键入修改后的姓名:\t";
cin.get(p3->name,36);
cin.ignore(36,'\n');
cout<<setw(49)<<"请键入修改后的电话号码:";
cin.get(p3->phone_num,12);
cin.ignore(20,'\n');
time_date=time(0);
current_time=localtime(&time_date);
p3->year=current_time->tm_year+1900;
p3->month=current_time->tm_mon+1;
p3->day=current_time->tm_mday;
p3->hour=current_time->tm_hour;
p3->minute=current_time->tm_min;
if(verify_delete())
{
pq=current_ptr->last;
delete_node(pq);
insert_node(p3);
cout<<setw(38)<<"记录已被修改成功!\n";
cin.ignore(30,'\n');
}
else
{cin.ignore(30,'\n');
cout<<setw(38)<<"记录未被修改!\n";}
}
}
else
cout<<setw(36)<<"找不到记录!\n";}
}
label3: cout<<setw(38)<<"键入Enter继续...";
cin.get(pause);cin.get(pause);
system("cls");
cout<<"\n\n\n\n"<<setw(36)<<"需要继续修改记录...\n";}while(verify_delete()&&head_ptr!=NULL);
system("cls");
if(head_ptr==NULL)
{cin.ignore(6,'\n');cout<<"\n\n\n\n"<<setw(45)<<"SORRY!电话为空,您无法继续删除记录!\n";cout<<setw(38)<<"键入Enter继续...";
cin.get(pause);system("cls");return;}
}
}
void action::process()
{
help:
int choice2;
system("cls");
cout<<endl;
cout<<"\n"<<setw(37)<<"欢迎进入进程菜单\n";
cout<<setw(55)<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<setw(50)<<"1-电话簿无法显示\n";
cout <<setw(52)<< "2-怎样清除所有记录\n";
cout <<setw(54)<< "3-什么时候出来新版本\n";
cout <<setw(62)<< "4-新版本中会增加什么新的功能\n";
cout <<setw(48)<< "5-程序编写过程\n";
cout <<setw(40)<< "0-退出\n";
cout<<setw(55)<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n\n"<<setw(35)<<"请键入您的选择:\t";
cin >> choice2;
switch(choice2)
{
case 1:
cout<<"请仔细检查一个叫FRIEND.DAT文件夹及里面的文件"<<endl;
cout<<"如果没有文件,则电话簿可能已经丢失,";
cout<<"如果文件名不符,则应将其更名为FRIEND.DAT"<<endl;
cout<<"键入Enter继续..."<<endl;
pause=getch();
system("cls");
goto help;
break;
case 2:
cout<<"删除名为FRIEND.DAT文件"<<endl;
cout<<"键入Enter继续..."<<endl;
pause=getch();
system("cls");
goto help;
break;
case 3:
cout <<'\n'<< "新的版本会在Intel公司推出新的操作系统Vista之后的一个月内震撼推出"<<endl;;
cout<<"届时会有更多的促销活动,值得期待!"<<endl;
cout << "键入Enter继续..."<<endl;
pause=getch();
system("cls");
goto help;
break;
case 4:
cout << "新的版本首先会改进原版本中的一些缺陷:"<<endl;
cout << "1.增加通过姓名首字母搜索联系人"<<endl;
cout << "2.在搜索出来的联系人中,可以进行编辑,修改,删除等功能"<<endl;
cout<<"3.修改记录时,询问用户需要做哪方面的修改,根据用户的选择来具体执行修改"<<endl;
cout << "4.使用不同用户,不同的操作权限"<<endl;
cout << "5.联网修补程序漏洞"<<endl;
cout << "键入Enter继续..."<<endl;
pause=getch();
system("cls");
goto help;
break;
case 5:
cout<<"\n\n\n\n"<<setw(44)<<"本程序历时一个多月,涉及的程序编程技巧较广,"<<endl;
cout<<"此程序功能相对而言比较强大"<<endl;
cout<<"在此再次感谢帮助完成程序的老师和同学"<<endl;
cout<<"再次声明:请尊重作者的版权,未得到作者的许可,不得用于任何以盈利为目的活动"<<endl;
cout << "键入Enter继续..."<<endl;
pause=getch();
system("cls");
goto help;
break;
default:
cout << "键入Enter继续..."<<endl;
cin.get(pause);system("cls");
break;
}
}
void action::write_list_to_file2() //将新的密码保存到code文件中去
{
ofstream outfile;
outfile.open("CODE.DAT",ios::out);
if(outfile)
{outfile<<Code<<endl;
outfile.close();}
else
cout<<"文件打开错误\n";
}
void action::write_list_to_file() //将链表写入到friend文件中去
{
ofstream outfile;
outfile.open("FRIENDS.DAT",ios::out);
if(outfile)
{
current_ptr=head_ptr;
if(head_ptr!=NULL)
{
do
{
outfile<<current_ptr->name<<endl;
outfile<<current_ptr->phone_num<<endl;
outfile<<current_ptr->year<<endl;outfile<<current_ptr->month<<endl;
outfile<<current_ptr->day<<endl;outfile<<current_ptr->hour<<endl;
outfile<<current_ptr->minute<<endl;
current_ptr=current_ptr->next;
}while(current_ptr!=head_ptr);
}
outfile<<"文件结束\n";
outfile.close();
}
else
{
cout<<"文件打开错误\n";
}
}
void action::load_list_from_file2() //将密码读取出来,并且将其赋值给Code数组,从而进行密码的读入
{
ifstream infile;
infile.open("CODE.DAT",ios::in);
if(infile)
{infile.get(Code,5);infile.ignore(5,'\n');}
else
cout<<"警告:记忆错误。从盘里读取失败\n";
}
void action::load_list_from_file() //从文件当中读出信息,并且动用insert函数创建双向链表
{
friend_node*p;
ifstream infile;
int end_loop=0;
infile.open("FRIENDS.DAT",ios::in);
char y[6],m[6],d[6],h[6],M[6];
if(infile)
{
do
{
p=new friend_node;
if(p!=NULL)
{
infile.get(p->name,36);
infile.ignore(36,'\n');
if((strcmp(p->name,"")!=0)&&(strcmp(p->name,"文件结束")!=0))
{
infile.get(p->phone_num,15);
infile.ignore(20,'\n');
infile.get(y,6);
p->year=change(y);
infile.ignore(20,'\n');
infile.get(m,6);
p->month=change(m);
infile.ignore(20,'\n');
infile.get(d,6);
p->day=change(d);
infile.ignore(20,'\n');
infile.get(h,6);
p->hour=change(h);
infile.ignore(20,'\n');
infile.get(M,6);
p->minute=change(M);
infile.ignore(20,'\n');
insert(p);
}
else
{
delete p;
end_loop=1;
}
}
else
{
cout<<"警告:记忆错误。从盘里读取失败\n";
end_loop=1;
}
}while(end_loop==0);
infile.close();
}
else
{
cout<<"没有有效的文件。链表为空\n";
}
}
void action::change_code() //更改密码
{
system("cls");
char m[5],key[5],key2[5];
label2: cout<<"\n\n\n\n"<<setw(36)<<"请输入旧密码:\t";
ccode(m);cout<<'\n';
for(int i=0;i<5;i++)
{ if(m[i]!=Code[i])
{
cout<<"\n"<<setw(38)<<"密码不正确!\n";
cin.ignore(38,'\n');
system("cls");
goto label2;
}
}
do{
cout<<"\n\n"<<setw(36)<<"请输入新密码:\t";
ccode(key);cout<<'\n';
cout<<'\n'<<setw(40)<<"请再次输入新密码:\t";
ccode(key2);cout<<'\n';
}while(strcmp(key,key2)!=0);
cout<<'\n'<<setw(42)<<"您的新密码已经确认!\n";
strcpy(Code,key);
write_list_to_file2();
cin.ignore(8,'\n');
cout<<'\n'<<setw(36)<<"请键入Enter继续...";
cin.get(pause);
system("cls");
}
void action::ccode(char*s) //执行密码的显示,用户输入密码时使用*进行覆盖,起到安全保护
{
char ch;
int i=0;
cout.flush();
ch=getch();
while(ch!=13)
{
s[i++]=ch;
cout<<"*";
cout.flush();
ch=getch();
}
s[i]=0;
}
int action::change(char*s) //将从文件读出的字符型数据转换成整型,主要用来对时间日期的赋值
{
int k=0;
for(int i=0;s[i];i++)
k=k*10+s[i]-'0';
return k;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?