#include#include #include using namespace std; struct contactsInfo { char name[20]; char address[50]; int telephoneNo; contactsInfo *next; }; class book { private: contactsInfo *head; contactsInfo *nail; public: book(){head = NULL;nail = head;} void insertInfo(); void delteInfo( char *strName ); void searchInfo( char *strName ); void displayBook(); void displayMenu(); }; void book::insertInfo() { contactsInfo *pdata = new contactsInfo; cout << "请输入姓名:"; cin >> pdata->name; cout << "请输入地址:"; cin >> pdata->address; cout << "请输入电话:"; cin >> pdata->telephoneNo; if ( head == NULL ) { head = pdata; nail = pdata; pdata->next = NULL; } else { nail->next = pdata; pdata->next = NULL; nail = pdata; } cout << endl; } void book::delteInfo( char *strName ) { contactsInfo *pdata = head; while( strcmp(pdata->name,strName) != 0 ) pdata = pdata->next; if( pdata == head ) head = pdata->next; else { contactsInfo *pdeletNode = head; for ( ;;pdeletNode = pdeletNode->next ) if ( pdeletNode->next == pdata ) break; pdeletNode->next = pdata->next; } delete pdata; cout << endl; } void book::searchInfo( char *strName ) { contactsInfo *pdata = head; while( strcmp(pdata->name,strName) ) { pdata = pdata->next; } cout << "查询结果:" << endl; cout << "姓名:" << pdata->name << "地址:" << pdata->address << "联系电话:" << pdata->telephoneNo << endl; cout << endl; } void book::displayBook() { contactsInfo *temp = head; cout << left << setw(10) << "姓名:"<< setw(30) << "地址:" << setw(20) << "联系电话:" << endl; while ( temp ) { cout << left << setw(10) << temp->name << setw(30) << temp->address << setw(20) << temp->telephoneNo << endl; temp = temp->next; } cout << endl; } void book::displayMenu() { cout << ">----------菜鸟简易通讯录----------<" << endl; cout << "1.添加联系人" << endl; cout << "2.查找联系人" << endl; cout << "3.删除联系人" << endl; cout << "4.显示所有联系人" << endl; cout << "0.退出通讯录" << endl; cout << endl; } int main() { book testInfo; int opeNo; while( true ) { testInfo.displayMenu(); cout << "请选择需要进行的操作:" ; cin >> opeNo; switch( opeNo ) { case 1: { testInfo.insertInfo(); break; } case 2: { char *str = new char; cout << "输入你要查找人的姓名:"; cin >> str; testInfo.searchInfo( str ); break; } case 3: { char *str = new char; cout << "输入你要删除人的姓名:"; cin >>str; testInfo.delteInfo( str ); break; } case 4: { testInfo.displayBook(); break; } case 0: { cout << "操作结束,退出系统,谢谢使用!!!" << endl; return 0; break; } default: { cout << "不要耍我嘛,输入正确的信息!!!" << endl; break; } } } return 0; } 简单的 呵呵 不知道是否符合要求 下面是截图