c課程設計電話簿
① 課程設計 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++課程設計,這個電話簿索引表意思是讓我分塊查找嗎還是直接建立姓名的完全索引
有什麼需要幫助,好在的啦