C++手机号码归属地查询软件,急需解决的问题
下面这个程序我做到修改就做不下去了,求高手帮帮忙啊,小弟一定感激涕零mobilbook.txt为磁盘文件,见附件
下面是程序
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string a[140000];
int main( )
{
int tag=0;
menu:
cout<<" ____________________________________ "<<endl;
cout<<"& 欢迎使用手机号码归属地查询系统 & "<<endl;
cout<<"| 请选择要进行的操作 | "<<endl;
cout<<"| | "<<endl;
cout<<"| | "<<endl;
cout<<"| | "<<endl;
cout<<"| | "<<endl;
cout<<"| | "<<endl;
cout<<"| | "<<endl;
cout<<"| 1 查询 2 添加 | "<<endl;
cout<<"| | "<<endl;
cout<<"| 3 修改 0 退出 | "<<endl;
cout<<"&____________________________________& "<<endl;
int choice;
cin>>choice;
if (choice>3||choice<0)
{cout<<"无此选项,请重新选择!"<<endl;
goto menu;
}
switch (choice)
{
case 0:goto o;
case 1:goto find;
case 2:goto add;
case 3:goto update;
}
find:
{
//查询代码
int i=0;
char s[8];///="1394831";
//将string 转换char[] cout<<s1.c_str()char m[8];strcpy(m,s1.c_str());
///string s1 = &(s[0]);
cout<<"请输入查询手机号码前7位"<<endl;
cin>>s;
string s1 = &(s[0]);
ifstream infile("mobilbook.txt");
//定义输入文件流对象,以输入方式打开磁盘文件f1.dat
if(!infile)
{ cerr<<"open error!"<<endl;
exit(1);
}
while(!infile.eof())
{
infile>>a[i];
if (s1==a[i].substr(0,7))
{
cout<<a[i]<<endl;
tag=1;
break;
}
}
infile.close();
if(tag==0)
cout<<"无此号码!"<<endl;//循环执行完
cout<<" _______________________ "<<endl;
cout<<"| 请选择要进行的操作 | "<<endl;
cout<<"| | "<<endl;
cout<<"| Y 继续查询 | "<<endl;
cout<<"| | "<<endl;
cout<<"| N 返回主菜单 | "<<endl;
cout<<"|_______________________| "<<endl;
char ch;
cin>>ch;
if(ch=='Y' || ch=='y') goto find;
else
{ system("cls"); //清屏
goto menu;
}
}
add: //添加
{ int i=0;
char s[8]; //定义一个号码段数组
char c[50]; //归属地数组
cout<<"请输入要添加的手机号码前7位:"<<endl;
cin>>s;
string s1 = &(s[0]);
ifstream f1("mobilbook.txt");
while(!f1.eof())
{
f1>>a[i];
if (s1==a[i].substr(0,7))
{
cout<<endl<<a[i]<<endl<<" 此号码已存在,请确认输入无误"<<endl;
goto a;
a:
cout<<" _______________________ "<<endl;
cout<<"| 请选择要进行的操作 | "<<endl;
cout<<"| | "<<endl;
cout<<"| Y 继续添加 | "<<endl;
cout<<"| | "<<endl;
cout<<"| N 返回主菜单 | "<<endl;
cout<<"|_______________________| "<<endl;
char cho;
cin>>cho;
if(cho=='Y' || cho=='y') goto add;
else
{ system("cls"); //清屏
goto menu;
}
break;
}
}
if(f1.eof())
cout<<"查询完毕,数据文件中无此号码,可以继续添加"<<endl;
f1.close();
ofstream outfile("mobilbook.txt",ios::app);
cout<<"请继续输入该号码的归属地(如:中国,呼和浩特):";
cin>>c;
cout<<endl<<endl;
string c1 = &(c[0]);
cout<<"您输入的号码及归属地为:"<<s<<","<<c<<endl;
cout<<" _______________________ "<<endl;
cout<<"| 请选择要进行的操作 | "<<endl;
cout<<"| | "<<endl;
cout<<"| Y 确认并保存 | "<<endl;
cout<<"| | "<<endl;
cout<<"| N 不保存 | "<<endl;
cout<<"|_______________________| "<<endl;
char ch;
cin>>ch;
if(ch=='Y' || ch=='y') goto y;
else goto menu;
y:
outfile<<"\n"<<s<<","<<c;
cout<<"存储成功!"<<endl;
goto a;
}
update: //修改代码
{ int i=0;
char s[8]; //定义一个号码段数组
cout<<"请输入要修改的手机号码前7位:"<<endl;
cin>>s;
string s1 = &(s[0]);
ifstream f1("mobilbook.txt");
while(!f1.eof())
{
f1>>a[i];
if (s1==a[i].substr(0,7))
{
//cout<<"您要修改的电话号码及归属地为: "<<a[i]<<endl;
tag=1;
break;
if(tag==0)
cout<<"无此号码!"<<endl;
cout<<" _______________________ "<<endl;
cout<<"| 请选择要进行的操作 | "<<endl;
cout<<"| | "<<endl;
cout<<"| Y 继续 | "<<endl;
cout<<"| | "<<endl;
cout<<"| N 返回主菜单 | "<<endl;
cout<<"|_______________________| "<<endl;
char ch;
cin>>ch;
if(ch=='Y' || ch=='y') goto update;
else
{ system("cls"); //清屏
goto menu;
}
}
}
goto menu;
}
o:
cout<<"\n\n\t欢迎再次使用手机号码归属地查询系统\n\n";
return 0;
}