各位高手 帮帮忙 怎么改case '6'才能实现(6)按座机号码查询功能

zhouli19900826 2009-12-28 05:40:43
代码如下
#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
using namespace std;
class tul
{
char name[20];char xingbie[2];char znum[11];char snum[11];char id[8];
public:
tul() { }
tul(char n[20],char x[2],char z[11],char s[11],char i[8])
{
strcpy(name,n);
strcpy(xingbie,x);
strcpy(znum,z);
strcpy(snum,s);
strcpy(id,i);
}
friend void main();
};


void main()
{
cout<<"********************************************************************\n";
cout<<"\n";
cout<<" ******** 欢迎来到通讯录管理系统 ********\n"<<endl;
cout<<"********************************************************************\n";
cout<<"请选择您需要的服务!"<<endl;
cout<<"操作:"<<endl;
cout<<"********** (0)数据录入 **********"<<endl;
cout<<"********** (1)增加数据 **********"<<endl;
cout<<"********** (2)删除数据 **********"<<endl;
cout<<"********** (3)修改数据 **********"<<endl;
cout<<"********** (4)查看通讯录中的数据 **********"<<endl;
cout<<"查询:"<<endl;
cout<<"********** (5)按姓名查询 **********"<<endl;
cout<<"********** (6)按座机号码查询 **********"<<endl;
cout<<"********** (7)按手机号码查询 **********"<<endl;
cout<<"********** (8)按单位名字简称查询 **********"<<endl;
cout<<"********** (9)退出 **********"<<endl;
cout<<"选择相关操作请输入相对的括号里的阿拉伯数字!"<<endl;

char p;char w;
tul *s[100];
ofstream *file[100];
int i=0;
int j=0;
bool flag2=0;
do
{
cin>>p;
if((p>='0'&&p<='9'))
flag2=1;
else
cout<<"指令错误!请重新输入:"<<endl;
}while(flag2==0);
do{


switch(p)

{

case '0':
{
char c;
char name[20];char xingbie[2];char znum[11];char snum[11];char id[8];
do{
cout<<"请输入您要增加的通讯人姓名:"<<endl;
cin>>name;
cout<<"请输入您要增加的通讯人性别:"<<endl;
cin>>xingbie;
cout<<"请输入您要增加的通讯人的座机号码:"<<endl;
cin>>znum;
cout<<"请输入您要增加的通讯人的手机号码:"<<endl;
cin>>snum;
cout<<"请输入您要增加的通讯人单位名字的简称"<<endl;
cin>>id;
file[j]=new ofstream("d:\\通讯录.txt",ios::ate);
*file[j]<<"姓名"<<name<<" "<<"性别"<<xingbie<<" "<<"座机号码"<<znum<<" "<<"手机号码"<<snum<<" "<<"单位名字简称"<<id<<" "<<endl;
fstream outfile1,infile; //作一个文本文档在文件夹中用于显示所录入的数据
outfile1.open("通讯录.txt",ios::out|ios::app);
if(!file)
{
cout<<"通讯录.txt can not open.\n";
return;
}
outfile1<<"姓名"<<name<<" "<<"性别"<<xingbie<<" "<<"座机号码"<<znum<<" "<<"手机号码"<<snum<<" "<<"单位名字简称"<<id<<" "<<endl;
outfile1.close();
infile.open("通讯录.txt",ios::in);
if(!file) //判断文件是否打开
{
cout<<"通讯录.txt can not open.\n";
return;
}
char ch;
while(infile.get(ch))
cout<<ch;
cout<<endl;
infile.close();
j++;
s[i]=new tul( name, xingbie,znum,snum,id);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
flag2=0;
do
{
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
else
flag2=1;
}while(flag2==0);
}while(c=='y');
break;
}


case '1':
{
char name[20];char xingbie[2];char znum[11];char snum[11];char id[8];
char c;
do
{
cout<<"请输入您要增加的通讯人姓名:"<<endl;
cin>>name;
cout<<"请输入您要增加的通讯人性别:"<<endl;
cin>>xingbie;
cout<<"请输入您要增加的通讯人的座机号码:"<<endl;
cin>>znum;
cout<<"请输入您要增加的通讯人的手机号码:"<<endl;
cin>>snum;
cout<<"请输入您要增加的通讯人单位名字的简称"<<endl;
cin>>id;
file[j]=new ofstream("d:\\通讯录.txt",ios::ate);
*file[j]<<"姓名"<<name<<" "<<"性别"<<xingbie<<" "<<"座机号码"<<znum<<" "<<"手机号码"<<snum<<" "<<"单位名字简称"<<id<<" "<<endl;
fstream outfile1,infile; //作一个文本文档在文件夹中用于显示所录入的数据
outfile1.open("通讯录.txt",ios::out|ios::app);
if(!file)
{
cout<<"通讯录.txt can not open.\n";
return;
}
outfile1<<"姓名"<<name<<" "<<"性别"<<xingbie<<" "<<"座机号码"<<znum<<" "<<"手机号码"<<snum<<" "<<"单位名字简称"<<id<<" "<<endl;
outfile1.close();
infile.open("通讯录.txt",ios::in);
if(!file) //判断文件是否打开
{
cout<<"通讯录.txt can not open.\n";
return;
}
char ch;
while(infile.get(ch))
cout<<ch;
cout<<endl;
infile.close();
j++;
s[i]=new tul( name, xingbie,znum,snum,id);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}


case '6':
{
char znum[11];
char c;
string jiadian,line,str,ne;
do
{
fstream fin("通讯录.txt");
fstream *p;
fstream outfile("修改.txt",ios::trunc|ios::out); //作一个文本文档在文件夹中用于显示所录入的数据
cout<<"请输入您要查询的通讯人的座机号码:"<<endl;
cin>>znum;
jiadian=znum;
while(!fin.eof() )
{
getline(fin,line);
istringstream stream(line);
ne = line.substr(0,line.find(" ",0));//找到名字,判断是否相等
if(ne != "座机号码"+jiadian)
{
fseek(*p,32,1);
cout<<fin.tellp()<<endl;

cout<<line<<endl;
}
}
fin.close();
cout<<"数据查找成功,还要继续查找吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
};break;


case '9':
{
exit(0);
break;
}

}
cout<<"您想继续进行其他操作吗?(y/n)"<<endl;
bool flag4=0;
do
{
cin>>w;
if(w!='y'&&w!='n')
cout<<"指令错误!请重新输入!"<<endl;
else
flag4=1;
}while(flag4==0);
if(w=='n') exit(0);
if(w=='y')
cout<<"请输入操作代码(0 数据录入/1 增加数据/2 删除数据/3 修改数据/4 输出通讯录中所有的数据/5 按姓名查询/6 按座机号码查询/7 按手机号码查询/8 按单位名字简称查询/9退出)"<<endl;
cin>>p;
}while(w=='y');
for(int x=0;x<i;x++)
{
delete s[x];
cout<<"delete all members!"<<endl;
}
}



.txtz中
姓名qw 性别a 座机号码qwer 手机号码qwrt 单位名字简称we
姓名we 性别a 座机号码dddd 手机号码hjmn 单位名字简称we
姓名er 性别a 座机号码ffff 手机号码erhg 单位名字简称we
姓名rt 性别a 座机号码gggg 手机号码ddfd 单位名字简称we
姓名tw 性别a 座机号码hhhh 手机号码sczx 单位名字简称we
姓名fw 性别a 座机号码jjjj 手机号码gggr 单位名字简称we
姓名vw 性别a 座机号码kkkk 手机号码sdfd 单位名字简称we
姓名sw 性别a 座机号码llll 手机号码aszx 单位名字简称we

例如:输入座机号码hhhh
显示:姓名tw 性别a 座机号码hhhh 手机号码sczx 单位名字简称we

...全文
1100 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
s446721902 2010-02-04
  • 打赏
  • 举报
回复
楼主执着啊帮你up下
zhouli19900826 2010-02-04
  • 打赏
  • 举报
回复
谁来帮帮我啊!-.-。
zhouli19900826 2010-01-23
  • 打赏
  • 举报
回复
但是我输入的是座机号啊 ,怎么比较名字呢?以需要用指针往前移动吧!怎么改呢?
macrojj 2010-01-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 macrojj 的回复:]
while(!fin.eof() )
{
getline(fin,line);
istringstream stream(line);
ne = line.substr(0,line.find(" ",0));

姓名vw 性别a 座机号码kkkk 手机号码sdfd 单位名字简称we
这个时候的ne是  姓名vw


if(ne != "座机号码"+jiadian)所以这的比较错了 应该比较名字吧
{
fseek(*p,32,1);
cout < <fin.tellp() < <endl;

cout < <line < <endl;
}
[/Quote]
macrojj 2010-01-13
  • 打赏
  • 举报
回复
while(!fin.eof() )
{
getline(fin,line);
istringstream stream(line);
ne = line.substr(0,line.find(" ",0));

姓名vw 性别a 座机号码kkkk 手机号码sdfd 单位名字简称we
这个时候的ne是 性别a 座机号码kkkk 手机号码sdfd 单位名字简称we

if(ne != "座机号码"+jiadian)所以这的比较错了
{
fseek(*p,32,1);
cout < <fin.tellp() < <endl;

cout < <line < <endl;
}
zhouli19900826 2010-01-13
  • 打赏
  • 举报
回复
谁能帮帮我啊
zhouli19900826 2009-12-28
  • 打赏
  • 举报
回复
你理解错了,我想要你帮我改一下case '6'的代码 使它能实现按座机号码查找功能 即输出一行的所有数据。。。。注意 是查找的那行
冻结 2009-12-28
  • 打赏
  • 举报
回复
如果要‘6’到6,可以’6‘-48

64,642

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧