资源预览内容
第1页 / 共12页
第2页 / 共12页
第3页 / 共12页
第4页 / 共12页
第5页 / 共12页
第6页 / 共12页
第7页 / 共12页
第8页 / 共12页
第9页 / 共12页
第10页 / 共12页
亲,该文档总共12页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
C+程序设计比赛题解,第一题,1. 从键盘输入若干个同学的姓名(使用拼音表示),按字典顺序排序后输出。要求利用C+标准模板库STL或者你熟悉的其他类库编程实现。,#include #include #include #include using namespace std; int main() list lst; string c; int i; for(i=0;ic; lst.push_back(c); cout :iterator p=lst.begin( );,while(p!=lst.end() cout*pendl; p+; coutendl; lst.sort(); cout“排序后“; p=lst.begin(); while(p!=lst.end() cout*pendl; p+; return 0; ,第二题,2. 设计一个简单的电话本软件。当用户从键盘输入联系人的姓名,能够查找到对应的电话号码。要求利用C+标准模板库或者你熟悉的其他类库编程实现。,#include #include #include using namespace std; int main() map m; int i,n; string s; char name20,phone20; coutn; getchar(); for (i=0;i (name,phone); ,cout :iterator p; p = m.find(s); if( p != m.end() cout second endl; else cout s “s phone number is not in the phonebook.n“; return 0; ,第三题,3. 完成下列的MyString类的定义和实现,并在主函数main( )中测试它。 class MyString public: MyString(const char *str = NULL); MyString(const MyString ,class MyString public: MyString(const char *str = NULL); MyString(const MyString ,MyString:MyString(const char *str) int length=strlen(str); m_data=new charlength+1; strcpy(m_data,str); MyString:MyString(const MyString ,MyString ,ostream ,
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号