城市编程
① 求C++编程题一道 输入10~20个城市名,按字母顺序输出城市清单。 在线等!
支持任意数目城市,c++代码:
#include <iostream>
#include <list>
#include <string>
using namespace std;
bool compare(string first, string second)
{
unsigned int i=0;
while ( (i<first.length()) && (i<second.length()) )
{
if (first[i]<second[i]) return true;
else if (first[i]>second[i]) return false;
++i;
}
if (first.length()<second.length()) return true;
else return false;
}
int main()
{
int n, i;
list<string> mylist;
list<string>::iterator it;
string city;
cout << "输入将要输入的城市总数: ";
cin >> n;
cout << "请输入" << n << "个城市:" << endl;
for(i = 0; i < n; i ++) {
cin >> city;
mylist.push_back(city);
}
mylist.sort(compare);
cout << "排序后: " << endl;
for (it=mylist.begin(); it!=mylist.end(); ++it)
cout << *it << endl;
return 0;
}
② 如何编程区号对应城市该如何编写
请先创建区号与对应城市的数据库,然后再调用,如果不想创建数据库,那就只能用select case语句一个个写了,会累死的,全国几百个城市。
用C语言编程的区号查询系统,要求实现区号查询系统中,添加新记录、删除记录、显示记录信息、按城市查找信息和退出系统等功能。①录入有关城市的名称和区号。②显示所有城市的信息。③通过输
入城市名称查找对应城市的区号。
④通过输入城市
名称查找到要删除的城市信息,然后可以进行删除,会显当前该城市信息。⑤通过输入城市名称查找到要修改的城市信息,然后依次进行信息修改。
⑥添加城市信息。
