| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4055 人关注过本帖
标题:求教通讯录管理系统中的姓名按字典顺序排列
只看楼主 加入收藏
玉垒浮云
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2012-11-22
收藏
得分:0 
回复 9楼 mmmmmmmmmmmm
#include<iostream>
#include<vector>
#include<string>
using namespace std;
struct information
{
    string name;
    int number;
    string address;
};
int main()
{
    cout<<"◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl;
    cout<<"◆                                                                    ◆"<<endl;
    cout<<"◆                         § 简易通讯录 §                           ◆"<<endl;
    cout<<"◆                                                                    ◆"<<endl;
    cout<<"◆                                                                    ◆"<<endl;
    cout<<"◆         1.输入联系人信息 ☆            *      $$      *            ◆"<<endl;
    cout<<"◆                                             $◢◣$                 ◆"<<endl;
    cout<<"◆         2.查找联系人               *     $◢★◣$      *         ◆"<<endl;
    cout<<"◆                                           $◢■■◣$               ◆"<<endl;
    cout<<"◆         3.修改联系人信息 ☆              $◢■■■◣$              ◆"<<endl;
    cout<<"◆                                   *       ︸︸||︸︸        *      ◆"<<endl;
    cout<<"◆         4.显示所有联系人 ☆                   ||                   ◆"<<endl;
    cout<<"◆                                        *             *             ◆"<<endl;
    cout<<"◆         5.退出                                                   ◆"<<endl;
    cout<<"◆                                      °☆ .★°∴ ★. ☆ °        ◆"<<endl;
    cout<<"◆                                                                    ◆"<<endl;
    cout<<"◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl;
   
   
   
   
    vector<information>aa;
    information temp;
    int n;
    cout<<"please input the amount of pepole"<<endl;
    cin>>n;
               
    while(true)
    {
        int choice;
        cout<<"please choose 1~5"<<endl;
        cout<<" 1.输入联系人信息"<<endl;
        cout<<" 2.查找联系人"<<endl;
        cout<<" 3.修改联系人信息"<<endl;
        cout<<" 4.显示所有联系人"<<endl;
        cout<<" 5.退出"<<endl;
        
        while(true)
        {
            cin>>choice;
            if(choice<1||choice>5)
                cout<<"input error,please input again"<<endl;
            else
                break;
        }
        
        switch(choice)
        {
        case 1:
            {
                for(int i=0;i!=n;++i)
                {
                    cout<<"Please input name number address"<<endl;
                    cin>>temp.name>>temp.number>>temp.address;
                    aa.push_back(temp);
                }
            }
            break;
            
            
        case 2:
            {
                cout<<"please input name you want to look for"<<endl;
               
                string name1;
               
                cin>>name1;
                bool flag=0;
                for(vector<information>::iterator k=aa.begin();k!=aa.end();++k)
                {
                    if((*k).name==name1)
                    {
                        cout<<(*k).name<<"  "<<(*k).number<<"  "<<(*k).address<<endl;
                        flag=1;
                    }
                }
                if(!flag)
                    cout<<"check no such person"<<endl;
                }
            break;
        case 3:
            {   
                string name2,address2;
                int number2;
                cout<<"please input name2 that you want to revise"<<endl;
                cin>>name2;
                for(vector<information>::iterator f=aa.begin();f!=aa.end();++f)
                {
                    if((*f).name==name2)
                    {
                        cout<<"Please input name number address"<<endl;
                        cin>>name2>>number2>>address2;
                        (*f).name=name2;
                        (*f).number=number2;
                        (*f).address=address2;
                        cout<<(*f).name<<" "<<(*f).number<<"  "<<(*f).address<<endl;
                    }
                }
            }
            break;
        case 4:
            {   
                string t1;
                vector<information>::iterator h;
                for ( h=aa.begin();h!=aa.end()-1;++h)
                {
                    for(vector<information>::iterator f=h+1;f!=aa.end();++f)
                    {
                        if((*h).name>(*f).name)
                        {
                            t1=(*h).name;
                            (*h).name=(*f).name;
                            (*f).name=t1;
                        }
                    }
                }
                for ( h=aa.begin();h!=aa.end();++h)
                    cout<<(*h).name<<" "<<(*h).number<<" "<<(*h).address<<endl;
               
            }
            break;
        case 5:
            cout<<"Goodbye!!!!"<<endl;
            break;
        }
    }
    return 0;
    }
   
用这个吧,比较简单易懂
2012-12-11 11:08
快速回复:求教通讯录管理系统中的姓名按字典顺序排列
数据加载中...
 
   



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

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