班级通讯录.docx

上传人:b****5 文档编号:4448290 上传时间:2022-12-01 格式:DOCX 页数:11 大小:142.72KB
下载 相关 举报
班级通讯录.docx_第1页
第1页 / 共11页
班级通讯录.docx_第2页
第2页 / 共11页
班级通讯录.docx_第3页
第3页 / 共11页
班级通讯录.docx_第4页
第4页 / 共11页
班级通讯录.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

班级通讯录.docx

《班级通讯录.docx》由会员分享,可在线阅读,更多相关《班级通讯录.docx(11页珍藏版)》请在冰豆网上搜索。

班级通讯录.docx

班级通讯录

班级通讯录

我自己编写了一个班级通讯录用C语言,程序如下:

#include 

#include 

#include

#include

#include

#include

#include

usingnamespacestd;

classbook

{

public:

  book();//默认构造函数

  charinter_face();//首页

  voidadd_person();//添加联系人

  voiddel_person();//删除联系人

  voidshow_all();//显示所有联系人

  voidalter();//修改信息

  voidselect();//查询联系人

  voidsave_new();//保存新增加的联系人

private:

  stringname;//姓名

  stringaddress;//地址

  stringnumber;//电话号码

  stringpost;//邮编

  stringqq;//QQ号

};

structrecord

{

  bookobject;//双向链表中的数据域是是一个记录类

  record*prior;//指向前躯

  record*next;//指向后继

};

book:

:

book()

{

  name="\0";

  address="\0";

  number="\0";

  post="\0";

  qq="\0";

}

//首页

charbook:

:

inter_face()

{

  system("cls");

  

  cout<

  cout<<"\t\t★★★★★★★★★★★★★★★★★★★★★★★★★★"<

    <<"\t\t※                        ※"<

    <<"\t\t※      班 级 通 迅 录        ※"<

    <<"\t\t※                        ※"<

    <<"\t\t※   1.添加新联系人.   4.修改信息.    ※"<

    <<"\t\t※                        ※"<

    <<"\t\t※   2.删除联系人.    5.查询联系人.   ※"<

    <<"\t\t※                        ※"<

    <<"\t\t※   3.显示所有联系人.  6.关闭通迅录.   ※"<

    <<"\t\t※                        ※"<

    <<"\t\t★★★★★★★★★★★★★★★★★★★★★★★★★★"<

    <<"\t\t\t选择:

";

  

  charchoose;

  cin>>choose;

  fflush(stdin);

  

  returnchoose;

}

//添加联系人

voidbook:

:

add_person()

{

  cout<

    <<"姓名:

";

  cin>>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<

!

!

!

!

"<

  system("pause");

}

//删除联系人

voidbook:

:

del_person()

{

  ofstreamoutData("temp.txt",ios:

:

out);

  ifstreaminData("pbook.txt",ios:

:

in);

  

  if(!

outData||!

inData)

  {

    cout<

!

!

!

找不到文件!

!

!

!

"<

    system("pause");

    return;

  }

  

  stringsign;

  cout<

";

  cin>>sign;

  stringstr1;

  boolflag=true;

  stringstr;

  

  while(inData>>name>>number)

  {

    getline(inData,str);

    

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

    {

      cout<

"<

      cout<

      cout<

:

left)<

        <<""<

      flag=false;

      break;

    }

    

    outData<

:

left)<

      <<""<

  }

  

  if(flag)

  {

    cout<

!

!

联系人中没你找的人!

!

!

!

"<

  }

  else

  {

    while(getline(inData,str))

    {

      outData<

    }

    

    outData.close();

    inData.close();

    

    ofstreamout("pbook.txt",ios:

:

out);

    ifstreamin("temp.txt",ios:

:

in);

    

    if(!

out||!

in)

    {

      cout<

!

!

"<

      system("pause");

      return;

    }

    

    while(getline(in,str))

    {

      out<

    }

    

    out.close();

    in.close();

    cout<

!

!

"<

  }

  

  system("pause");  

}

//显示所有联系人

voidbook:

:

show_all()

{

  ifstreaminData("pbook.txt",ios:

:

in);

  

  

  if(!

inData)

  {

    cout<

!

!

!

没有找到文件!

!

!

!

!

"<

    system("pause");

    return;

  }

  

  boolflag=true;

  stringrecord;

  

  while(getline(inData,record))

  {

    if(flag)

    {

      cout<

"<

    }

    cout<

    flag=false;

  }

  

  if(flag)

  {

    cout<

!

!

!

!

"<

  }

  else

  {

    cout<

!

!

!

!

"<

  }

  

  system("pause");

}

//修改信息

voidbook:

:

alter()

{

  ifstreaminData("pbook.txt",ios:

:

in);

  

  if(!

inData)

  {

    cout<

!

!

!

!

"<

    system("pause");

    return;

  }

  

  stringsign;

  cout<

";

  cin>>sign;

  fflush(stdin);

  

  stringstr1;

  getline(inData,str1);

  

  record*H=newrecord;

  record*p=H;

  record*q=H;

  boolflag=true;

  

  while(inData>>p->object.name >>p->object.number>>p->object.qq

    >>p->object.post>>p->object.address)

  {

    p->next=newrecord;

    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<

        cout<

:

left)<

          <object.name <<""<object.number

          <<""<object.qq 

          <<""<object.post 

          <<""<object.address<

        flag=false;

      }

      cout<

"<

      cout<<"姓名 :

";

      cin>>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<

!

!

!

"<

    system("pause");

    return;

  }

  else

  {

    ofstreamout("pbook.txt",ios:

:

out);

    

    if(!

out)

    {

      cout<

!

!

不能打开文件!

!

!

!

"<

      system("pause");

      return;

    }

    

    out<

    p=H->next;

    while(p)

    {

      out<

:

left)<object.name 

        <<""<object.number 

        <<""<object.qq

        <<""<object.post

        <<""<object.address<

      p=p->next;

    }

    

    out.close();

    cout<

!

!

!

"<

    system("pause");

  }

}

//查询联系人

voidbook:

:

select()

{

  ifstreaminData("pbook.txt",ios:

:

in);

  

  if(!

inData)

  {

    cout<

!

!

!

文件找不到!

!

!

!

"<

    system("pause");

    return;

  }

  

  stringsign;

  cout<

";

  cin>>sign;

  fflush(stdin);

  

  stringstr1;

  boolflag=true;

  

  stringstr;

  while(inData>>name>>number)

  {

    getline(inData,str);

    

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

    {

      cout<

"<

      cout<

      cout<

:

left)<

        <

      flag=false;

      break;

    }

  }

}

voidbook:

:

save_new()

{

  ofstreamoutData("pbook.txt",ios:

:

app);

  if(!

outData)

  {

    cout<

!

!

打开文件失败!

!

!

!

"<

    system("pause");

    return;

  }

  outData<

:

left)<

    <<""<

    <

    <

    <

  

  outData.close();

}

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

intmain()

{

  charchoose;

  bookabj;

  

  while(choose=abj.inter_face())

  {

    switch(choose)

    {

    caseADD:

      abj.add_person();////添加联系人

      break;

    caseDEL:

      abj.del_person();////删除联系人

      break;

    caseSHOW:

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

      break;

    caseAlter:

      abj.alter();////修改信息

      break;

    caseSelect:

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

      break;

    caseEND:

      cout<

!

!

!

!

"<

      exit(0);

      break;

    default:

      break;

    }

  }

  return0;

用c++进行编译,连接和运行之后,截图如下:

机械工程学院闫强20131067

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 国外设计风格

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1