当前位置:首页 » 课程大全 » c课程设计电话簿

c课程设计电话簿

发布时间: 2021-03-16 02:39:48

课程设计 c++ 关于模板实现电话簿管理 急急急啊,求助各位大哥啦

#include<string>
using namespace std;
//电话本
class book
{
public:
void dis();
void set();
void input();
book();
book(string,string,string,string,string);
protected:
string birthday,number,sex,name,address;
};
book::book()
{
birthday="无出生日期或未输入";
number="无电话号码或未输入";
sex="无性别或未输入";
name="无名字或未输入";
address="无地址或未输入";
}
book::book(string na,string s,string b,string num,string add):name(na),sex(s),birthday(b),number(num),address(add){}
void book::dis() //显示输入的内容
{
cout<<"姓名:"<<p->name<<endl;
cout<<"性别:"<<p->sex<<endl;
cout<<"出生日期:"<<p->birthday<<endl;
cout<<"电话号码:"<<p->number<<endl;
cout<<"家庭住址:"<<p->address<<endl;
}

void book::set() //开始界面
{
int chose;
cout<<"***********************"<<endl;
cout<<"*** 输入数据,请按1 ***"<<endl;
cout<<"*** 查询数据,请按2 ***"<<endl;
cout<<"*** 修改数据,请按3 ***"<<endl;
cout<<"*** 退出程序,请按4 ***"<<endl;
cout<<"***********************"<<endl;
cout<<endl<<"please chose:";
cin>>chose;
switch(chose)
{
case 1:input(); //输入函数
case 2:dis(); //查询显示函数
case 3:edit(); //修改函数,这个函数不会写。
case 4:exit(0);
}
}
void input()
{
FILE *in;
in=fopen("c:\phone.txt","at");
book *p=&temp;
for(char quit;quit!='N'||quit!='n';)
{
cout<<"请输入数据:"<<endl<<"姓名:";
cin>>p->name;
cout<<endl<<"性别(m or f):";
cin>>p->sex;
cout<<endl<<"出生日期:";
cin>>p->birthday;
cout<<endl<<"电话号码:";
cin>>p->number;
cout<<endl<<"家庭住址:";
cin>>p->address;
//下面写入文件
fprintf(in,"%4s,%4s,%4s,%4s,%4s",p->name,p->sex,p-birthday,p->number,p->address);
cout<<endl<<endl<<"继续输入?(y/n)";
cin<<quit;
}
}
int main()
{
void input(),edit();
p->set();
p->input();
p->dis();
delete p;
return 0;
}

② C语言课程设计---电话薄管理(C语言高手进)

/*
vc 6.0运行通过-原创
链表做的
*/

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#define ID struct id
struct id
{
char name[20];
char tele[20];
ID *next;
};

int pc=0;

ID *creat()
{
ID *p1,*p2,*head;
char str[20];
p1=p2=head=NULL;
printf("\t\t\t 开始输入记录(姓名 # 结束)!\n");
while(1)
{
printf("请输入姓名:\n");scanf("%s",str);getchar();
if(strcmp(str,"#")==0) break;
p1=(ID*)malloc(sizeof(ID));
strcpy(p1->name,str);
printf("请输入电话号码:\n");scanf("%s",p1->tele);getchar();

if(head==NULL)
{
head=p1;
p2=p1;
}
else
{
p2->next=p1;
p2=p1;
}
pc++;
}
p2->next=NULL;
return(head);
}

/*输入/添加记录*/
ID *insert(ID *head)
{
ID *temp,*p1,*p2;
printf("插入操作开始!!!\n");
temp=(ID *)malloc(sizeof(ID));
printf("请输入姓名:\n");scanf("%s",temp->name);getchar();
printf("请输入电话号码:\n");scanf("%s",temp->tele);getchar();

if (head==NULL)
{
head=temp;
temp->next=NULL;
}
else
{
p1=head;
while(p1!=NULL)
{
p2=p1;
p1=p1->next;
}
p2->next=temp;
temp->next=p1;
}

printf("插入成功");
pc++;
return (head);
}

/*删除记录*/
ID *delet(ID *head)
{
ID *p1,*p2;
char str[20];
printf("请输入要删除的电话号码:");scanf("%s",str);getchar();
p1=head;
if (head==NULL)
{
printf("没有记录\n");
goto end;
}
while(p1!=NULL && strcmp(p1->tele,str))
{
p2=p1;p1=p1->next;
}
if(p1==NULL)
printf("未找到符合记录!\n");
else if(strcmp(p1->tele,str)==0)
{
if (p1==head)
head=p1->next;
else
p2->next=p1->next;
printf("删除成功!!!\n");
pc--;
}
end:return head;
}

/*查找记录*/
ID *search(ID *head)
{
ID *p1,*p2;
int flag=0;
char c;
printf("请输入姓名的首字母:");scanf("%c",&c);getchar();
p1=head;
while( p1!=NULL)
{
if(p1->name[0]==c)
{
printf("姓名:%s\t电话号码:%s\n",p1->name,p1->tele);
flag=1;
}
p2=p1;p1=p1->next;
}
if(flag==0) printf("未找到符合记录!\n");
return head;
}

/*修改记录*/
ID *modify(ID *head)
{
ID *p1,*p2;
int mode;
char str[20];
printf("请输入要修改记录的姓名:");scanf("%s",str);getchar();
p1=head;
while( p1!=NULL)
{
if(strcmp(p1->name,str)==0)
{
printf("1.姓名:%s\t2.电话号码:%s\n",p1->name,p1->tele);
printf("请选择要修改选项:\n");
scanf("%d",&mode);getchar();
if(mode==1)
{
printf("请输入修改后的姓名\n");
scanf("%s",p1->name);getchar();
}
else if(mode==2)
{
printf("请输入修改后的电话号码\n");
scanf("%s",p1->tele);getchar();
}
else
printf("输入有误!\n");
break;
}
p2=p1;p1=p1->next;
}
if(p1==NULL) printf("未找到符合要求的记录!\n");
return head;
}

/*显示结果函数*/
void print(ID *head)
{
ID *p;
p=head;
printf("\t\t\t*****************\n");
printf("显示结果是:\n");
printf("姓名\t电话号码\n");
if(head!=NULL)
do
{
printf("%s\t%s\n",p->name,p->tele);
p=p->next;
} while(p!=NULL);
}

void main()
{
ID *head=NULL;
int choise;
printf("\t\t\t* * * * C语言课设* * * *\n");
while(1)
{
printf("\t\t 电话簿管理系统\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\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 0.退出\n");
printf("\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请选择(0-6):");
scanf("%d",&choise);getchar();
switch(choise)
{
case 1: head=creat();
break;
case 2: print(head);
break;
case 3: head=search(head);
break;
case 4: head=insert(head);
break;
case 5: head=delet(head);
break;
case 0:
exit(0);
break;
default :printf("输入错误,请重新输入!\n");
}
}
}

③ c++课程设计 简易电话簿管理

#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>
using namespace std;
int count=0;
class CData
{
public:
CData(){};
virtual int Compare(CData &,int)=0;
virtual void Show()=0;
virtual ~CData(){};
};
class CNode
{
private:
CData *pData;
CNode *pNext;
public:
CNode(){pData=0;pNext=0;};
CNode(CNode &node)
{
pData=node.pData;
pNext=node.pNext;
}
void InputData(CData *pdata){pData=pdata;}
void ShowNode(){pData->Show();}
CData *GetData(){return pData;}
friend class CList;
};
class CList
{

CNode *pHead;
public:
CList(){pHead=0;};
~CList(){DeleteList();}
void AddNode(CNode *pnode);
CNode *DeleteNode(CNode *);
CNode *LookUp(CData &);
bool LookUpF(CData &);
void ShowList();
void DeleteList();
CNode *GetListHead(){return pHead;}
CNode *GetListNextNode(CNode *pnode);
};
CNode *CList::GetListNextNode(CNode *pnode)
{
CNode *p1=pnode;
return p1->pNext;
};
void CList::AddNode(CNode *pnode)
{
if (pHead==0)
{
pHead=pnode;
pnode->pNext=0;
return;
}
else
{
pnode->pNext=pHead;
pHead=pnode;
}
};
CNode *CList::DeleteNode(CNode *pnode)
{
CNode *p1,*p2;
p1=pHead;
while(p1!=pnode&&p1->pNext!=0)
{
p2=p1;
p1=p1->pNext;
}
if (p1==pHead)
{
pHead=pHead->pNext;
return pnode;
}
p2->pNext=p1->pNext;
return pnode;
}
CNode *CList::LookUp(CData &data)
{
CNode *p1=pHead;
while(p1)
{
if (p1->pData->Compare(data,1)==0)
return p1;
p1=p1->pNext;
}
return 0;
}
bool CList::LookUpF(CData &data)
{
bool f1=false;
CNode *p1=pHead;
while(p1)
{
if (p1->pData->Compare(data,0)==0)
{
p1->ShowNode();
f1=true;
}
p1=p1->pNext;

}
return f1;
}
void CList::ShowList()
{
CNode *p1=pHead;
while(p1)
{
p1->pData->Show();
p1=p1->pNext;
}
}
void CList::DeleteList()
{
CNode *p1,*p2;
p1=pHead;
while(p1)
{
delete p1->pData;
p2=p1;
p1=p1->pNext;
delete p2;
}
}
class CTelRecord:public CData
{
private :
char szName[20];
char szNumber[20];
char szF;
public:
CTelRecord(){strcpy(szName,"\0");strcpy(szNumber,"\0");}
CTelRecord(char *name,char *number)
{
strcpy(szName,name);
strcpy(szNumber,number);
szF=name[0];
}
void SetRecord(char *name, char *number)
{
strcpy(szName,name);
strcpy(szNumber,number);
szF=name[0];
}
int Compare(CData &,int);
void Show();
};
int CTelRecord::Compare(CData&data,int choice)
{
CTelRecord &temp=(CTelRecord &)data;
if(choice==1)
return strcmp(szName,temp.szName);
else
return (szF==temp.szF ? 0:1);
}
void CTelRecord::Show()
{
cout<<setw(15)<<szName<<setw(15)<<szNumber<<endl;
}
void AddRecord(CList &TelList)
{
CNode *pNode;
CTelRecord *pTel;
char szName[20],szNumber[20];
cout<<"请输入姓名(输入0退出,并进入系统菜单)"<<endl;
cin.getline(szName,20);
while(strcmp(szName,"0"))
{
cout<<"请输入电话号码: "<<endl;
cin.getline(szNumber,20);
pTel=new CTelRecord;
pTel->SetRecord(szName,szNumber);
pNode=new CNode;
pNode->InputData(pTel);
TelList.AddNode(pNode);
count++;
cout<<"请输入姓名(输入0退出,并进入系统菜单) "<<endl;
cin.getline(szName,20);
}
cout<<endl<<endl;
}

void DisplayRecord(CList&TelList)
{
cout<<"目前共有 "<<count<<" 条记录,具体记录如下:"<<endl;
cout<<setw(15)<<"【姓名】"<<setw(15)<<"【电话号码】"<<endl;
TelList.ShowList();
cout<<endl<<endl;
system("pause");
}

void LookUpRecord(CList&TelList)
{
CNode *pLook;
char szName[20];
cout<<"请输入您需要查找的姓名(输入0退出,并进入系统菜单)"<<endl;
cin.getline(szName,20);
while (strcmp(szName,"0"))
{
CTelRecord tele(szName,"0");
pLook=TelList.LookUp(tele);
if (pLook)
{
cout<<"在电话簿中找到"<<szName<<",内容是:"<<endl;
cout<<setw(15)<<"【姓名】"<<setw(15)<<"【电话号码】"<<endl;
pLook->ShowNode();
}
else
cout<<"在电话簿中找不到"<<szName<<","<<endl;
cout<<"请输入您需要查找的姓名(输入0退出,并进入系统菜单)"<<endl;
cin.getline(szName,20);
}
cout<<endl<<endl;
}

void DeleteRecord(CList&TelList)
{
CNode *pLook;
char szName[20];
cout<<"请输入您需要删除的姓名(输入0退出,并进入系统菜单)"<<endl;
cin.getline(szName,20);
while(strcmp(szName,"0"))
{
CTelRecord tel(szName,"0");
pLook=TelList.LookUp(tel);
if (pLook)
{
cout<<"在电话簿中找到"<<szName<<",内容是:"<<endl;
pLook->ShowNode();
cout<<"请确定是否删除此记录(Y/N)【确定删除请输入Y或y,取消删除请输入N或n】:"<<endl;
char ok;
cin>>ok;
cin.ignore();
if (ok=='Y'||ok=='y')
{
TelList.DeleteNode(pLook);
cout<<szName<<"的资料删除成功!"<<endl;
delete pLook;
count--;
}
else if(ok=='N'||ok=='n')
cout<<szName<<"的资料删除失败"<<endl;
}
else
cout<<"在电话簿中找不到"<<szName<<","<<endl;
cout<<"请输入您需要删除的姓名(输入0退出,并进入系统菜单)"<<endl;
cin.getline(szName,20);
}
cout<<endl<<endl;
}
void ModifyRecord(CList &TelList)
{
CNode *pLook;
CTelRecord *pTel;
char szName[20],szNumber[20];
cout<<"请输入您需要修改的姓名(输入0退出,并进入系统菜单)"<<endl;
cin.getline(szName,20);
while(strcmp(szName,"0"))
{
CTelRecord tel(szName,"0");
pLook=TelList.LookUp(tel);
if (pLook)
{
cout<<"在电话簿中找到"<<szName<<",内容是:"<<endl;
pLook->ShowNode();
cout<<"-----下面开始修改-----"<<endl<<"请输入修改后的姓名: "<<endl;
cin.getline(szName,20);
cout<<"请输入修改后的电话号码:"<<endl;
cin.getline(szNumber,20);
cout<<"请确定是否修改此记录(Y/N)【确定修改请输入Y或y,取消修改请输入N或n】:"<<endl;
char ok;
cin>>ok;
cin.ignore();
if (ok=='Y'||ok=='y')
{
pTel=new CTelRecord;
*pTel=tel;
pTel->SetRecord(szName,szNumber);
pLook->InputData(pTel);
cout<<szName<<"的资料修改成功!"<<endl;
}
else if(ok=='N'||ok=='n')
cout<<szName<<"的资料修改失败!"<<endl;
}
else
cout<<" 在电话簿中找不到"<<szName<<","<<endl;
cout<<" 请输入您需要修改的姓名(输入0退出,并进入系统菜单)";
cin.getline(szName,20);
}
}

void StoreFile(CList&TelList)
{
ofstream outfile("TELEPHONE.DAT",ios::binary);
if (!outfile)
{
cout<<" 数据库文件打开错误,没有将数据存入文件!\n";
return;
}
CNode *pnode;
CTelRecord *pTel;
string strName,strNumber;
pnode=TelList.GetListHead();
while(pnode)
{
pTel=(CTelRecord *)pnode->GetData();
outfile.write((char *)pTel,sizeof(CTelRecord));
pnode=TelList.GetListNextNode(pnode);
}
outfile.close();
}
void Operate(string &strChoice,CList&TelList)
{
if (strChoice=="1")
AddRecord(TelList);
else if (strChoice=="5")
DisplayRecord(TelList);

else if (strChoice=="3")
LookUpRecord(TelList);

else if (strChoice=="4")
DeleteRecord(TelList);
else if(strChoice=="2")
ModifyRecord(TelList);
else if (strChoice=="6")

StoreFile(TelList);
else cout<<"对不起,您的输入有误,请重新输入您的选择: "<<endl;
}
void LoadFile(CList &TelList)
{
fstream infile("TELEPHONE.DAT",ios::binary);
if (!infile)
{
cout<<"没有数据文件!\n\n";
return;
}
CNode *pNode;
CTelRecord *pTel;
while (!infile.eof())
{
pTel=new CTelRecord;
infile.read((char*)pTel,sizeof(CTelRecord));
pNode=new CNode;
pNode->InputData(pTel);
TelList.AddNode(pNode);
}
TelList.DeleteNode(pNode);
infile.close();
}

int main()
{
CList TelList;
system("cls");
cout<<"*******************************************************************"<<endl;
cout<<" --------------******欢迎进入电话簿管理系统******-------------\n";
cout<<"*******************************************************************"<<endl;
LoadFile(TelList);
string strChoice;
do
{ cout<<"-------------【欢迎进入系统菜单】------------- "<<endl;
cout<<" 1.增加数据 "<<endl;
cout<<" 2.更新数据 "<<endl;
cout<<" 3.查询数据 "<<endl;
cout<<" 4.删除数据 "<<endl;
cout<<" 5.全部数据 "<<endl;
cout<<" 6.退 出 "<<endl;
cout<<"【请输入您的选择】:"<<endl;
cin>>strChoice;
cin.ignore();
Operate(strChoice,TelList);
}while(strChoice!="6");
StoreFile(TelList);
cout<<"*******************************************************************"<<endl;
cout<<" ------------******欢迎再次使用电话簿管理系统******---------- "<<endl;
cout<<"*******************************************************************"<<endl;
system("pause");
return 0;
}

④ 急求c语言课程设计通讯录系统,谢谢了

/**main_tongxunlu.c**Createdon:2011-6-21*Author:zhanglujin*/#include#include#include#includestructrecord{charname[20];//姓名charphone[12];//电话charadress[50];//地址charpostcode[8];//邮政编码chare_mail[20];//电子邮件。}student[100];//假设最大数为100.//定义全局变量num,表示已经输入的人数。intnum;//这里使用数组解决通讯录的问题,实际上使用链表更好。intmenu_select(){chars[80];inta;/*定义整形变量*/system("cls");printf("\t\t***********欢迎进入通讯管理界面********\n\n");printf("\t\t\t0.输入记录\n");printf("\t\t\t1.显示记录\n");printf("\t\t\t2.按姓名查找\n");printf("\t\t\t3.按电话号码查找\n");printf("\t\t\t4.插入记录\n");printf("\t\t\t5.按姓名排序\n");printf("\t\t\t6.删除记录\n");printf("\t\t\t7.Quit\n");printf("\t\t***********************************************\n\n");do{printf("Enteryouchoice(0~7):");scanf("%s",s);a=atoi(s);}while(a7);returna;}intadser(){printf("\t\t\t****************请输入用户信息****************\n");printf("\t\t\t输入姓名:\n");scanf("%s",student[num].name);printf("\t\t\t输入电话号码:\n");scanf("%s",student[num].phone);printf("\t\t\t输入地址:\n");scanf("%s",student[num].adress);printf("\t\t\t输入邮编:\n");scanf("%s",student[num].postcode);printf("\t\t\t输入e-mail:\n");scanf("%s",student[num].e_mail);num++;printf("\t\t\t是否继续添加?(Y/N):\n");if(getch()=='y'||getch()=='Y')adser();return(0);}voidlist(){inti;system("cls");if(num!=0){printf("\t\t\t***************以下为通讯录所有信息************\n");for(i=0;i=0));student[j+1]=tmp;}}printf("\t\t\t排序成功,是否显示?(y/n)");if(getch()=='y')list();return(0);}intmain(){printf("\t\t************************************************\n");printf("\t\t********welcometoTONGXUNLU*******************\n");printf("\t\t###########codebyXXXXX###################\n");printf("\t\t*************************************************\n");printf("按任意键进入主菜单\n");getch();intselectnum;while(1){selectnum=menu_select();switch(selectnum){case0:{adser();break;}case1:{list();break;}case2:{searchbyname();break;}case3:{searchbyphone();break;}case4:{adser();//这里插入,应该能指定位置,不过意义不大,所以和添加记录一样了。break;}case5:{sortbyname();break;}case6:{dele();break;}case7:{printf("BYEBYE!\n");system("pause");getchar();exit(0);}}}getchar();return0;}

⑤ c语言程序设计 电话簿管理系统

这个是一个简单的系统,你可以改的完善一点,代码如下:
#include<stdio.h>
#include<string.h>
//person结构定义
struct person
{
char name[8];
char tel[15];
char addr[50];
};//结束定义
char filename[20];
FILE *fp;
void creat();
void ndelete();
void output();
void search();
void search1();
void search2();
void append();

main( )

{
int m;
creat();
while(1)
{
printf("\n\t\t***********欢迎使用电话查询系统**********\n\n");
printf("\n\t\t添加, 请按1");
printf("\n\t\t按姓名查找,请按2");
printf("\n\t\t按号码查找, 请按3");
printf("\n\t\t输出, 请按4");
printf("\n\t\t退出, 请按0\n");
printf("\n\t\t********************************************\n\n");
printf("Please select(0--4):");
scanf("%d",&m);
if(m>=0&&m<=4)
{
switch(m)
{
case 1: append();
break;
case 2: search();
break;
case 3: search1();
break;
case 4: output();
break;
case 0: exit();
}
printf("\n\n操作完毕,请再次选择!");
}
else
printf("\n\n选择错误,请再次选择!");
}
}

/*输入模块creat( ): 电话薄的子函数。*/
void creat()
{
printf("\n请确定电话薄文件名:");
scanf("%s",filename);

if((fp=fopen(filename,"at+"))==NULL)
{
printf("\n不能建电话薄录!");
exit();
}
fprintf(fp,"%-10s%-20s%-50s\n","姓名","电话号码","住址");

fclose(fp);
}

/*输出模块output( ):输出电话薄中联系人的个人信息的子函数*/
void output()
{
struct person one;
if((fp=fopen(filename,"r"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
printf("\n\n%20s\n","通 讯 录");
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
printf("%-10s%-20s%-50s",one.name,one.tel,one.addr);
}
fclose(fp);
}

/*添加模块append( ):向电话薄中添加某人的个人信息的子函数*/
void append()
{
struct person one;
search2();
if((fp=fopen(filename,"a"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
printf("\n请输入添加的姓名、电话号码及住址\n");
scanf("%s%s%s",one.name,one.tel,one.addr);
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
fclose(fp);
}
/*查找模块search( ):在电话薄中按姓名查找某人的个人信息的子函数*/
void search()
{
int k=0;
char namekey[8];
struct person one;
printf("\n请输入姓名:");
scanf("%s",namekey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\n不能打开电话薄!");
exit();
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
printf("\n\n已查到,记录为:");
printf("\n%-10s%-20s%-50s",one.name,one.tel,one.addr);
k=1;
}
}
if(!k)
printf("\n\n对不起,电话薄中没有此人的记录。");
fclose(fp);
}

/*查找模块search1( ):在电话薄中按电话号码查找某人的个人信息的子函数*/
void search1()
{
int k=0;
char telkey[15];
struct person one;
printf("\n请输入电话号码:");
scanf("%s",telkey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\n不能打开电话薄!");
exit();
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(telkey,one.tel))
{
printf("\n\n已查到,记录为:");
printf("\n%-10s%-2s%-50s",one.name,one.tel,one.addr);
k=1;
}
}
if(!k)
printf("\n\n对不起,电话薄中没有此人的记录。");
fclose(fp);
}

/*查找模块search( ):在电话薄中按姓名查找某人的个人信息的子函数*/
void search2()
{
int k=0;
char namekey[8];
struct person one;
printf("\n请输入添加的姓名:\n");

scanf("%s",namekey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\n不能打开电话薄!");
exit();
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);

if(!strcmp(namekey,one.name))
{
printf("\n\n查到有同名记录为:");
printf("\n%-10s",one.name);
k=1;
printf("\n\n请改名字后继续完成添加\n");
}

}

fclose(fp);
}

⑥ c语言课程设计报告通讯录

就放大师傅的说法都是法国

⑦ c语言课程设计--- 电话簿管理系统

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUM 100
struct phoneinfor
{
char name[15];
char sex[8];
char num[15];
char job[15];
char address[30];
}phoneinfor[NUM];
char Initialization()/*界面初始化*/
{
char ch;
printf(" ********Phone Information System********\n1.Show all the phone information\n2.Add phone information\n3.Delete phone information\n4.Search phone information\n5.Exit\nPlease select:");
do
{
ch=getch();
if(ch>='1'&&ch<='5')
{
printf("%c\n",ch);
getchar();
return ch;
}
}while(1);
}
void showall()/*显示所有*/
{
int i=0;
FILE *fp;
system("cls");
if((fp=fopen("C:\\phoneinfo.txt","r"))==NULL)
{
printf("ERROR:cannot open file\n");
getchar();
return;
}
printf("name sex phonenum job address\n");
while(!(fp))
{fread(&phoneinfor[i],sizeof(struct phoneinfor),1,fp);
printf("%-15s %-6s %-9s %-15s %-s\n",phoneinfor[i].name,phoneinfor[i].sex,phoneinfor[i].num,phoneinfor[i].job,phoneinfor[i].address);
i++;
if(!i%20)
{
printf("Press any key to continue...");
getch();
}
}
fclose(fp);
printf("Press any key to return");
getch();
return;
}
void addinfor()/*增加数据*/
{
int i=0,b=0;
char ch;
FILE *fp;
do
{
system("cls");
printf("name:");
gets(phoneinfor[i].name);

printf("sex:");
gets(phoneinfor[i].sex);
printf("phonenum:");
gets(phoneinfor[i].num);
printf("job:");
gets(phoneinfor[i].job);
printf("address:");
gets(phoneinfor[i].address);
printf("Saved!Continue?(Y/N)");
do
{
ch=getch();
if(ch=='Y'||ch=='y'||ch=='N'||ch=='n')
{
printf("%c\n",ch);
getchar();
break;
}
}while(1);
i++;
}while(ch=='Y'||ch=='y');
if((fp=fopen("C:\\phoneinfo.txt","a+"))==NULL)
{
printf("ERROR:cannot open file\n");
return;
}
for(b=0;b<i;b++)
if(fwrite(&phoneinfor[b],sizeof(struct phoneinfor),1,fp)!=1)
printf("file write error\n");
fclose(fp);
return;
}
void delinfor()/*删除信息*/
{
int i=0,b=0,k;
char delnum[9];
FILE *fp;
system("cls");
printf("Enter the Delete phonenum:");
gets(delnum);
if((fp=fopen("C:\\phoneinfo.txt","r"))==NULL)
{
printf("ERROR:cannot open file\n");
return;
}
while(!feof(fp))
{
fread(&phoneinfor[i],sizeof(struct phoneinfor),1,fp);
i++;
}
fclose(fp);
for(b=0;b<i;b++)
if(!strcmp(delnum,phoneinfor[b].num))
{
for(k=b;k<i-1;k++)
phoneinfor[k]=phoneinfor[k+1];
if((fp=fopen("C:\\phoneinfo.txt","w"))==NULL)
{
printf("ERROR:cannot open file\n");
return;
}
for(i=0;i<k;i++)
if(fwrite(&phoneinfor[i],sizeof(struct phoneinfor),1,fp)!=1)
printf("file write error\n");
fclose(fp);
printf("Delete!Press any key to return...");
getchar();
return;
}
printf("Not Found!Press any key to return...");
getchar();
return;
}
void searchinfor()/*查找信息*/
{
char ch;
char searchinfor[20];
int i=0;
FILE *fp;
system("cls");
printf("search mode:\n1.By name\n2.By phonenum\nChoose:");
do
{
ch=getch();
if(ch=='1'||ch=='2')
{
printf("%c\n",ch);
getchar();
break;
}
}while(1);
if((fp=fopen("C:\\phoneinfo.txt","r"))==NULL)
{
printf("ERROR:cannot open file\n");
return;
}
if(ch=='1')
{
printf("Enter the name:");
gets(searchinfor);
printf("name sex phonenum job address\n");
while(!feof(fp))
{
fread(&phoneinfor[i],sizeof(struct phoneinfor),1,fp);
if(!strcmp(searchinfor,phoneinfor[i].name))
{
printf("%-15s %-6s %-9s %-15s %-s\n",phoneinfor[i].name,phoneinfor[i].sex,phoneinfor[i].num,phoneinfor[i].job,phoneinfor[i].address);
printf("Press any key to return...");
getchar();
fclose(fp);
return;
}
i++;
}
}
if(ch=='2')
{
printf("Enter the phonenum:");
gets(searchinfor);
printf("name sex phonenum job address\n");
while(!feof(fp))
{
fread(&phoneinfor[i],sizeof(struct phoneinfor),1,fp);
if(!strcmp(searchinfor,phoneinfor[i].num))
{
printf("%-15s %-6s %-9s %-15s %-s\n",phoneinfor[i].name,phoneinfor[i].sex,phoneinfor[i].num,phoneinfor[i].job,phoneinfor[i].address);
printf("Press any key to return...");
getchar();
fclose(fp);
return;
}
i++;
}
}
system("cls");
printf("Not Found!Press any key to return...");
fclose(fp);
getchar();
return;
}
void main()
{
char ch;
do
{
system("cls");
ch=Initialization();
if(ch=='1') showall();
if(ch=='2') addinfor();
if(ch=='3') delinfor();
if(ch=='4') searchinfor();
if(ch=='5') break;
}while(1);
system("cls");
printf("Thank you for your use!");
getchar();
}

⑧ C语言课程设计:通讯录管理系统

/*
* main_tongxunlu.c
*
* Created on: 2011-6-21
* Author: zhanglujin
*/

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
struct record
{
char name[20]; //姓名
char phone[12]; //电话
char adress[50]; //地址
char postcode[8]; //邮政编码
char e_mail[20]; //电子邮件。
}student[100]; //假设最大数为100.
//定义全局变量num,表示已经输入的人数 。
int num; //这里使用数组解决通讯录的问题,实际上使用链表更好。
int menu_select()
{
char s[80];
int a;/*定义整形变量*/
system("cls");
printf("\t\t***********欢迎进入通讯管理界面********\n\n");
printf("\t\t\t0. 输入记录\n");
printf("\t\t\t1. 显示记录\n");
printf("\t\t\t2. 按姓名查找\n");
printf("\t\t\t3. 按电话号码查找\n");
printf("\t\t\t4. 插入记录 \n");
printf("\t\t\t5. 按姓名排序\n");
printf("\t\t\t6. 删除记录\n");
printf("\t\t\t7. Quit\n");
printf("\t\t***********************************************\n\n");
do{
printf("Enter you choice(0~7):");
scanf("%s",s);
a=atoi(s);
}
while (a<0 || a>7);
return a;
}
int adser()
{
printf("\t\t\t**************** 请输入用户信息 ****************\n");
printf("\t\t\t输入姓名:\n");
scanf("%s",student[num].name);
printf("\t\t\t输入电话号码:\n");
scanf("%s",student[num].phone);
printf("\t\t\t输入地址:\n");
scanf("%s",student[num].adress);
printf("\t\t\t输入邮编:\n");
scanf("%s",student[num].postcode);
printf("\t\t\t输入e-mail:\n");
scanf("%s",student[num].e_mail);
num++;
printf("\t\t\t是否继续添加?(Y/N):\n");
if(getch()=='y' || getch()=='Y')
adser();
return(0);
}
void list()
{
int i;
system("cls");
if(num!=0)
{
printf("\t\t\t*************** 以下为通讯录所有信息************\n");
for (i=0;i<num;i++)
{
printf("\t\t\t姓名:%s\n",student[i].name);
printf("\t\t\t电话:%s\n",student[i].phone);
printf("\t\t\t地址:%s\n",student[i].adress);
printf("\t\t\t邮编:%s\n",student[i].postcode);
printf("\t\t\te-mail:%s\n",student[i].e_mail);
if(i+1<num)
{
system("pause");
}
}
printf("\t\t\t************************************************\n");
}
else
printf("\t\t\t通讯录中无任何纪录\n");
printf("\t\t\t按任意键返回主菜单:\n");
getch(); //这里是无回显的输入字符,你输入的字符不会显示在屏幕上。
return;
}
int searchbyname()
{
int mark=0;
int i;
printf("\t\t\t***************** 按姓名查找 *******************\n");
char name[20];
printf("\t\t\t请输入姓名:\n");
scanf("%s",name);
for(i=0;i<num;i++)
{
if (strcmp(student[i].name,name)==0)
{
printf("\t\t\t************* 以下是您查找的用户信息 ***********\n");
printf("\t\t\t姓名: %s",student[i].name);
printf("\t\t\t电话: %s",student[i].phone);
printf("\t\t\t地址: %s",student[i].adress);
printf("\t\t\te-mail:%s",student[i].e_mail);
printf("\t\t\t************************************************\n");
mark++;
if((i+1)<num)
{
printf("\t\t\t是否继续查找相同名字的用户信息:(y/n)\n");
if(getch()=='y' || getch()=='Y')
{
continue;
}
else
return(0);
}
else
{
printf("\t\t\t按任意键返回主菜单");
getch();
return(0);
}
}
}
if(mark == 0)
{
printf("\t\t\t没有相同姓名的用户纪录\n");
printf("\t\t\t按任意键返回主菜单\n");
getch();
return(0);
}
return 0;
}
int searchbyphone()
{
int mark=0;
int i;
printf("\t\t\t****************** 按电话查找 ******************\n");
char phone[10];
printf("\t\t\t请输入电话号码:\n");
scanf("%s",phone);
for(i=0;i<num;i++)
{
if (strcmp(student[i].phone,phone)==0)
{
printf("\t\t\t************** 以下是您查找的用户信息 **********\n");
printf("\t\t\t姓名: %s",student[i].name);
printf("\t\t\t电话: %s",student[i].phone);
printf("\t\t\t地址: %s",student[i].adress);
printf("\t\t\te-mail:%s",student[i].e_mail);
printf("\t\t\t************************************************\n");
printf("\t\t\t按任意键返回主菜单\n");
mark++;
getch();
return(0);
}
}
if (mark==0)
{
printf("\t\t\t没有改用户的信息\n");
printf("\t\t\t按任意键返回主菜单\n");
getch();
return(0);
}
return(0);
}
void deletebyphone()
{
int i,j;
int deletemark=0;
char phone[20];
printf("\t\t\t请输入要删除用户电话号码:\n");
scanf("%s",phone);
if(num==0)
{
printf("\t\t\t对不起,文件中无任何纪录\n");
printf("\t\t\t按任意键返回主菜单\n");
getch();
return;
}
for (i=0;i<num;i++)
{
if (strcmp(student[i].phone,phone)==0)
{
printf("\t\t\t以下是您要删除的用户纪录:\n");
printf("\t\t\t姓名: %s",student[i].name);
printf("\t\t\t电话: %s",student[i].phone);
printf("\t\t\t地址: %s",student[i].adress);
printf("\t\t\te-mail:%s",student[i].e_mail);
printf("\t\t\t是否删除?(y/n)");
if (getch()=='y' || getch()=='Y')
{
for (j=i;j<num-1;j++)
student[j]=student[j+1];
num--;
deletemark++;
printf("\t\t\t删除成功");
printf("\t\t\t是否继续删除?(y/n)");
if (getch()=='y' || getch()=='Y')
deletebyphone();
return;
}
else
return;
}
continue;
}
if (deletemark==0)
{
printf("\t\t\t没有该用户的纪录");
printf("\t\t\t是否继续删除?(y/n)");
if(getch()=='y' || getch()=='Y')
deletebyphone();
return;
}
return;
}
void deletebyname()
{
int a=0;
int findmark=0;
int j;
int deletemark=0;
int i;
char name[20];
printf("\t\t\t请输入要删除用户姓名:\n");
scanf("%s",name);
for (i=a;i<num;i++)
{
if(strcmp(student[i].name,name)==0)
{
printf("\t\t\t以下是您要删除的用户纪录:");
findmark++;
printf("\t\t\t________________________________");
printf("\t\t\t姓名: %s",student[i].name);
printf("\t\t\t电话: %s",student[i].phone);
printf("\t\t\t地址: %s",student[i].adress);
printf("\t\t\te-mail:%s",student[i].e_mail);
printf("\t\t\t________________________________");
printf("\t\t\t是否删除?(y/n)");
if (getch()=='y' || getch() == 'Y')
{
for(j=i;j<num-1;j++)
student[j]=student[j+1];
num--;
deletemark++;
printf("\t\t\t删除成功");
if((i+1)<num)
{
printf("\t\t\t是否继续删除相同姓名的用户信息?(y/n)");
if (getch()=='y')
{
a=i;
continue;
}
}
printf("\t\t\t是否继续删除?(y/n)");
if (getch()=='y')
deletebyname();
return;
}
if((i+1)<num)
{
printf("\t\t\t是否继续删除相同姓名的用户信息?(y/n)");
if (getch()=='y' || getch() == 'Y')
{
a=i;
continue;
}
}
}
else
continue;
}
if ((deletemark==0)&&(findmark==0))
{
printf("\t\t\t没有该用户的纪录");
printf("\t\t\t是否继续删除?(y/n)");
if(getch()=='y' || getch() == 'Y')
deletebyphone();
return;
}
else if (findmark!=0)
{
printf("\t\t\t没有重名信息");
printf("\t\t\t没有该用户的纪录");
printf("\t\t\t是否继续删除?(y/n)");
if(getch()=='y' || getch() == 'Y')
deletebyphone();
return;
}
}
int dele()
{
char choic;
printf("\t\t\t1-按电话号码删除 2-按姓名删除");
printf("\t\t\t请选择:");
choic=getch();
switch (choic)
{
case '1':deletebyphone();break;
case '2':deletebyname();break;
}
return(0);
}
int sortbyname() //按姓名进行排序
{
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(tmp.name,student[j].name)<0&&j>=0));
student[j+1]=tmp;
}
}
printf("\t\t\t排序成功,是否显示?(y/n)");
if (getch()=='y')
list();
return(0);
}
int main()
{
printf("\t\t************************************************\n");
printf("\t\t********welcome to TONGXUNLU *******************\n");
printf("\t\t###########code by XXXXX ###################\n");
printf("\t\t*************************************************\n");
printf("按任意键进入主菜单\n");
getch();
int selectnum;
while(1)
{
selectnum = menu_select();
switch(selectnum)
{
case 0:
{
adser();
break;
}
case 1:
{
list();
break;
}
case 2:
{
searchbyname();
break;
}
case 3:
{
searchbyphone();
break;
}
case 4:
{
adser(); //这里插入,应该能指定位置,不过意义不大,所以和添加记录一样了。
break;
}
case 5:
{
sortbyname();
break;
}
case 6:
{
dele();
break;
}
case 7:
{
printf("BYE BYE!\n");
system("pause");
getchar();
exit(0);
}
}
}
getchar();
return 0;
}

⑨ C++课程设计,这个电话簿索引表意思是让我分块查找吗还是直接建立姓名的完全索引

有什么需要帮助,好在的啦

热点内容
武汉大学学生会辅导员寄语 发布:2021-03-16 21:44:16 浏览:612
七年级学生作文辅导学案 发布:2021-03-16 21:42:09 浏览:1
不屑弟高考成绩 发布:2021-03-16 21:40:59 浏览:754
大学毕业证会有成绩单 发布:2021-03-16 21:40:07 浏览:756
2017信阳学院辅导员招聘名单 发布:2021-03-16 21:40:02 浏览:800
查询重庆2018中考成绩查询 发布:2021-03-16 21:39:58 浏览:21
结业考试成绩怎么查询 发布:2021-03-16 21:28:40 浏览:679
14中医医师资格笔试考试成绩查分 发布:2021-03-16 21:28:39 浏览:655
名著赏析课程标准 发布:2021-03-16 21:27:57 浏览:881
北京大学商业领袖高端培训课程 发布:2021-03-16 21:27:41 浏览:919