通讯录管理系统源代码

合集下载

通讯录管理系统调试源代码

通讯录管理系统调试源代码

通讯录管理系统调试源代码预览说明:预览图片所展示的格式为文档的源格式展示,下载源文件没有水印,内容可编辑和复制#include#include#include#include#includeusing namespace std;#define FILENAME "C:\\\\phonebook.txt"class Person{public:string name;string sex;string address;stringtel;stringshuxing;Person(string na){name=na;}Person(string na,stringse,stringadd,stringte,stringsx){name=na;sex=se;address=add;tel=te;shuxing=sx;}void display(){cout<<name<<" "<<address<<"="" "<<sex<<"="" "<<shuxing<<endl;<="" "<<tel<<"="" p="">}void add_Person1();void add_Person2();voidlist_Person();void Reach();voiddelete_Person();voiddisplay_diff();voidrenew_Person();};int main(){Person person1("hh");loop:cout<<"\★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★\"<<endl;< p="">cout<<"\★★**********************欢迎使用通讯录系统******************* ★★\"<<endl;< p="">cout<<"\★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★\"<<endl;< p="">cout<<"\★★************************************************* ***********★★"<<endl;< p="">cout<<"\★★ 1.查看所有联系人2.查找联系人3.添加联系人★★\"<<endl;< p="">cout<<"\★★************************************************* ***********★★\"<<endl;< p="">cout<<"\★★ 4.删除联系人5.修改联系人6.显示类别联系人★★\"<<endl;< p="">cout<<"\★★************************************************* ***********★★\"<<endl;< p="">cout<<"\★★7.退出程序★★\"<<endl;< p="">cout<<"\★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★\"<<endl;< p="">cout<<"\ 开发者:"<<"黄龙吉"<<" "<<"张帆"<<" "<<"陈续旭"<<" "<<"程传奇"<<endl;< p="">cout<<"请输入菜单选项:";int a;do{cin>>a;if(a<0||a>8)cout<<"输入有误请重新输入!(1-7)"<<endl;< p=""> } while(a<0||a>8);switch(a){case 1: //显示所有联系人{system("cls");person1.list_Person();system("pause");system("cls");break;}case 2: //按姓名搜索 {system("cls");person1.Reach();system("pause");system("cls");break;}case 3: //添加联系人 { system("cls");person1.add_Person2();system("pause");system("cls");break;}case 4: //删除联系人{ system("cls");person1.delete_Person();system("pause");system("cls");break;}case 5: //修改联系人信息 { system("cls"); person1.renew_Person();system("pause");system("cls");break;}case 6: //按类别显示{ system("cls"); person1.display_diff();system("pause");system("cls");break;}case 7:{//退出break;}default:break;}if (a!=7){goto loop;}return 0;}void Person::add_Person1(){ofstreamfout;fout.open(FILENAME,ios::app);//文件不存在时会主动创建if (fout.fail()){cerr<<"open file with write error"<<endl;< p="">}fout<<name<<" "<<address<<"="" "<<sex<<"="" "<<shuxing<<endl;<="" "<<tel<<"="" p="">fout.close();}void Person::add_Person2(){string name;string sex;string address;stringtel;stringshuxing;ofstreamfout;fout.open(FILENAME,ios::app);//文件不存在时会主动创建if (fout.fail()){cerr<<"open file with write error"<<endl;< p="">}cout<<"请输入姓名:"<<endl;< p="">cin>>name;cout<<"请输入性别:"<<endl;< p="">cin>>sex;cout<<"请输入地址:"<<endl;< p="">cin>>address;cout<<"请输入电话:"<<endl;< p="">cin>>tel;cout<<"请输入属性:"<<endl;< p="">cin>>shuxing;fout<<setw(19)<<left<<name<<setw(5)<<left<<sex<<set w(13)<<left<<<setw(14)<<left<<tel<<setw(10)<<left<<shuxi ng<<endl;<="" p="">fout.close();}void Person::list_Person(){ //全部显示记录//read from fileifstream fin(FILENAME);if (fin.fail()){cerr<< "open file with read error" <<endl;< p="">_exit(-127);}//////////////////////////string s;//存储返回的字符串,即一行的内容//fin.seekg(20,ios::cur);cout<<"================================= ===================="<<endl;< p="">cout<<setw(19)<<left<<"姓名"<<setw(8)<<left<<"性别"<<setw(14)<<left<<"地址"<<setw(9)<<left<<"电话"<<setw(15)<<left<<"属性"<<endl<<endl;< p="">while(getline(fin,s)){//cout<<s.length()<<endl;< p="">cout<<s<<endl;< p="">}cout<<"================================= ===================="<<="" p="">}void Person::Reach(){ //查找记录ifstreaminput_file;char h[100];string s;string name;cout<<"请输入要查找人的姓名:"<<endl;< p="">cin>>name;input_file.open(FILENAME);if(!input_file){cout<<"Codefile.txt can't open file!"<<endl;< p="">return ;}int flag=0;while(input_file>>h){ //使用文件读取来判断文件是否到末尾//字符串运算使用双等于来比较比使用函数更方便if(h==name){cout<< h;getline(input_file,s);cout<<s<<endl;< p="">}else{flag=1;}}if(flag)cout<<"对不起通讯录中没有"+name+"的信息!"<<endl;< p="">input_file.close();//在c++中字符数组可以直接跟字符串作比较}void Person::delete_Person() //删除记录{ifstream fin(FILENAME);ofstreamfout("temp.txt");if (fin.fail()){cerr<< "open file with read error" <<endl;< p="">_exit(-127);}charch;//fin.seekg(20,ios::cur);while(fin.get(ch))//cout<<s.length()<<endl;< p="">fout.put(ch);cout<<="">cout<<"================================= ===================="<<="" p="">fout.close();ifstreamfinfile("temp.txt");ofstreamfoutfile(FILENAME);char h[100];string s;string name;cout<<"请输入要删除人的姓名:"<<endl;< p="">cin>>name;string name1;if(!finfile){cout<<"Codefile.txt can't open file!"<<endl;< p="">return ;}int flag=0;while(finfile>>h){ //使用文件读取来判断文件是否到末尾//字符串运算使用双等于来比较比使用函数更方便if(h!=name){foutfile<<h<<" ";<="" p="">getline(finfile,s);foutfile<<s<<endl;< p="">}else{flag=1;name1=name;getline(finfile,s);}}if(flag==1)cout<<"联系人"+name1+"已经被删除!"<<endl;< p=""> elsecout<<"对不起通讯录中无联系人"+name+"!"<<endl;< p=""> }void Person::renew_Person(){ifstream fin(FILENAME);ofstreamfout("temp.txt");if (fin.fail()){cerr<< "open file with read error" <<endl;< p="">_exit(-127);}charch;//fin.seekg(20,ios::cur);while(fin.get(ch))//cout<<s.length()<<endl;< p="">fout.put(ch);cout<<="">cout<<"================================= ===================="<<="" p="">fout.close();ifstreamfinfile("temp.txt");ofstreamfoutfile(FILENAME);char h[100];string s;string name;cout<<"请输入要修改的姓名:"<<endl;< p="">cin>>name;string name1;int flag;if(!finfile){cout<<"Codefile.txt can't open file!"<<endl;< p="">return ;}while(finfile>>h){ //使用文件读取来判断文件是否到末尾//字符串运算使用双等于来比较比使用函数更方便if(h!=name){foutfile<<h;< p="">getline(finfile,s);foutfile<<s<<endl;< p="">}else{flag=1;getline(finfile,s);string name;string sex;stringtel;string address;stringshuxing;cout<<"请输入记录:"<<endl;< p="">cout<<"姓名:";cin>>name;name1=name;cout<<"性别:";cin>>sex;cout<<"地址:";cin>>address;cout<<"电话:";cin>>tel;cout<<"属性:";cin>>shuxing;foutfile<<setw(19)<<left<<name<<setw(5)<<left<<sex<< setw(13)<<left<<address<<setw(14)<<left<<tel<<setw(10)<<left<<shuxing<< endl;<="" p="">}}if(flag==1)cout<<"联系人"+name+"已经成功修改为"+name1+"!"<<endl;< p="">elsecout<<"通讯录中没有联系人"+name+" 无法进行修改!"<<endl;< p="">}void Person::display_diff(){//分类显示函数ifstreaminfile(FILENAME);char name[100];char sex[100];chartel[100];charsx[100];char add[100];stringshuxing;cout<<"请输入想要查询的类型:"<<endl;< p="">cin>>shuxing;while(infile>>name){infile>>sex;infile>>add;infile>>tel;infile>>sx;if(sx==shuxing){cout<<setw(19)<<left<<name<<setw(5)<<left<<sex<<set w(13)<<left<<<setw(14)<<left<<tel<<setw(10)<<left<<shuxi ng<<endl;<="" p="">}}infile.close();}</setw(19)<<left<<name<<setw(5)<<left<<sex<<setw(13 )<<left<</endl;<></endl;<></endl;<></setw(19)<<left<<name<<setw(5)<<left<<sex<<setw(13 )<<left<<></endl;<></s<<endl;<></h;<></endl;<></endl;<></s.length()<<endl;<></endl;<></endl;<></endl;<></s<<endl;<></h<<"></endl;<></endl;<></s.length()<<endl;<></endl;<></endl;<></s<<endl;<></endl;<></endl;<></s<<endl;<></s.length()<<endl;<></setw(19)<<left<<"姓名"<<setw(8)<<left<<"性别"<<setw(14)<<left<<"地址"<<setw(9)<<left<<"电话"<<setw(15)<<left<<"属性"<<endl<<endl;<></endl;<></endl;<></setw(19)<<left<<name<<setw(5)<<left<<sex<<setw(13 )<<left<</endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></name<<"></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></name<<">。

(完整word版)个人通讯录管理系统源代码

(完整word版)个人通讯录管理系统源代码

个人通讯录管理系统import javax。

swing。

*;import java。

awt.*;import java。

awt.event。

*;import java.io.*;public class TongXunLu {public static void main(String[] args) {new menu();}}class menu implements ActionListener{JMenuItem zengjia,suoyou,beifen,quit,select,del;JFrame f;Container con;JMenuBar bar;String str1,str2,str3;JFileChooser fc1 = new JFileChooser();File fc2=new File("D://test。

txt”);menu(){f=new JFrame(”通讯录管理系统");f。

setDefaultCloseOperation(JFrame。

DISPOSE_ON_CLOSE);f。

setSize(500, 400);f。

setLocation(130, 150);con=f。

getContentPane();Color c=Color。

YELLOW ;Font fo=new Font("黑体",Font.BOLD,40); JPanel pan=new JPanel();JLabel lab=new JLabel(”通讯录管理系统");lab.setForeground(c);lab.setFont(fo);pan.add(lab);con。

add(pan);bar=new JMenuBar();f。

setJMenuBar(bar);JMenu menu1=new JMenu("文件"); JMenu menu2 =new JMenu(”查询"); JMenu menu3 =new JMenu("删除");zengjia=new JMenuItem("增加记录");suoyou=new JMenuItem(”所有记录”);beifen=new JMenuItem(”文件备份”);quit=new JMenuItem(”退出");select=new JMenuItem(”查询");del=new JMenuItem("删除");menu1.add(zengjia);(完整word版)个人通讯录管理系统源代码menu1。

通讯录管理系统c语言课程设计代码

通讯录管理系统c语言课程设计代码

通讯录管理系统C语言课程设计代码
一、引言
在现代社会中,通讯方式多样化且频繁,通讯录管理系统应运而生。

本文将介
绍一个基于C语言设计的通讯录管理系统的代码实现。

通讯录管理系统可以帮助
用户有效地管理联系人信息,实现增删改查等操作。

二、系统功能设计
通讯录管理系统主要包括以下功能: 1. 添加联系人:用户可以输入联系人姓名、电话号码等信息,将联系人信息添加到通讯录中。

2. 删除联系人:用户可以根据
姓名或电话号码删除指定联系人信息。

3. 修改联系人:用户可以修改已有联系人
的信息,包括姓名、电话号码等。

4. 查询联系人:用户可以根据姓名或电话号码
查询联系人信息。

5. 显示所有联系人:用户可以查看通讯录中所有联系人的信息。

三、代码实现
```c #include <stdio.h> #include <string.h>
#define MAX_CONTACTS 100 #define MAX_NAME_LENGTH 50 #define
MAX_PHONE_LENGTH 15
struct Contact { char name[MAX_NAME_LENGTH]; char
phone[MAX_PHONE_LENGTH]; };
struct Contact contacts[MAX_CONTACTS]; int numContacts = 0;
void addContact() { if (numContacts < MAX_CONTACTS) { printf(。

(完整word版)通讯录管理系统源代码

(完整word版)通讯录管理系统源代码

源代码:#include "stdio.h"#include ”stdlib。

h"#include "string.h”#include "conio.h”#include "stdlib.h”#define null 0struct record{char name[20];char phone[20];char adress[40];char postcode[10];char e_mail[30];}student[500];struct LinkList{struct record US;struct LinkList *next;}a;struct LinkList *head=null;int num=0;FILE *fp;int menu_select();int adduser();int list();int search();int display();int add();int listbyname();int dele();int save();int exit();void main(){system(”cls”);for(;;){switch(menu_select()){case 0:adduser();break;case 1:list();break;case 2:search();break;case 3:display();break;case 4:add();break;case 5:listbyname();break;case 6:dele();break;case 7:save();break;case 8:exit(0);}}}menu_select(){char s[80];int a;printf("*_* press any key enter menu!*_*\n");getch();system(”cls”);printf(”\t\t********************MENU*********************\n\n");printf("\t\t 0。

个人通讯录管理系统C语言源程序(优秀版)

个人通讯录管理系统C语言源程序(优秀版)

#include <stdio.h> /*头文件*/#include <stdlib.h> //包含最常用的系统函数#include <string.h> //关于字符数组的函数定义的头文件#include <conio.h> //控制台输入输出//定义结构体struct tongxunlu /*定义通讯录结构体变量*/{char xingming[20]; /*定义输入名字的数组*/char dianhua[20]; /*定义输入电话号码的数组*/char dizhi[40]; /*定义输入地址的数组*/} txl[100]; //默认100个数据int n=0;//记录数据联系人数量FILE *fp; /*定义文件*///程序用到的所有函数void zhucaidan(); /*主菜单函数*/void zengjia(); /*增加联系人函数*/void readfile(); /*文件中读入函数*/void writefile(); /*文件中写入函数*/void xiugai(); /*修改联系人函数*/void xiugai_xingming(); /*姓名修改*/void xiugai_dianhua(); /*电话号码修改*/void chazhao(); /*查找联系人函数*/void chazhao_xingming(); /*按姓名查找*/void chazhao_dianhua(); /*按号码查找*/void shanchu(); /*删除联系人函数*/void shanchu_quanbu(); /*全部删除*/void shanchu_dange(); /*单个删除*/void xianshi(); /*号码显示*///程序主函数模块六void main() /*主函数main*/{ readfile(); /*读入文件*/while(1) /* 循环(永远进行)*/{zhucaidan(); /*调用主菜单函数*/}}//读取文件函数部分开始模块七void readfile(){if((fp=fopen("c:\\通讯录.txt","r"))==NULL) /*以只读方式打开判定文件是否为空*/ {printf("\n\t\t\t 通讯录文件不存在"); /*判断结论*/if ((fp=fopen("同通讯录.txt","w"))==NULL) /*只写方式判断*/{printf("\n\t\t建立失败"); /*为空结论*/exit(0); /*退出*/}else /*不为空则执行else*/{printf("\n\t-----------------欢迎使用通讯录管理系统------------------");printf("\n\t 通讯录文件已建立");printf("\n\t 按任意键进入主菜单");printf("\n\t---------------------------------------------------------");getch();return ;}exit(0);}fseek(fp,0,2); /*文件位置指针移动到文件末尾*/if (ftell(fp)>0) /*文件不为空*/{rewind(fp); /*文件位置指针移动到文件开始位置*/for (n=0;!feof(fp) && fread(&txl[n],sizeof(struct tongxunlu),1,fp);n++);printf("\n\t----------欢迎使用通讯录管理系统1.0beat版----------------");printf("\n\t 文件导入成功");printf("\n\t 按任意键返回主菜单");printf("\n\t---------------------------------------------------------");getch();return;}printf("\n\t------------欢迎使用通讯录管理系统1.0beat版--------------");printf("\n\t 文件导入成功");printf("\n\t 通讯录文件中无任何纪录");printf("\n\t 按任意键返回主菜单");printf("\n\t---------------------------------------------------------");getch();return;}//读取文件函数结束//文件主菜单函数开始模块六void zhucaidan(){char c;system("cls");printf("\n\t\t|------- 欢迎您使用通讯录管理系统1.0beat版-----|");printf("\n\t\t| 1-添加联系人2-查询和显示联系人|");printf("\n\t\t| 3-删除联系人4-修改联系人|");printf("\n\t\t| 5-保存退出0-不保存退出|");printf("\n\t\t|------------------------------------------------|");printf("\n\t\t请选择您所所要的服务:");c=getch();switch (c) /*对于上边的选择项目*/{case '1':zengjia();break;case '2':chazhao();break;case '3':shanchu();break;case '4':xiugai();break;case '5':writefile();break;case '0':exit(0);default:zhucaidan(); /*如果没有则返回主菜单等待输入*/}}//文件主菜单函数结束//添加新联系人函数开始模块一void zengjia(){printf("\n\t\t------------------ 请输入联系人信息--------------------\n");printf("\n\t\t输入联系人姓名:");scanf("%s",txl[n].xingming); /*键盘输入*/printf("\n\t\t输入联系人电话号码:");scanf("%s",txl[n].dianhua);printf("\n\t\t输入联系人地址:");scanf("%s",txl[n].dizhi);n++; /*统计个数*/printf("\n\t\t是否继续添加联系人?(Y/N):"); /*是否继续输入联系人.*/ if (getch()=='y')zengjia();return;}//添加新联系人结束//写入文件函数开始模块七void writefile() /*联系人写入文件*/{int i;if ((fp=fopen("c:\\通讯录.txt","w"))==NULL){printf("\n\t\t文件打开失败");}for (i=0;i<n;i++){if (fwrite(&txl[i],sizeof(struct tongxunlu),1,fp)!=1){printf("\n\t\t写入文件错误!\n");}}fclose(fp); /*关闭文件*/printf("\n\t------------------------------------------------------"); /*输出提示信息*/printf("\n\t\t通讯录文件已保存");printf("\n\t\t谢谢使用,欢迎再次使用!\n");printf("如果对本软件有疑问,请到我们官网()提出您的问题,我们将为您解答.\n");printf("我们的软件有不足之处,欢迎到官网()反映,我们将努力改正!");printf("\n\t\t按任意键退出程序\n\t\t"); /*输出完毕*/exit(0);printf("\n\t------------------------------------------------------");}//写入文件函数结束///查询联系人函数开始模块四----------------------------------------------------void chazhao(){char c;system("cls");printf("\n\t\t------------------- 显示和查询联系人------------------");printf("\n\t\t| 1-逐个显示所有2-按姓名查询|");printf("\n\t\t| 3-按电话查询4-返回主菜单|");printf("\n\t\t|------------------------------------------------------");printf("\n\t\t请选择您所所要的服务:");c=getch();switch (c){case '1':xianshi();break; /*显示所有号码*/case '2':chazhao_xingming();break; /*调用按姓名查询函数*/case '3':chazhao_dianhua();break; /*调用按号码查询函数*/case '4':zhucaidan();break; /*主菜单*/}}void xianshi()//显示所有联系人函数{int i;system("cls");//清楚屏幕if(n!=0){printf("\n\t\t----------欢迎您查询通讯录所有联系人信息-------------");for (i=0;i<n;i++) /*依次序显示*/{printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t--------------------------------------------------");if (i+1<n){printf("\n\t\t-----------------------");system("pause");//返回错误信息}}printf("\n\t\t---------------------------------------------");}else /*无联系人*/printf("\n\t\t通讯录中无任何纪录");printf("\n\t\t按任意键返回主菜单:");getch();return;}//按号码查询函数void chazhao_dianhua(){int mark=0;int i;char phone[15];printf("\n\t\t------------------- 按电话查找-------------------------");printf("\n\t\t请输入电话号码:");scanf("%s",phone);for(i=0;i<n;i++){if (strcmp(txl[i].dianhua,phone)==0)//对比查找函数{printf("\n\t\t------------ 以下是您查找的学生信息------------");printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t------------------------------------------------");printf("\n\t\t按任意键返回主菜单:");mark++;getch();return;}}if (mark==0){printf("\n\t\t没有找到联系人的信息");printf("\n\t\t按任意键返回主菜单");getch();return;}}void chazhao_xingming()//按姓名查询{int mark=0;int i;char name[20];printf("\n\t\t----------------按姓名查找--------------------");printf("\n\t\t请输入您要查找的姓名:");scanf("%s",name);for(i=0;i<n;i++){if (strcmp(txl[i].xingming,name)==0){printf("\n\t\t------------ 以下是您查找的联系人信息---------------");printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t---------------------------------------------------");mark++;getch();return;}}if (mark==0){printf("\n\t\t没有找到联系人的信息");printf("\n\t\t按任意键返回主菜单");getch();return;}}////查询联系人函数结束-----------------------------------------------------////删除联系人函数部分开始-------------------------------------------------void shanchu(){char c;if(n==0) /*如果通讯录中没有一个记录输出以下部分*/{printf("\n\t\t对不起,文件中无任何纪录");printf("\n\t\t按任意键返回主菜单");getch();return;}system("cls"); /*清屏*/printf("\n\t\t----------------- 删除菜单----------------------");printf("\n\t\t| 1-删除所有2-删除单个|");printf("\n\t\t| 3-返回主菜单|");printf("\n\t\t|-------------------------------------------------");printf("\n\t\t请选择您所所要的服务:");c=getch(); /*输入的赋予choice*/switch (c){case '1':shanchu_quanbu();break;case '2':shanchu_dange();break;case '3':zhucaidan();break;default:zhucaidan();break;}}void shanchu_quanbu()//删除所有联系人{printf("\n\t\t确认删除?(y/n)");if (getch()=='y'){fclose(fp);if ((fp=fopen("通讯录.txt","w"))==NULL) /*文件空输出*/{printf("\n\t\t不能打开文件,删除失败");readfile();}n=0;printf("\n\t\t纪录已删除,按任意键返回主菜单");getch();return;}elsereturn;}void shanchu_xingming()//按姓名删除联系人{int i,m,mark=0,a=0;char name[20];printf("\n\t\t请输入要删除联系人姓名:");scanf("%s",name); /*键盘输入姓名*/for (i=a;i<n;i++){if (strcmp(txl[i].xingming,name) == 0) //对比字符串查找到要删除的联系人{printf("\n\t\t以下是您要删除的联系人纪录:");printf("\n\t\t--------------------------------");printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t--------------------------------");printf("\n\t\t是否删除?(y/n)");if (getch()=='y') // 实现删除功能{for (m=i;m<n-1;m++)txl[m]=txl[m+1]; /*将通讯录的想前移*/n--;mark++;printf("\n\t\t删除成功");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')shanchu_xingming(); /*继续调用删除函数*/return;}elsereturn;}continue;}if (mark==0){printf("\n\t\t没有该联系人的纪录");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')shanchu_xingming();return;}}void shanchu_dianhua()//按电话号码删除联系人{int i,m,mark=0; /*变量定义*/char phone[20];printf("\n\t\t请输入要删除联系人电话号码:");scanf("%s",phone);if(n==0){printf("\n\t\t对不起,文件中无任何纪录");printf("\n\t\t按任意键返回主菜单");getch();return;}for (i=0;i<n;i++){if (strcmp(txl[i].dianhua,phone)==0){printf("\n\t\t以下是您要删除的联系人纪录:");printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t是否删除?(y/n)");if (getch()=='y'){for (m=i;m<n-1;m++) //递推替换实现删除txl[m]=txl[m+1];n--;mark++; //记录删除次数printf("\n\t\t删除成功");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')shanchu_dianhua();return;}elsereturn;}continue;}if (mark==0){printf("\n\t\t没有该联系人的纪录");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')return ;}}void shanchu_dange()//删除单个联系人{char c;printf("\n\t----------------------------------------------------------");printf("\n\t\t 1-按姓名删除2-按电话删除");printf("\n\t\t请选择您所所要的服务:");printf("\n\t----------------------------------------------------------");c=getch();switch (c){case '1':shanchu_xingming();break;case '2':shanchu_dianhua();break;}}///删除函数部分结束--------------------------------------------------------///修改联系人函数开始--------------------------------------------------void xiugai() /*修改函数*/{char c;if(n==0){printf("\n\t\t对不起,文件中无任何纪录");printf("\n\t\t按任意键返回主菜单");getch();return;}system("cls");printf("\n\t\t-----------------修改联系人菜单-----------------------");printf("\n\t\t| 1-按姓名修改2-按电话修改|");printf("\n\t\t| 任意键-按返回主菜单|");printf("\n\t\t------------------------------------------------------");c=getch();switch(c){case '1':xiugai_xingming();break;case '2':xiugai_dianhua();break;default:zhucaidan();break;}}void xiugai_xingming(){char c;int i,mark=0;char name[20];printf("\n\t\t请输入要修改的联系人姓名:");scanf("%s",name);if(n==0){printf("\n\t\t文件中无任何联系人");printf("\n\t\t按任意键返回主菜单");getch(); mark++;return;}for(i=0;i<n;i++){if(strcmp(txl[i].xingming,name)==0){printf("\n\t\t以下是您要修改的联系人信息");printf("\n\t\t姓名: %s",txl[i].xingming);printf("\n\t\t电话: %s",txl[i].dianhua);printf("\n\t\t地址: %s",txl[i].dizhi);printf("\n\t\t是否修改(y/n)");if(getch()=='y'){printf("\n\t------------请选择修改信息---------------");printf("\n\t 1-修改姓名2-修改电话");printf("\n\t 3-修改地址");printf("\n\t-----------------------------------------");printf("\n\t请选择您所所要的服务:");scanf("%s",&c);switch(c){case '1': printf("\n\t请输入新姓名:");scanf("%s",txl[i].xingming);break;case'2':printf("\n\t请输入新电话:%s");scanf("%s",txl[i].dianhua);break;case'3':printf("\n\t请输入新地址: ");scanf("%s",txl[i].dizhi);break;}}}}if(mark==0){printf("\n\t\t没有找到联系人信息");printf("\n\t是否继续修改?(Y/N):");if(getch()=='y')xiugai_xingming();return;}}void xiugai_dianhua(){char c,phone[15];int i,mark=0;printf("\n\t\t请输入要修改联系人的号码:");scanf("%s",phone);if(n==0){printf("\n\t\t文件中无任何联系人");printf("\n\t\t按任意键返回主菜单");getch();mark++;return;}for(i=0;i<n;i++){if(strcmp(txl[i].dianhua,phone)==0){printf("\n\t\t以下是您要修改的联系人信息");printf("\n\t\t姓名: %s",txl[i].xingming);printf("\n\t\t电话: %s",txl[i].dianhua);printf("\n\t\t地址: %s",txl[i].dizhi);printf("\n\t\t是否修改(y/n)");if(getch()=='y'){printf("\n\t------------请选择修改信息---------------");printf("\n\t 1-修改姓名2-修改电话");printf("\n\t 3-修改地址");printf("\n\t-----------------------------------------");printf("\n\t请选择您所所要的服务:");scanf("%s",&c);switch(c){case'1': printf("\n\t请输入新姓名:");scanf("%s",txl[i].xingming);break;case'2':printf("\n\t请输入新电话:");scanf("%s",txl[i].dianhua);break;case'3':printf("\n\t请输入新地址: ");scanf("%s",txl[i].dizhi);break;}}}}if(mark==0){printf("\n\t没有该联系人信息");printf("\n\t是否继续修改?(Y/N):");if(getch()=='y')xiugai_dianhua();return;}}其中专业理论知识内容包括:保安理论知识、消防业务知识、职业道德、法律常识、保安礼仪、救护知识。

C语言通讯录管理系统程序代码

C语言通讯录管理系统程序代码

C语言通讯录管理系统程序代码————————————————————————————————作者:————————————————————————————————日期:一、课程设计题目及要求题目通讯录管理系统任务:自学C语言中相关知识,设计出通讯录管理系统。

要求如下所述:◆建立通讯录信息,信息至少包含编号、姓名、年龄、电话、通讯地址、电子邮箱等;;◆能够提供添加、删除和修改通讯录信息的功能;◆能够提供按姓名或电话等查询;◆将通讯录保存在文件中;◆能够按表格方式输出通讯录信息。

二、系统设计方案(一)总体框架图:通讯录管理系统:1、录入通讯录信息2、修改通讯录信息3、查询通讯录信息4、浏览通讯录信息5、增加通讯录信息6、推出系通讯录统(二)模块设计模块一:头文件,变量定义,函数的声明对系统所使用的变量进行定义,对函数进行声明模块二:录入通讯录信息声明函数void readfile(),说明一个文件指针FILE *fp 打开文件"student.txt"模块三:通讯录信息的查找声明void seek()为查找函数,通过switch(item)设定用学号查找,用姓名查找两个分支模块四:通讯录信息的修改声明void modify()为学生信息修改函数,通过switch(item)设定所要修改的项目模块五:通讯录信息按学号排序声明void sort()将录入通讯录信息系按升序排列,用的是“冒泡排序法”实现排序模块六:加通讯录信息声明void insert()插入通讯录信息,先通过判断通讯录是否存在,若否则继续输入,若是跳出,重新循环模块七:通讯录信息声明void del()实现通讯录信息删除,通过学号对比确定要删除的信息,然后用后一个替换掉。

模块八:示学生信息通过display()函数输出通讯录信息模块九;存信息通过fp=fopen("student.txt","w");写入信息模块十:界面菜单通过switch(num)调用,以上各函数,实现功能三、设计详情1. 主函数主函数设计要求简洁,只提供部分提示语和函数的调用【程序】图1. 主函数流程图 显示一系列输入n ,判断n根据n 的值调用各功能结束开始Nvoid menu()/* 界面*/{ int num;printf(" \n\n 自动化0901通讯录管理系统\n\n");printf(" ***************** \n\n");printf(" * 制作人:翁行兴* \n \n");printf(" ***************** \n\n");printf("*********************系统功能菜单************************ \n");printf(" ---------------------- ---------------------- \n");printf(" * 1.刷新学生信息* * 2.查询学生信息* \n");printf(" * 3.修改学生信息* * 4.增加学生信息* \n");printf(" * 5.按学号删除信息* * 6.显示当前信息* \n");printf(" * 7.保存当前学生信息* * 8.退出系统* \n");printf(" ---------------------- ---------------------- \n");printf("请选择菜单编号:");scanf("%d",&num);switch(num){case 1:readfile();break;case 2:seek();break;case 3:modify();break;case 4:insert();break;case 5:del();break;case 6:display();break;case 7:save();break;case 8:k=0;break;default:printf("请在1-8之间选择\n");}}四、源代码#include<stdio.h>#include<stdlib.h>#include<string.h>#define BUFLEN 100#define LEN 15#define N 100struct record /*结构体*/{char code[LEN+1]; /* 学号*/char name[LEN+1]; /* 姓名*/int age; /* 年龄*/char sex[3]; /* 性别*/char time[LEN+1]; /* 出生年月*/ char add[30]; /* 家庭地址*/char tel[LEN+1]; /* 电话号码*/char mail[30]; /* 电子邮件地址*/ }stu[N];int k=1,n,m; /* 定义全局变量*/ void readfile();/* 函数声明*/void seek();void modify();void insert();void del();void display();void save();void menu();int main(){while(k)menu();system("pause");return 0;}void readfile()/* 建立信息*/{char *p="student.txt";FILE *fp;int i=0;if ((fp=fopen("student.txt","r"))==NULL){printf("Open file %s error! Strike any key to exit!",p);system("pause");exit(0);}while(fscanf(fp,"%s %s%d%s %s %s %s %s",stu[i].code,stu[i].name,&stu[i].age, stu[i].sex,stu[i].time,stu[i].add,stu[i].tel,stu[i].mail)==8){i++; i=i;}fclose(fp);n=i;printf("录入完毕!\n");}void seek() /*查找*/{int i,item,flag;char s1[21]; /* 以姓名和学号最长长度+1为准*/printf("------------------\n");printf("-----1.按学号查询-----\n");printf("-----2.按姓名查询-----\n");printf("-----3.退出本菜单-----\n");printf("------------------\n");while(1){printf("请选择子菜单编号:");scanf("%d",&item);flag=0;switch(item){ case 1:printf("请输入要查询的学生的学号:\n");scanf("%s",s1);for(i=0;i<n;i++)if(strcmp(stu[i].code,s1)==0){flag=1;printf("学号姓名年龄性别出生年月地址电话E-mail\n");printf("--------------------------------------------------------------------\n");printf("%6s %7s %6d %5s %9s %8s %10s %14s\n",stu[i].code,stu[i].name,stu[i].age,stu[i].sex,stu[i].time,stu[i].add,stu[i].tel,stu[i].mail);}if(flag==0)printf("该学号不存在!\n"); break;case 2:printf("请输入要查询的学生的姓名:\n");scanf("%s",s1);for(i=0;i<n;i++)if(strcmp(stu[i].name,s1)==0){flag=1;printf(" 学号姓名年龄性别出生年月地址电话E-mail\n");printf("--------------------------------------------------------------------\n");printf("%6s %7s %6d %5s %9s %8s %10s %14s\n",stu[i].code,stu[i].name,stu[i].age, stu[i].sex,stu[i].time,stu[i].add,stu[i].tel,stu[i].mail);}if(flag==0)printf("该姓名不存在!\n"); break;case 3:return;default:printf("请在1-3之间选择\n");}}}void modify() /*修改信息*/{int i,item,num;char sex1[3],s1[LEN+1],s2[LEN+1]; /* 以姓名和学号最长长度+1为准*/printf("请输入要要修改的学生的学号:\n");scanf("%s",s1);for(i=0;i<n;i++)if(strcmp(stu[i].code,s1)==0) /*比较字符串是否相等*/num=i;printf("------------------\n");printf("1.修改姓名\n");printf("2.修改年龄\n");printf("3.修改性别\n");printf("4.修改出生年月\n");printf("5.修改地址\n");printf("6.修改电话号码\n");printf("7.修改E-mail地址\n");printf("8.退出本菜单\n");printf("------------------\n");while(1){printf("请选择子菜单编号:");scanf("%d",&item);switch(item){case 1:printf("请输入新的姓名:\n");scanf("%s",s2);strcpy(stu[num].name,s2); break; case 2:printf("请输入新的年龄:\n");scanf("%d",&stu[num].age);break; case 3:printf("请输入新的性别:\n");scanf("%s",sex1);strcpy(stu[num].sex,sex1); break; case 4:printf("请输入新的出生年月:\n"); scanf("%s",s2);strcpy(stu[num].time,s2); break; case 5:printf("请输入新的地址:\n");scanf("%s",s2);strcpy(stu[num].add,s2); break; case 6:printf("请输入新的电话号码:\n"); scanf("%s",s2);strcpy(stu[num].tel,s2); break; case 7:printf("请输入新的E-mail地址:\n"); scanf("%s",s2);strcpy(stu[num].mail,s2); break;case 8:return;default:printf("请在1-8之间选择\n");}}}void sort()/*按学号排序*/{int i,j,*p,*q,s;char temp[10];for(i=0;i<n-1;i++){for(j=n-1;j>i;j--)if(strcmp(stu[j-1].code,stu[j].code)>0) {strcpy(temp,stu[j-1].code);strcpy(stu[j-1].code,stu[j].code); strcpy(stu[j].code,temp);strcpy(temp,stu[j-1].name);strcpy(stu[j-1].name,stu[j].name); strcpy(stu[j].name,temp);strcpy(temp,stu[j-1].sex);strcpy(stu[j-1].sex,stu[j].sex);strcpy(stu[j].sex,temp);strcpy(temp,stu[j-1].time);strcpy(stu[j-1].time,stu[j].time); strcpy(stu[j].time,temp);strcpy(temp,stu[j-1].add);strcpy(stu[j-1].add,stu[j].add);strcpy(stu[j].add,temp);strcpy(temp,stu[j-1].tel);strcpy(stu[j-1].tel,stu[j].tel);strcpy(stu[j].tel,temp);strcpy(temp,stu[j-1].mail);strcpy(stu[j-1].mail,stu[j].mail);strcpy(stu[j].mail,temp);p=&stu[j-1].age;q=&stu[j].age;s=*q;*q=*p;*p=s;}}}void insert() /*插入函数*/{int i=n,j,flag;printf("请输入待增加的学生数:\n");scanf("%d",&m);do{flag=1;while(flag){flag=0;printf("请输入第%d 个学生的学号:\n",i+1); scanf("%s",stu[i].code);for(j=0;j<i;j++)if(strcmp(stu[i].code,stu[j].code)==0){printf("已有该学号,请检查后重新录入!\n");flag=1;break; /*如有重复立即退出该层循环,提高判断速度*/}}printf("请输入第%d 个学生的姓名:\n",i+1);scanf("%s",stu[i].name);printf("请输入第%d 个学生的年龄:\n",i+1);scanf("%d",&stu[i].age);printf("请输入第%d 个学生的性别:\n",i+1);scanf("%s",stu[i].sex);printf("请输入第%d 个学生的出生年月:(格式:年.月)\n",i+1); scanf("%s",stu[i].time);printf("请输入第%d 个学生的地址:\n",i+1);scanf("%s",stu[i].add);printf("请输入第%d 个学生的电话:\n",i+1);scanf("%s",stu[i].tel);printf("请输入第%d 个学生的E-mail:\n",i+1);scanf("%s",stu[i].mail);if(flag==0){i=i;i++;}}while(i<n+m);n+=m;printf("录入完毕!\n\n");sort();}void del(){int i,j,flag=0;char s1[LEN+1];printf("请输入要删除学生的学号:\n");scanf("%s",s1);for(i=0;i<n;i++)if(strcmp(stu[i].code,s1)==0){flag=1;for(j=i;j<n-1;j++)stu[j]=stu[j+1];}if(flag==0)printf("该学号不存在!\n");if(flag==1){printf("删除成功,显示结果请选择菜单6\n");n--;}}void display(){int i;printf("所有学生的信息为:\n");printf("学号姓名年龄性别出生年月地址电话E-mail\n"); printf("--------------------------------------------------------------------\n"); for(i=0;i<n;i++){printf("%6s %7s %5d %5s %9s %8s %10s %14s\n",stu[i].code,stu[i].name,stu[i].age, stu[i].sex,stu[i].time,stu[i].add,stu[i].tel,stu[i].mail);}}void save(){int i;FILE *fp;fp=fopen("student.txt","w"); /*写入*/for(i=0;i<n;i++){fprintf(fp,"%s %s %d %s %s %s %s %s\n",stu[i].code,stu[i].name,stu[i].age,stu[i].sex,stu[i].time,stu[i].add,stu[i].tel,stu[i].mail);}fclose(fp);}void menu()/* 界面*/{int num;printf(" \n\n 自动化0901学生信息管理系统\n\n");printf(" ***************** \n\n");printf(" * 制作人:翁行兴* \n \n");printf(" ***************** \n\n");printf("*********************系统功能菜单************************ \n"); printf(" ---------------------- ---------------------- \n");printf(" * 1.刷新学生信息* * 2.查询学生信息* \n");printf(" * 3.修改学生信息* * 4.增加学生信息* \n");printf(" * 5.按学号删除信息* * 6.显示当前信息* \n");printf(" * 7.保存当前学生信息* * 8.退出系统* \n");printf(" ---------------------- ---------------------- \n"); printf("请选择菜单编号:");scanf("%d",&num);switch(num){case 1:readfile();break;case 2:seek();break;case 3:modify();break;case 4:insert();break;case 5:del();break;case 6:display();break;case 7:save();break;case 8:k=0;break;default:printf("请在1-8之间选择\n");}}五.调试过程一.主界面二.测试数据当选择4——增加学生信息时,出现对话框,先输入增加的数量。

通讯录管理系统代码

通讯录管理系统代码

#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct{ //通讯录结点类型char num[5]; //编号char name[9]; //姓名char sex[3]; //性别char phone[13]; //电话char addr[31]; //地址}DataType;typedef struct node{ //结点类型定义DataType data; //结点数据域struct node * next; //结点指针域}ListNode;typedef ListNode * LinkList;LinkList head;ListNode *p;//函数说明int menu_select( );LinkList CreateList(void);void InsertNode(LinkList head,ListNode *p);ListNode * ListFind(LinkList head);void DelNode(LinkList head);void PrintList(LinkList head);//主函数void main(){for(;;) {switch(menu_select()){case 1:printf("*********************************\n");printf("********通讯录链表的建立*********\n");printf("*********************************\n");head=CreateList();break;case 2:printf("*********************************\n");printf("* 通讯者信息的添加*\n");printf("*********************************\n");printf("编号(4) 姓名(8) 性别电话(11)地址\n");printf("*********************************\n");p=(ListNode *)malloc(sizeof(ListNode));//申请新结点scanf("%s%s%s%S%%s",p->data.num,p->,p->data.sex,p->data.phone,p->data.addr);InsertNode(head,p);break;case 3:printf("*********************************\n");printf("* 通讯录信息的查询\n");printf("*********************************\n");p=ListFind(head);if(p!=NULL) {printf("编号姓名性别电话地址\n");printf("--------------------------------\n");printf("%S,%s,%s,%s,%S\n",p->data.num,p->,p->data.sex,p->data.phone,p->data.addr);printf("--------------------------------\n");}elseprintf("没查到要查询的通迅者!\n");break;case 4:printf("*********************************\n");printf("* 通讯录信息的删除\n");printf("*********************************\n");DelNode(head);//删除结点break;case 5:printf("*********************************\n");printf("* 通讯录链表的输出\n");printf("*********************************\n");PrintList(head);break;case 0:printf("\t 再见!\n");return;}}}//菜单选择函数int menu_select(){int sn;printf(" 通讯录管理系统\n");printf("=====================\n");printf(" 1 通讯录链表的建立\n");printf(" 2 通迅者结点的插入\n");printf(" 3 通讯者结点的查询\n");printf(" 4 通讯者结点的删除\n");printf(" 5 通讯录链表的输出\n");printf(" 0 退出管理系统\n");printf("=====================\n");printf(" 请选择0-5:" );for(;;){scanf("%d",&sn);if(sn<0||sn>5)printf("\n\t输入错误,重选0-5:");elsebreak;}return sn;}//用尾插法建立通讯录链表函数LinkList CreateList(void){//用尾插法建立带头结点的通讯录链表算法LinkList head=(ListNode *)malloc(sizeof(ListNode));//申请头结点ListNode *p,*rear;int flag=0;//结束标志置0rear=head;//尾指针初始指向头结点while(flag==0){p=(ListNode *)malloc(sizeof(ListNode));//申请新结点printf("编号(4)姓名(8)性别电话(11)地址(31)\n");printf("----------------------------------------------\n");scanf("%s%s%s%s%s",p->data.num, p->, p->data.sex, p->data.phone, p->data.addr);rear->next=p;//新结点链接到尾结点之后rear=p;//尾指针指向新结点printf("结束建表吗?(1/0):");scanf("%d",&flag);//读入一个标志数据}rear->next=NULL;//终端结点指针域置空return head;//返回链表头指针}//在通讯录链表head中插入结点void InsertNode(LinkList head,ListNode *p){ListNode *p1,*p2;p1=head;p2=p1->next;while(p2!=NULL && strcmp(p2->data.num,p->data.num)<0) {p1=p2;//p1指向刚访问过的结点p2=p2->next;//p2指向表的下一个结点}p1->next=p;//插入p所指向的结点p->next=p2;//链接表中剩余部分}//有序通讯率链表上的查找ListNode * ListFind(LinkList head){//有序通讯率链表上的查找ListNode *p;char num[5];char name[9];int xz;printf("==============\n");printf("1.按编号查询\n");printf("2.按姓名查询\n");printf("==============\n");printf(" 请选择\n");p=head->next;//假定通讯录表带头结点scanf("%s",&xz);if(xz==1){printf("请输入要查找者的编号:");scanf("%s",num);while(p && strcmp(p->data.num,num)<0)p=p->next;if(p==NULL || strcmp(p->data.num,num)>0)p=NULL;//没有查到要查找的通讯者}elseif(xz==2){printf("请输入要查找者的姓名:");scanf("%s",name);while(p && strcmp(p->,name)!=0)p=p->next;}return p;}//通讯链表上结点的删除void DelNode(LinkList head){char jx;ListNode *p,*q;p=ListFind(head);//调用查找函数if(p==NULL){printf("没有查到要删除的通讯者!/n");return;}printf("真的要删除该结点吗?(Y/N):");scanf("%c",&jx);if(jx=='y'|| jx=='Y'){q=head;while(q!=NULL && q->next!=p)q=q->next;q->next=p->next;//删除结点free(p);//释放被删除的结点空间printf("通讯者已被删除!/n");}}//通讯录链表的输出函数void PrintList(LinkList head){ListNode *p;p=head->next;//使p指向链表开始结点printf("编号姓名性别联系电话地址/n");printf("----------------------------/n");while(p!=NULL){printf("%s,%s,%s,%s,%s,/n",p->data.num,p->,p->data.sex,p->data.phone,p->data.a ddr);printf("--------------------/n");p=p->next;//后移一个结点}}。

通讯录管理系统源代码

通讯录管理系统源代码

源代码#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct _EmployeeInformation{int number;char name[20];char sex[20];char birthday[20];char job[20];char salary[20];char telephone[20];}EmployeeInformation;void viewall(EmployeeInformation employee[], int a);//查询所有职工的信息函数声明void viewa(EmployeeInformation employee[], int b);//查询一个职工的信息函数声明void add(EmployeeInformation employee[], int c);//新增一个职工的信息函数声明void delet(EmployeeInformation employee[], int d);//删除一个职工的信息函数声明void modify(EmployeeInformation employee[], int e);//修改一个职工的信息函数声明int main(){EmployeeInformation employee[100];EmployeeInformation a[1] = {0};int choice2, x = 0, i, j;char choice1 = 'y';FILE *fp;if((fp = fopen("d:\\EmployeeInfo.txt","r")) == NULL) //判断该文件是否存在,如否则提示,否则读出{printf("File open error!\n");exit(0);}fp = fopen("d:\\EmployeeInfo.txt","r");while(! feof(fp)){fscanf(fp,"%d %s %s %s %s %s %s\n",&employee[x].number,employee[x].name,employee[x].sex,employee[x].birthday,employee[x].job,employee[x].salary,employee[x].telephone);x ++;}fclose(fp);do{system("color 1f");printf("=====Welcome to Employee Management System!=====\n");printf("* 1.View All Employee Information. #\n");printf("# 2.View A Employee Information. *\n");printf("* 3.Add Employee Information. #\n");printf("# 4.Delete Employee Information. *\n");printf("* 5.Modify Employee Information. #\n");printf("# 6.Exit. *\n");printf("================================================\n");printf("Please Select:");scanf("%d", &choice2);switch(choice2){case 1: //查询所有职工的信息system("color 2f");viewall(employee, x);printf("y -> 继续系统n-> 退出系统\n");fflush(stdin);scanf("%c", &choice1);system("cls");break;case 2: //查询一个职工的信息system("color 3f");while(choice2 == 2){viewa(employee, x);printf("2->Countinue 0->Stop\n");scanf("%d",&choice2);}printf("y -> 继续系统n -> 退出系统\n");fflush(stdin);scanf("%c", &choice1);system("cls");break;case 3: //新增一个职工的信息system("color 4f");while(choice2 == 3){add(employee, x);x ++;printf("3->Countinue 0->Stop\n");scanf("%d", &choice2);}printf("y -> 继续系统n-> 退出系统\n");fflush(stdin);scanf("%c", &choice1);system("cls");break;case 4: //删除一个职工的信息system("color 5f");while(choice2 == 4){printf("Please input you want to delete number:");delet(employee, x);x --;printf("4->Countinue 0->Stop\n");scanf("%d", &choice2);}printf("y -> 继续系统n -> 退出系统\n");fflush(stdin);scanf("%c", &choice1);system("cls");break;case 5: //修改一个职工的信息system("color 6f");while(choice2 == 5){printf("Please input you want to modify number:");modify(employee, x);printf("5->Countinue 0->Stop\n");scanf("%d",&choice2);}printf("y -> 继续系统n -> 退出系统\n");fflush(stdin);scanf("%c", &choice1);system("cls");break;case 6: //退出系统system("color 7f");printf("Thank you for using this system!\n");printf("Press enter to exit……\n");exit(0);default: //提醒输入有误system("color 8f");printf("Your input is wrong.\n");printf("y -> 继续系统n -> 退出系统\n");fflush(stdin);scanf("%c", &choice1);system("cls");break;}}while(choice1 == 'y');for(j = 0; j < x-1; j ++) //冒泡排序,将职工按职工号大小进行排序{for(i = 0; i <= x-2 ; i ++){if(employee[i].number > employee[i+1].number){a[0] = employee[i];employee[i] = employee[i+1];employee[i+1] = a[0];}}}fp=fopen("d:\\EmployeeInfo.txt","w"); //新建文本并写入职工信息for(i = 0; i < x; i ++){fprintf(fp,"%d %s %s %s %s %s %s\n",employee[i].number,employee[i].name,employee[i].sex,employee[i].birthday,employee[i].job,employee[i].salary,employee[i].telephone);}fclose(fp);system("color 9f");printf("Thank you for using this system!\n");printf("Pres s enter to exit……\n");return 0;}void viewall(EmployeeInformation employee[], int a) //查询所有职工的信息{int i,j;EmployeeInformation b[1] = {0};for(j = 0; j < a-1; j ++) //冒泡排序,将从文本读出的职工信息按职工号大小进行排序{for(i = 0; i <= a-2 ; i ++){if(employee[i].number > employee[i+1].number){b[0] = employee[i];employee[i] = employee[i+1];employee[i+1] = b[0];}}}printf("Number\t \tName\tSex\tBir\tJob\tSalary\tTelephone\n");for(i = 0; i < a; i ++) //打出所有职工的信息{printf("%d\t",employee[i].number);printf("%s\t",employee[i].name);printf("%s\t",employee[i].sex);printf("%s\t",employee[i].birthday);printf("%s\t",employee[i].job);printf("%s\t",employee[i].salary);printf("%s\n",employee[i].telephone);}}void viewa(EmployeeInformation employee[], int b) //查询一个职工的信息{int i, flag, num;printf("Please input you want to search number:\n");scanf("%d", &num);flag = -1;for(i = 0; i < b; i ++) //将输入的号码与原有比较,如没有则提醒,否则继续{if(num == employee[i].number){flag = i;break;}}if(flag >= 0){printf("Number\t \tName\tSex\tBir\tJob\tSalary\tTelephone\n");printf("%d\t", employee[i].number);printf("%s\t", employee[i].name);printf("%s\t", employee[i].sex);printf("%s\t", employee[i].birthday);printf("%s\t", employee[i].job);printf("%s\t", employee[i].salary);printf("%s\n", employee[i].telephone);}else{printf("Not have this employee information.\n");}}void add(EmployeeInformation employee[], int c) //新增一个职工的信息{int i, num, flag;printf("Please input you want to add employee's informatoin:\n");printf("Number:");scanf("%d", &num);flag = -1;for(i = 0; i < c; i ++) //将输入的号码与原有比较,如已有则提醒,否则继续{if(num == employee[i].number){flag = i;break;}}if(flag >= 0){printf("There have had this employee information.\n");printf("Number\t \tName\tSex\tBir\tJob\tSalary\tTelephone\n");printf("%d\t", employee[i].number);printf("%s\t", employee[i].name);printf("%s\t", employee[i].sex);printf("%s\t", employee[i].birthday);printf("%s\t", employee[i].job);printf("%s\t", employee[i].salary);printf("%s\n", employee[i].telephone);}else{employee[c].number = num;printf("Name:");scanf("%s", employee[c].name);printf("Sex:");scanf("%s", employee[c].sex);printf("Birthday:");scanf("%s", employee[c].birthday);printf("Job:");scanf("%s", employee[c].job);printf("Salary:");scanf("%s", employee[c].salary);printf("Telephone:");scanf("%s", employee[c].telephone);printf("Add success!\n");}}void delet(EmployeeInformation employee[], int d) //删除一个职工的信息{int i, k, flag, num, choice4;scanf("%d", &num);flag = -1;for(i = 0; i < d; i ++) //将输入的号码与原有比较,如没有该职工则提醒,否则继续{if(num == employee[i].number){flag = i;k = i;break;}}if(flag >= 0){printf("Number\t \tName\tSex\tBir\tJob\tSalary\tTelephone\n");printf("%d\t",employee[i].number);printf("%s\t",employee[i].name);printf("%s\t",employee[i].sex);printf("%s\t",employee[i].job);printf("%s\t",employee[i].salary);printf("%s\n",employee[i].telephone);printf("Do you really want to delet this employee information.\n");printf("1->Yes 2->No\n");scanf("%d", &choice4);if(choice4 == 1) //将要删除的信息用后面的覆盖掉,以达到删除的目的{for(k = i; k < d-1; k ++){employee[k] = employee[k + 1];}}printf("Delete success!\n");}else{printf("Not have this employee information.\n");}}void modify(EmployeeInformation employee[], int e) //修改一个职工的信息{int i, flag, num, choice5;scanf("%d", &num);flag = -1;for(i = 0; i < e; i ++) //将输入的号码与原有比较,如没有该职工则提醒,否则继续{if(num == employee[i].number){flag = i;break;}}if(flag >= 0){printf("Number\t \tName\tSex\tBir\tJob\tSalary\tTelephone\n");printf("%d\t", employee[i].number);printf("%s\t", employee[i].name);printf("%s\t", employee[i].sex);printf("%s\t", employee[i].birthday);printf("%s\t", employee[i].job);printf("%s\n", employee[i].telephone);printf("Do you really want to change this employee information.\n");printf("1->Yes 2->No\n");scanf("%d", &choice5);if(choice5 == 1) //重新编辑职工的信息{printf("New number:");scanf("%d", &employee[i].number);printf("New name:");scanf("%s", employee[i].name);printf("New sex:");scanf("%s", employee[i].sex);printf("New birthday:");scanf("%s", employee[i].birthday);printf("New job:");scanf("%s", employee[i].job);printf("New salary:");scanf("%s", employee[i].salary);printf("New telephone:");scanf("%s", employee[i].telephone);printf("Modify success!\n");}}else{printf("Not have this employee information.\n");}}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

源代码:#include "stdio.h"#include "stdlib.h"#include "string.h"#include "conio.h"#include "stdlib.h"#define null 0struct record{char name[20];char phone[20];char adress[40];char postcode[10];char e_mail[30];}student[500];struct LinkList{struct record US;struct LinkList *next;}a;struct LinkList *head=null;int num=0;FILE *fp;int menu_select();int adduser();int list();int search();int display();int add();int listbyname();int dele();int save();int exit();void main(){system("cls");for(;;){switch(menu_select()){case 0:adduser();break;case 1:list();break;case 2:search();break;case 3:display();break;case 4:add();break;case 5:listbyname();break;case 6:dele();break;case 7:save();break;case 8:exit(0);}}}menu_select(){char s[80];int a;printf("*_* press any key enter menu! *_* \n");getch();system("cls");printf("\t\t********************MENU*********************\n\n"); printf("\t\t 0. 输入记录\n");printf("\t\t 1. 显示记录\n");printf("\t\t 2. 按姓名查找\n");printf("\t\t 3. 按电话号码查找\n");printf("\t\t 4. 插入记录\n");printf("\t\t 5. 按姓名排序\n");printf("\t\t 6. 删除记录\n");printf("\t\t 7. 记录保存文件\n");printf("\t\t 8. Quit\n");printf("\t\t***********************************************\n");do{printf("\n Enter you choice(0~11):");scanf("%s",s);a=atoi(s);}while (a<0||a>11);return a;}adduser(){printf("\n\t\t**************** 请输入用户信息****************\n"); printf("\n\t\t输入姓名:");scanf("%s",&student[num].name);printf("\n\t\t输入电话号码:");scanf("%s",&student[num].phone);printf("\n\t\t输入地址:");scanf("%s",&student[num].adress);printf("\n\t\t输入邮编:");scanf("%s",&student[num].postcode);printf("\n\t\t输入e-mail:");scanf("%s",&student[num].e_mail);num++;printf("\n\t\t是否继续添加?(Y/N):");if (getch()=='y')adduser();return(0);}list(){int i;system("cls");if(num!=0){printf("\n\t\t*************** 以下为通讯录所有信息************"); for (i=0;i<num;i++){printf("\n\t\t姓名:%s",student[i].name);printf("\n\t\t电话:%s",student[i].phone);printf("\n\t\t地址:%s",student[i].adress);printf("\n\t\t邮编:%s",student[i].postcode);printf("\n\t\te-mail:%s",student[i].e_mail);printf("\t\t");if (i+1<num){printf("\n\t\t__________________________");system("pause");}}printf("\n\t\t************************************************");}elseprintf("\n\t\t通讯录中无任何纪录");printf("\n\t\t按任意键返回主菜单:");getch();return(0);}search(){int mark=0;int i;int a=0;printf("\n\t\t***************** 按姓名查找*******************");char name[20];printf("\n\t\t请输入姓名:");scanf("%s",name);for(i=a;i<num;i++){if (strcmp(student[i].name,name)==0){printf("\n\t\t************* 以下是您查找的用户信息***********");printf("\n\t\t姓名:%s",student[i].name);printf("\n\t\t电话:%s",student[i].phone);printf("\n\t\t地址:%s",student[i].adress);printf("\n\t\te-mail:%s",student[i].e_mail);printf("\n\t\t************************************************");mark++;if ((i+1)<num){printf("\n\t\t是否继续查找相同名字的用户信息:(y/n)");if (getch()=='y'){a=i;continue;}elsereturn(0);}else{printf("\n\t\t按任意键返回主菜单");getch();return(0);}}}if(mark!=0){printf("\n\t\t没有相同姓名的用户纪录");printf("\n\t\t按任意键返回主菜单");getch();return(0);}else{printf("\n\t\t没有相同姓名的用户纪录");printf("\n\t\t按任意键返回主菜单");getch();return(0);}}display(){int mark=0;int i;int a=0;printf("\n\t\t****************** 按电话查找******************"); char phone[10];printf("\n\t\t请输入电话号码:");scanf("%s",phone);for(i=0;i<num;i++){if (strcmp(student[i].phone,phone)==0){printf("\n\t\t************** 以下是您查找的用户信息**********"); printf("\n\t\t姓名:%s",student[i].name);printf("\n\t\t电话:%s",student[i].phone);printf("\n\t\t地址:%s",student[i].adress);printf("\n\t\te-mail:%s",student[i].e_mail);printf("\n\t\t************************************************"); printf("\n\t\t按任意键返回主菜单:");mark++;getch();return(0);}}if (mark==0){printf("\n\t\t没有改用户的信息");printf("\n\t\t按任意键返回主菜单");getch();return(0);}return(0);}add(){int i;if ((fp=fopen("student.bin","wb"))==NULL){printf("\n\t\t文件打开失败");}for (i=0;i<num;i++){if (fwrite(&student[i],sizeof(struct record),1,fp)!=1){printf("\n\t\t写入文件错误!\n");}printf("\n\t\t**************** 请输入用户信息****************\n"); printf("\n\t\t输入姓名:");scanf("%s",&student[num].name);printf("\n\t\t输入电话号码:");scanf("%s",&student[num].phone);printf("\n\t\t输入地址:");scanf("%s",&student[num].adress);printf("\n\t\t输入邮编:");scanf("%s",&student[num].postcode);printf("\n\t\t输入e-mail:");scanf("%s",&student[num].e_mail);num++;printf("\n\t\t是否继续添加?(Y/N):");if (getch()=='y')adduser();return(0);}fclose(fp);printf("\n\t\t通讯录文件已保存");printf("\n\t\t按任意键退出程序\n\t\t");exit(0);return(0);}void deletebyphone(){int i,j;int deletemark=0;char phone[20];printf("\n\t\t请输入要删除用户电话号码:"); scanf("%s",phone);if(num==0){printf("\n\t\t对不起,文件中无任何纪录"); printf("\n\t\t按任意键返回主菜单");getch();return;}for (i=0;i<num;i++){if (strcmp(student[i].phone,phone)==NULL) {printf("\n\t\t以下是您要删除的用户纪录:"); printf("\n\t\t姓名:%s",student[i].name); printf("\n\t\t电话:%s",student[i].phone); printf("\n\t\t地址:%s",student[i].adress); printf("\n\t\te-mail:%s",student[i].e_mail); printf("\n\t\t是否删除?(y/n)");if (getch()=='y'){for (j=i;j<num-1;j++)student[j]=student[j+1];num--;deletemark++;printf("\n\t\t删除成功");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')deletebyphone();return;}elsereturn;}continue;}if (deletemark==0){printf("\n\t\t没有该用户的纪录");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')deletebyphone();return;}}void deletebyname(){int a=0;int findmark=0;int j;int deletemark=0;int i;char name[20];printf("\n\t\t请输入要删除用户姓名:");scanf("%s",name);for (i=a;i<num;i++){if (strcmp(student[i].name,name)==NULL){printf("\n\t\t以下是您要删除的用户纪录:"); findmark++;printf("\n\t\t________________________________"); printf("\n\t\t姓名:%s",student[i].name);printf("\n\t\t电话:%s",student[i].phone);printf("\n\t\t地址:%s",student[i].adress);printf("\n\t\te-mail:%s",student[i].e_mail);printf("\n\t\t________________________________"); printf("\n\t\t是否删除?(y/n)");if (getch()=='y'){for (j=i;j<num-1;j++)student[j]=student[j+1];num--;deletemark++;printf("\n\t\t删除成功");if((i+1)<num){printf("\n\t\t是否继续删除相同姓名的用户信息?(y/n)");if (getch()=='y'){a=i;continue;}}printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')deletebyname();return;}if((i+1)<num){printf("\n\t\t是否继续删除相同姓名的用户信息?(y/n)");if (getch()=='y'){a=i;continue;}}}elsecontinue;}if ((deletemark==0)&&(findmark==0)){printf("\n\t\t没有该用户的纪录");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')deletebyphone();return;return;}else if (findmark!=0){printf("\n\t\t没有重名信息");printf("\n\t\t没有该用户的纪录");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')deletebyphone();return;return;}}dele(){char choic;printf("\n\t\t1-按电话号码删除2-按姓名删除");printf("\n\t\t请选择:");choic=getch();switch (choic){case '1':deletebyphone();break;case '2':deletebyname();break;}return(0);}listbyname(){int i,j;struct record tmp;for (i=1;i<num;i++){if(strcmp(student[i].name,student[i-1].name)<0){tmp=student[i];j=i-1;do{student[j+1]=student[j];j--;}while ((strcmp(,student[j].name)<0&&j>=0)); student[j+1]=tmp;}}printf("\n\t\t排序成功,是否显示?(y/n)");if (getch()=='y')list();return(0);}save(){int j;FILE*fp;fp=fopen("student.txt","w");if (fp==NULL)printf("can't open the file.");if(num!=0){for(j=0;j<num;j++){fwrite(student,sizeof(student),1,fp);}}printf("保存成功!");fclose(fp);return(0);}。

相关文档
最新文档