/***********************************************************
*版權所有 (C)2015. ChengAng
*
*文件名稱: zupu.cpp
*文件標識: 無
*內容摘要: 該項目的所有函數的實現
*其他說明: 無
*當前版本: V1.0
*作 者: 程昂
*完成日期: 20151223
*
*修改記錄1:
*修改日期: 20151223
*版本號: V1.0
*修改人: Cheng Ang
*修改內容:
********************************************************************/
#include"zupu.h"
/***********************************************************
*功能描述: 主函數,負責項目的調度
*輸入參數: 無
*輸出參數: 無
*返回值: 無
*其他說明: 無
*************************************************************/
int main() //主函數
{
creat();
huanying();
Save();
return 0;
}
/***********************************************************
*功能描述:新建或者打開已經存在的文件,從中讀取內容
*輸入參數: 無
*輸出參數: 無
*返回值: 無
*其他說明: 無
*************************************************************/
void creat() //創建或讀取文件
{
int j;
long k;
fp=fopen("數據文件.txt","r t");
if(fp!=NULL)
{
for(i=0; i<=maxlen; i++ )
{
j=fgetc(fp);
if(j==EOF)
return;
k=i;
fseek(fp,k*sizeof(struct persons),0);
fread(&persons[i],sizeof(struct persons),1,fp);
s=(linklist)malloc(sizeof(listnode));
s->num=persons[i].num;
strcpy(s->name,persons[i].name);
strcpy(s->e_addr,persons[i].e_addr);
strcpy(s->tel_no,persons[i].tel_no);
s->sim_no=persons[i].sim_no;
strcpy(s->arch,persons[i].arch);
s->cishu=persons[i].cishu;
if(head==NULL) //若爲空,則建立新節點
{
head=s;
r=head;
head->next=NULL;
}
else //否則,插入節點
{
r->next=s;
r=s;
r->next=NULL;
}
}
fclose(fp);
}
else //存入文件
{
fp=fopen("數據文件.txt","w");
i=1;
}
}
/***********************************************************
*功能描述: 開始界面,提供選擇操作的界面
*輸入參數: 選擇鍵
*輸出參數: 無
*返回值: 無
*其他說明: 通過選擇進入各種功能
*************************************************************/
void huanying() //選擇界面
{
system("cls"); //清屏
do
{
xiaotu();
cout<<" 歡迎使用通訊錄管理系統~~~~~~~"<<endl;
cout<<endl;
cout<<"+---------------------------------------------------------+"<<endl;
cout<<"+ 1.顯示分組信息請按1 4.編輯信息請按4 +"<<endl;
cout<<"+ 2.刪除信息請按2 5.撥號請按5 +"<<endl;
cout<<"+ 3.添加信息請按3 6.保存並退出請按6 +"<<endl;
cout<<"+ 7.查找信息請按7 8.輸出全部信息請按8 +"<<endl;
cout<<"+---------------------------------------------------------+"<<endl;
cout<<endl;
cout<<"請輸入您的的選擇-----"<<endl;
cin>>ch;
switch(ch) //選擇操作
{
case '1':
system("cls");
Show();
break;
case '2':
system("cls");
Delete();
break;
case '3':
system("cls");
Input();
break;
case '4':
system("cls");
Alter();
break;
case '5':
system("cls");
Dial();
break;
case '6':
system("cls");
Save();
fclose(fp);
xiaotu();
exit(0);
break;
case '7':
system("cls");
find();
break;
case '8':
system("cls");
shuchu();
break;
default:
printf("\n\t*********************************\n");
printf("\n\t 請輸入 1-8!!! \n");
printf("\n\t**********************************");
break;
}
}
while(1);
}
/***********************************************************
*功能描述: 添加一個人的信息;插入到鏈表
*輸入參數: 聯繫人信息
*輸出參數: 無
*返回值: 無
*其他說明: 會有判斷該人是否存在的功能;
若存在則有返回重新輸入或者回到主界面的功能.
*************************************************************/
void Input() //添加信息
{
int choic;
s=(linklist)malloc(sizeof(listnode)); //建立頭節點
cout<<"----------------------------------------------"<<endl;
printf("\n\n\t 請輸入該用戶的信息:\n");
cout<<"請輸入姓名: ";
cin>>s->name;
cout<<"請輸入電話: ";
cin>>s->tel_no;
cout<<"請設置快捷鍵(0-9): ";
cin>>s->sim_no;
cout<<"請輸入地址: ";
cin>>s->e_addr;
cout<<"請輸分組名 ";
cin>>s->arch;
s->cishu=0;
cout<<"----------------------------------------------"<<endl;
if(head==NULL)
printf("\n\n");
else
{
p8=head;
while(p8!=NULL&&strcmp(s->name,p8->name)!=0&&strcmp(s->tel_no,p8->tel_no)!=0)
p8=p8->next;
if(p8!=NULL)
{
cout<<"+----------------------------------------------+"<<endl;
cout<<"+------------您添加的用戶已存在!---------------+"<<endl;
cout<<endl;
cout<<"+ 重新輸入請按1,返回菜單請按 3 +"<<endl;
cout<<endl;
cout<<"+----------------------------------------------+"<<endl;
cin>>choic;
if(choic==1)
Input();
if(choic==3)
huanying();
free(s);
}
}
if(head==NULL)
{
head=s;
head->next=NULL;
}
else
{
r->next=s;
r=s;
r->next=NULL; //尾插法
}
}
/***********************************************************
*功能描述: 查找一個聯繫人信息的功能
*輸入參數: 聯繫人姓名
*輸出參數: 該聯繫人信息
*返回值: 無
*其他說明: 無
*************************************************************/
void find() //查找功能
{
int choic;
system("cls");
printf("\n\n\t 請輸入姓名:");
cin>>name1;
p10=head;
while(p10!=NULL&&strcmp(name1,p10->name)!=0) //判斷是否存在
p10=p10->next;
if(p10==NULL)
{
printf("\n\n\t 您選擇的用戶不存在!");
printf("\n\n\t2 請重新輸入,請選擇是重新輸入(1)還是返回主菜單(2)");
cin>>choic;
if(choic==1)
{
find();
}
if(choic==2)
{
system("cls");
huanying();
}
}
else
{
cout<<"----------------------------------------------"<<endl;
cout<<"+ 名 字: "<<p10->name<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"+ 電 話: "<<p10->tel_no<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"+ 快捷鍵: "<<p10->sim_no<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"+ 分 組: "<<p10->arch<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"+ 撥打次數: "<<p10->cishu<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"**********************************************"<<endl;
cout<<endl;
cout<<"返回界面請按1"<<endl;
cout<<endl;
cout<<"----------------------------------------------"<<endl;
cin>>choic;
if(choic==1)
{
system("cls");
huanying();
}
}
}
/***********************************************************
*功能描述: 編輯一個聯繫人的信息
*輸入參數: 聯繫人信息
*輸出參數: 無
*返回值: 無
*其他說明: 這裏運用了input()的功能,同樣有input()的判斷功能
*************************************************************/
void Alter() //編輯信息
{
int choic;
cout<<"+----------------------------------------------+"<<endl;
cout<<endl;
printf("\n\n\t 請輸入姓名:");
cin>>name1;
cout<<endl;
cout<<"+----------------------------------------------+"<<endl;
p3=head;
while(p3!=NULL&&strcmp(name1,p3->name)!=0)
p3=p3->next;
if(p3==NULL)
{
cout<<"+----------------------------------------------+"<<endl;
cout<<"+------------您選擇的用戶不存在!---------------+"<<endl;
cout<<endl;
cout<<"+ 重新輸入請按1,返回菜單請按 3 +"<<endl;
cout<<endl;
cout<<"+----------------------------------------------+"<<endl;
cin>>choic;
if(choic==1)
Alter();
if(choic==3)
huanying();
}
else
{
cout<<endl;
printf("\n\n\t 請輸入該用戶的新信息!");
cout<<"----------------------------------------------"<<endl;
printf("\n\n\t 請輸入該用戶的信息:\n");
cout<<"請輸入姓名:";
cin>>s->name;
cout<<"請輸入電話:";
cin>>s->tel_no;
cout<<"請設置快捷鍵(0-9):";
cin>>s->sim_no;
cout<<"請輸入地址:";
cin>>s->e_addr;
cout<<"請輸分組名";
cin>>s->arch;
s->cishu=0;
cout<<"----------------------------------------------"<<endl;
while(p9!=NULL&&strcmp(name1,p9->name)!=0&&strcmp(tel_no1,p9->tel_no)!=0)
p9=p9->next;
if(p9==NULL)
{
strcpy(p3->name,name1);
strcpy(p3->tel_no,tel_no1);
strcpy(p3->e_addr,e_addr1);
p3->sim_no=sim_no1;
strcpy(p3->arch,arch1);
}
else
{
cout<<"+----------------------------------------------+"<<endl;
cout<<"+------------您添加的用戶已存在!---------------+"<<endl;
cout<<endl;
cout<<"+ 返回菜單請按 1 +"<<endl;
cout<<endl;
cout<<"+----------------------------------------------+"<<endl;
cin>>choic;
if(choic==1)
{
system("cls");
huanying();
}
}
}
}
/***********************************************************
*功能描述: 進行對分組的選擇功能
*輸入參數: 分組名字
*輸出參數: 無
*返回值: 分組名字
*其他說明: 無
*************************************************************/
void Show() //選擇想要查看的分組
{
p2=head;
int choic;
char ch1[10];
if(p2==NULL) //若爲空
{
cout<<"----------------------------------------------"<<endl;
cout<<" 暫時沒有分組 "<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<" 按1返回主菜單 "<<endl;
cout<<"----------------------------------------------"<<endl;
cin>>choic;
if(choic==1)
huanying();
}
else
{
printf(" 你想要查看哪個分組? \n");
while(p2!=NULL) //通過不斷指向下一個節點讀取分組信息
{
cout<<"------------分組: "<<p2->arch<<endl;
p2=p2->next;
continue;
}
cout<<" 請輸入分組名字選擇 "<<endl;
cout<<" "<<endl;
cin>>ch1;
ShowA(ch1);
}
}
/***********************************************************
*功能描述:輸出一個分組的全部聯繫人的信息
*輸入參數: 選擇鍵
*輸出參數: 無
*返回值: 無
*其他說明: 無
*************************************************************/
void ShowA(char aa[10]) //打印分組聯繫人信息
{
int choic;
p11=head;
if(p11==NULL)
{
cout<<"----------------------------------------------"<<endl;
cout<<endl;
cout<<"該分組暫時沒人,返回界面請按1,繼續選擇請按3"<<endl;
cout<<endl;
cout<<"----------------------------------------------"<<endl;
cin>>choic;
if(choic==1)
huanying();
if (choic==3)
Show();
}
else
while(p11!=NULL)
{
if((strcmp(p11->arch,aa))==0)
{
cout<<"----------------------------------------------"<<endl;
cout<<"+ 名 字: "<<p11->name<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"+ 電 話: "<<p11->tel_no<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"+ 快捷鍵: "<<p11->sim_no<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"+ 分 組: "<<p11->arch<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"+ 撥打次數: "<<p11->cishu<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"**********************************************"<<endl;
}
p11=p11->next;
continue;
}
cout<<endl;
cout<<"返回界面請按1,繼續選擇請按3"<<endl;
cout<<endl;
cout<<"----------------------------------------------"<<endl;
cin>>choic;
if(choic==1)
{
system("cls");
huanying();
}
if (choic==3)
{
system("cls");
Show();
}
}
/***********************************************************
*功能描述: 刪除一個聯繫人的信息
*輸入參數: 聯繫人姓名
*輸出參數: 無
*返回值: 無
*其他說明: 先進行查找是否有該聯繫人
*************************************************************/
void Delete() //刪除通訊人信息
{
printf("\n\n\t 請輸入要刪除用戶的姓名:");
cin>>name1;
p4=head;
if(strcmp(p4->name,name1)==0)
{
p4=p4->next;
head=p4;
}
else
{
while(strcmp(p4->next->name,name1)!=0)
p4=p4->next;
p5=p4->next;
p4->next=p5->next;
free(p5);
}
}
/***********************************************************
*功能描述: 撥號動畫的功能;該聯繫人撥號次數+1
*輸入參數: 選擇鍵1、2;(1)輸入姓名、(2)輸入快捷鍵
*輸出參數: 聯繫人電話,撥號次數
*返回值: 撥號次數
*其他說明: 動畫過程用了時間函數
*************************************************************/
void Dial() //撥號功能
{
int c,choic;
int a;
char b;
cout<<"+----------------------------------------------+"<<endl;
cout<<"+ 撥叫用戶請按(1) 使用單鍵撥號請按(2) +"<<endl; //兩種撥號方式
cout<<"+----------------------------------------------+"<<endl;
cin>>a;
p0=head;
if(a==1)
{
cout<<" 請輸入撥叫用戶的姓名:";
cin>>name1;
while(strcmp(name1,p0->name)!=0&&p0!=NULL)
p0=p0->next;
if(p0==NULL)
{
cout<<"+----------------------------------------------+"<<endl;
cout<<" 您選擇的用戶不存在!";
cout<<"+----------------------------------------------+"<<endl;
cout<<"+ 重新輸入請按(1) 返回主菜單(2) +"<<endl;
cout<<"+----------------------------------------------+"<<endl;
cin>>choic;
if(choic==1)
{
system("cls");
Dial();
}
if(choic==2)
{
system("cls");
huanying();
}
}
else
{
cout<<endl;
cout<<" "<<endl;
cout<<" loding------ "<<endl;
for(int j=0; j<20; j++) //運用時間函數,實現撥號界面
{
Sleep(100);
cout<<"■";
}
cout<<" "<<endl;
cout<<" "<<endl;
Sleep(500);
cout<<endl;
cout<<p0->tel_no<<endl;
p0->cishu=p0->cishu+1;
cout<<"+----------------------------------------------+"<<endl;
cout<<"撥打次數: "<<p0->cishu<<endl;
cout<<"+----------------------------------------------+"<<endl;
cout<<endl;
}
}
else
{
cout<<"請輸入單鍵號碼:";
cin>>b;
while(p0!=NULL&&b!=p0->sim_no) //遍歷鏈表比較查詢
p0=p0->next;
if(p0==NULL)
{
cout<<" 您輸入的單鍵號碼不存在!";
cout<<"+----------------------------------------------+"<<endl;
cout<<"+ 重新輸入請按(1) 返回主菜單(2) +"<<endl;
cout<<"+----------------------------------------------+"<<endl;
cin>>choic;
if(choic==1)
{
find();
}
if(choic==2)
{
system("cls");
huanying();
}
}
else
{
cout<<endl;
cout<<" "<<endl;
cout<<" loding------ "<<endl;
for(int j=0; j<20; j++)
{
Sleep(100);
cout<<"■";
}
cout<<" "<<endl;
cout<<" "<<endl;
Sleep(500);
cout<<p0->name<<endl;
cout<<p0->tel_no;
p0->cishu=p0->cishu+1;
cout<<"+----------------------------------------------+"<<endl;
cout<<"撥打次數: "<<p0->cishu<<endl;
cout<<"+----------------------------------------------+"<<endl;
cout<<endl;
}
}
}
/***********************************************************
*功能描述: 輸出全部聯繫人的信息
*輸入參數: 無
*輸出參數: 信息
*返回值: 無
*其他說明: 無
*************************************************************/
void shuchu() //輸出全部信息
{
int choic;
p10=head;
while(p10!=NULL)
{
cout<<"----------------------------------------------"<<endl;
cout<<"+ 名 字: "<<p10->name<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"+ 電 話: "<<p10->tel_no<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"+ 快捷鍵: "<<p10->sim_no<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"+ 分 組: "<<p10->arch<<endl;
cout<<"----------------------------------------------"<<endl;
cout<<"+ 撥打次數: "<<p10->cishu<<endl;
cout<<"----------------------------------------------"<<endl;
p10=p10->next; //遍歷輸出信息
continue;
}
cout<<endl;
cout<<"返回界面請按1,繼續選擇請按3"<<endl;
cout<<endl;
cout<<"----------------------------------------------"<<endl;
cin>>choic;
if(choic==1)
huanying();
if (choic==3)
Show();
}
/***********************************************************
*功能描述:輸出兔子圖案
*輸入參數: 無
*輸出參數: 無
*返回值: 無
*其他說明: 無
*************************************************************/
void xiaotu() //兔子圖案
{
cout<<endl;
cout<<" ┏━┓ ┏━┓"<<endl;
cout<<" ★│┃ ┃│┃"<<endl;
cout<<" ┃│┗灬┛│┃"<<endl;
cout<<" ┃ ┃"<<endl;
cout<<" ┃ ^ ^ ┃"<<endl;
cout<<" ﹌ ˇ ﹌ "<<endl;
cout<<" ┗○━━━○┛"<<endl;
}
/***********************************************************
*功能描述: 將操作完成後的信息存儲到文件
*輸入參數: 無
*輸出參數: 無
*返回值: 無
*其他說明: 方便下次運行時的調用
*************************************************************/
void Save() //存入文件
{
int j;
fp=fopen("數據文件.txt","w");
for(p2=head,j=0; p2!=NULL; j++ ,p2=p2->next)
{
strcpy(persons[j].name,p2->name);
strcpy(persons[j].tel_no,p2->tel_no);
persons[j].sim_no=p2->sim_no;
strcpy(persons[j].e_addr,p2->e_addr);
strcpy(persons[j].arch,p2->arch);
persons[j].cishu=p2->cishu;
fwrite(&persons[j],sizeof(struct persons),1,fp);
}
}
<pre name="code" class="cpp">/***********************************************************
*版權所有 (C)2015. ChengAng
*
*文件名稱: zupu.cpp
*文件標識: 無
*內容摘要: 該文件用於對結構體以及各函數的定義
*其他說明: 無
*當前版本: V1.0
*作 者: 程昂
*完成日期: 20151223
*
*修改記錄1:
*修改日期: 20151223
*版本號: V1.0
*修改人: Cheng Ang
*修改內容:
********************************************************************/
#include <iostream>
#include<stdlib.h>
#include<windows.h>
#include<stdio.h>
using namespace std;
#define maxlen 100 //最多100個信息
void find(); //查找功能
void huanying(); //選擇界面
void creat(); //創建或打開文件
void ShowA(char aa[10]); //顯示分組信息
void Show(); //選擇分組
void Delete(); //刪除功能
void find(); //查找功能
void Save(); //存入文件
void Input(); //添加信息
void xiaotu(); //兔子圖案
void shuchu(); //輸出全部信息
void Alter(); //編輯信息
void Dial(); //撥號功能
//存放通訊表的結構體數組peisons[maxlen]的定義
struct persons
{
int num;
char name[20]; //姓名
char e_addr[20]; //地址
char tel_no[15]; //電話
char sim_no; //快捷鍵
char arch[10]; //分組
int cishu; //撥打次數
} persons[maxlen];
//存放通訊表的鏈表的節點類型 listnode 的定義
typedef struct lnode
{
int num;
char name[20]; //姓名
char e_addr[20]; //地址
char tel_no[15]; //電話
char sim_no; //快捷鍵
char arch[10]; //分組
int cishu; //撥打次數
struct lnode *next; //儲存指向下一個人的指針
} listnode, *linklist;
linklist head=NULL,r=NULL; //初始化鏈表
listnode *s,*p0,*p1,*p2,*p3,*p4,*p5,*p6,*p7,*p8,*p9,*p10,*p11,*p12; //定義指針
//結構體外信息
int i;
char name1[10],ch;
char tel_no1[15];
char arch1[10];
char sim_no1;
char e_addr1[20];
int cishu_1=0;
FILE *fp; //定義文件指針
<img src="https://img-blog.csdn.net/20151225230006811?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /><img src="https://img-blog.csdn.net/20151225230053193?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" style="font-family: Arial, Helvetica, sans-serif;" alt="" />
<img src="https://img-blog.csdn.net/20151225230141170?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /><img src="https://img-blog.csdn.net/20151225230153784?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
<img src="https://img-blog.csdn.net/20151225230203081?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />