| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2022 人关注过本帖, 1 人收藏
标题:C++手机号码归属地查询软件,急需解决的问题
只看楼主 加入收藏
叶吹雪
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-11-7
收藏(1)
 问题点数:0 回复次数:6 
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;
}

mobilbook.rar (255.86 KB) 磁盘文件

搜索更多相关主题的帖子: 手机号码 软件 查询 
2008-11-07 16:35
wyp02033
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-12-3
收藏
得分:0 
附件怎么下不了?
2008-12-03 22:34
newyj
Rank: 2
等 级:新手上路
威 望:3
帖 子:542
专家分:0
注 册:2008-1-4
收藏
得分:0 
goto 满天飞啊
还是 分成多个 函数 调用 比较清楚点
2008-12-03 23:11
peng_piao
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2008-11-5
收藏
得分:0 
goto的程序,我一律跳过
抱歉
2008-12-05 19:05
idxls
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-9-6
收藏
得分:0 
呵呵,有点汇编的韵味
2008-12-05 20:33
zhangyafei4353
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2008-11-28
收藏
得分:0 
望高手指点:只写了(2 添加)部分。。。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string a[140000];

class Mobilbook
{
    int tag;
    char s[8];             //定义一个号码段数组
    char c[50];            //归属地数组
public:
    Mobilbook()
    {
        tag=0;
    }
    void menu(int i);           //显示菜单
    void add();            //添加号码
};

int main( )
{
    int choice;
    Mobilbook MB;
    do
    {  
        MB.menu(0);
        cin>>choice;
        switch(choice)
        {
        case 0 :         break;
        case 1 :         break;
        case 2 :MB.add();break;
        case 3 :         break;
        default:         break;
        }
    }  while(choice!=0);
    return 0;
}


void Mobilbook::menu(int i)
{
    switch(i)
    {
    case 0:
        {
            system("cls");
            cout<<"\t\t ____________________________________  "<<endl;
            cout<<"\t\t&   欢迎使用手机号码归属地查询系统   & "<<endl;   
            cout<<"\t\t|         请选择要进行的操作         | "<<endl;
            cout<<"\t\t|                                    | "<<endl;
            cout<<"\t\t|                                    | "<<endl;
            cout<<"\t\t|                                    | "<<endl;
            cout<<"\t\t|                                    | "<<endl;
            cout<<"\t\t|                                    | "<<endl;
            cout<<"\t\t|                                    | "<<endl;
            cout<<"\t\t|      1 查询          2 添加        | "<<endl;
            cout<<"\t\t|                                    | "<<endl;
            cout<<"\t\t|      3 修改          0 退出        | "<<endl;
            cout<<"\t\t&____________________________________& "<<endl;
            cout<<"\n\t\t→请选择:"; break;
        }
    case 1:
        {    system("cls");
            cout<<"\t\t _______________________  "<<endl;
            cout<<"\t\t|   请选择要进行的操作  | "<<endl;
            cout<<"\t\t|                       | "<<endl;
            cout<<"\t\t|   Y 继续添加          | "<<endl;
            cout<<"\t\t|                       | "<<endl;
            cout<<"\t\t|   N 返回主菜单        | "<<endl;
            cout<<"\t\t|_______________________| "<<endl;
            cout<<"\n\t\t→请选择:"; break;
        }
    case 2:
        {    system("cls");
            cout<<"\t\t _______________________  "<<endl;
            cout<<"\t\t|   请选择要进行的操作  | "<<endl;
            cout<<"\t\t|                       | "<<endl;
            cout<<"\t\t|   Y 确认并保存        | "<<endl;
            cout<<"\t\t|                       | "<<endl;
            cout<<"\t\t|   N 不保存            | "<<endl;
            cout<<"\t\t|_______________________| "<<endl;    
            cout<<"\n\t\t→请选择:"; break;              
        }
    case 3:
        {
            cout<<"\t\t";
            system("pause");         break;
        }
    }
}

void Mobilbook::add()
{
    char ch;
    do
    {
        int i=0;
        menu(0);
        cout<<"\n\t\t●请输入要添加的手机号码前7位:";
        cin>>s;
        string   s1   =   &(s[0]);
        ifstream f1("mobilbook.txt");
        if(!f1.eof())
        {
            f1>>a[i];
            if (s1==a[i].substr(0,7))
            {
                cout<<endl<<"\t\t"<<a[i]<<endl<<"\t\t此号码已存在,请确认输入无误"<<endl;
                menu(3);                
            }
            else
            {
                cout<<"\t\t数据文件中无此号码,可以继续添加"<<endl;
                f1.close();
                ofstream outfile("mobilbook.txt",ios::app);
                cout<<"\t\t请输入该号码的归属地:";
                cin>>c;
                cout<<endl<<endl;
                string   c1   =   &(c[0]);
                cout<<"\t\t您输入的号码及归属地为:"<<s<<","<<c<<endl;
                menu(3);
                menu(2);
                char ch;
                cin>>ch;
                if(ch=='Y' || ch=='y')
                {
                    outfile<<"\n"<<s<<","<<c;
                    cout<<"\t\t存储成功!"<<endl;
                    menu(3);
                }
            }
        }
        menu(1);
        cin>>ch;
    }while(ch=='Y' || ch=='y');
}
2008-12-06 11:39
as698522
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-6-22
收藏
得分:0 
回复是美德~
2011-06-22 11:38
快速回复:C++手机号码归属地查询软件,急需解决的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.044831 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved