您的当前位置:首页正文

C++通讯录管理系统

来源:个人技术集锦


#include #include

#include #include #include #include #include

using namespace std; class book { public:

book();//默认构造函数 char inter_face();//首页 void add_person();//添加联系人 void del_person();//删除联系人 void show_all();//显示所有联系人 void alter();//修改信息 void select();//查询联系人

void save_new();//保存新增加的联系人 private:

string name;//姓名 string address;//地址 string number;//电话号码 string post;//邮编 string qq;//QQ号 };

struct record

{

book object;//双向链表中的数据域是是一个记录类 record *prior;//指向前躯 record *next;//指向后继 };

book::book() {

name = \"\\0\"; address = \"\\0\"; number = \"\\0\"; post = \"\\0\";

qq = \"\\0\"; } //首页

char book::inter_face() {

system(\"cls\");

cout <cout<<\"\\★★★★★★★★★★★★★★★★★★★★★★★★★★\" <<<\"\\\选择 :\" ;

char choose; cin >>choose; fflush(stdin);

return choose; }

//添加联系人

void book::add_person() {

cout <>name; fflush(stdin); cout <<\"电话 : \"; cin >>number; fflush(stdin); cout <<\"QQ : \"; cin >>qq;

fflush(stdin); cout <<\"邮编 : \"; cin >>post; fflush(stdin); cout <<\"地址 : \"; cin >>address; fflush(stdin);

save_new();

cout <//删除联系人

void book::del_person() {

ofstream outData(\"temp.txt\ ifstream inData(\"pbook.txt\

if (!outData || !inData) {

cout <string sign;

cout <>sign; string str1; bool flag = true; string str;

while (inData >>name >>number) {

getline(inData, str);

if ((sign==name) || (sign==number))

{

cout <cout <outData <cout <while (getline(inData, str)) {

outData <outData.close(); inData.close();

ofstream out(\"pbook.txt\ ifstream in(\"temp.txt\

if (!out || !in) {

cout <while (getline(in, str)) {

out <out.close(); in.close();

cout <}

system(\"pause\"); }

//显示所有联系人 void book::show_all() {

ifstream inData(\"pbook.txt\

if (!inData) {

cout <bool flag = true; string record;

while (getline(inData, record)) {

if (flag) {

cout <cout <cout <cout <system(\"pause\"); }

//修改信息 void book::alter() {

ifstream inData(\"pbook.txt\

if (!inData) {

cout <string sign;

cout <>sign; fflush(stdin);

string str1;

getline(inData, str1);

record *H = new record; record *p = H; record *q = H; bool flag = true;

while (inData >>p->object.name >>p->object.number >>p->object.qq >>p->object.post >>p->object.address) {

p->next = new record; p = p->next; p->prior = q; q->next = p; q = p; }

p->next = NULL;

inData.close(); p = H; while (p) {

if ((p->object.name==sign) || (p->object.number==sign))

{

if (flag) {

cout <cout <<object.name <<\" \" <object.number <<\" \" <object.qq <<\" \" <object.post

<<\" \" <object.address <cout <>p->object.name; fflush(stdin);

cout <<\"电话号:\"; cin >>p->object.number; fflush(stdin); cout <<\"QQ :\"; cin >>p->object.qq; fflush(stdin); cout <<\"邮编 :\"; cin >>p->object.post; fflush(stdin); cout <<\"地址 :\"; cin >>p->object.address; fflush(stdin); break; }

p = p->next; } if (flag)

{

cout <ofstream out(\"pbook.txt\ if (!out)

{

cout <out <next; while (p) {

out <object.name <<\" \" <object.number <<\" \" <object.qq <<\" \" <object.post

<<\" \" <object.address <next; }

out.close();

cout <//查询联系人 void book::select() {

ifstream inData(\"pbook.txt\

if (!inData)

{

cout <string sign;

cout <>sign;

fflush(stdin);

string str1; bool flag = true;

string str;

while (inData >>name >>number) {

getline(inData, str);

if ((name==sign) || (number==sign)) {

cout <cout <}

system(\"pause\"); }

void book::save_new() {

ofstream outData(\"pbook.txt\

if (!outData)

{

cout <outData << setiosflags(ios::left) << setw(17) << name <<\" \" << setw(16) << number <<\" \" << setw(18) << qq <<\" \" << setw(14) << post <<\" \" << setw(20) << address <outData.close(); }

enum power{ADD = '1', DEL = '2', SHOW = '3', Alter = '4', Select = '5', END = '6'};

int main() {

char choose; book abj;

while (choose = abj.inter_face()) {

switch (choose) {

case ADD:

abj.add_person();////添加联系人 break; case DEL:

abj.del_person();////删除联系人 break; case SHOW:

abj.show_all();////显示所有联系人 break;

case Alter:

abj.alter();////修改信息 break; case Select:

abj.select();////查询联系人 break;

case END:

cout <return 0; }

因篇幅问题不能全部显示,请点此查看更多更全内容