| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4055 人关注过本帖
标题:求教通讯录管理系统中的姓名按字典顺序排列
取消只看楼主 加入收藏
玉垒浮云
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2012-11-22
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:6 
求教通讯录管理系统中的姓名按字典顺序排列
#include<iostream>
#include<vector>
#include<string>
using namespace std;
struct information
{
    string name;
    int number;
    string address;
};
int main()
{
    vector<information>aa;
    information temp;
    int n;
    cout<<"please input the amount of pepole"<<endl;
    cin>>n;
   
    for(int i=0;i!=n;++i)
    {
        cin>>temp.name>>temp.number>>temp.address;
        aa.push_back(temp);
    }
   
   
    for(vector<information>::iterator j=aa.begin();j!=aa.end();++j)
    {
        
        cout<<(*j).name<<" "<<(*j).number<<" "<<(*j).address<<endl;
    }
    cout<<"please input name you want to look for"<<endl;

    string name1;
    cout<<"please input name1"<<endl;
    cin>>name1;
    for(vector<information>::iterator k=aa.begin();k!=aa.end();++k)
    {
        if((*k).name==name1)
            cout<<(*k).name<<(*k).number<<(*k).address<<endl;
    }
    return 0;
}
这是我的代码,缺一个按字典排序的功能,请大神指教
搜索更多相关主题的帖子: 管理系统 address include 通讯录 
2012-12-10 09:17
玉垒浮云
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2012-11-22
收藏
得分:0 
编写一个简易的通信录程序,具备输入、存储、排序、管理、查找等功能。
读入n个用户姓名、电话号码和地址,并按姓名的字典顺序排列。通过输入某一个人的姓名查找对应的电话号码和地址。如果查找的姓名不在电话簿中,则输出“查无此人”。
2012-12-10 09:20
玉垒浮云
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2012-11-22
收藏
得分:0 
如何实现按姓名的字典顺序进行排列?
2012-12-10 09:20
玉垒浮云
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2012-11-22
收藏
得分:0 
回复 4楼 rjsp
能详细点吗,不会啊!!!!
2012-12-10 10:17
玉垒浮云
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2012-11-22
收藏
得分:0 
回复 5楼 mmmmmmmmmmmm
详细点,可以吗,不会啊!!!
2012-12-10 10:17
玉垒浮云
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2012-11-22
收藏
得分:0 
回复 8楼 rjsp
#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;
    }
   
我已经会了,虽然你的我看不懂,但还是谢谢!!!还有我用的就是c++风格啊!!!!
2012-12-11 11:07
玉垒浮云
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.057517 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved