输入名字显示其电话号码
来源:互联网 发布:北大青鸟java培训 编辑:程序博客网 时间:2024/06/11 17:37
运行结果:
Enter a name to find the corresponding phone number. Ash Williams The number is: 333-2323 Look up another name? (y/n) y Enter a name to find the corresponding phone number. lenove Name not found. Look up another name? (y/n) n
findPhoneNumber.cpp
#include <iostream>#include <string>using namespace std;const string lookupName(const string&, const string*, const string*, int);int main() { string names[] = {"Michael Myers", "Ash Williams", "Jack Torrance", "Freddy Krueger"}; string phoneNumbers[] = {"333-8000", "333-2323", "333-6150", "339-7970"}; string targetName, targetPhone; char c; do { cout << "Enter a name to find the corresponding phone number.\n"; getline(cin, targetName); targetPhone = lookupName(targetName, names, phoneNumbers, 4); if (targetPhone.length() > 0) cout << "The number is: " << targetPhone << endl; else cout << "Name not found.\n"; cout << "Look up another name? (y/n)\n"; cin >> c; /* 有参示例:cin.ignore(5,'\n') 当从输入流(cin)中读取5个字符或该字符为'\n'时停止读取。 * 无参示例:cin.ignore(),仅从输入流(cin)中读取1个字符。 * / cin.ignore(); // 将字符y或n之后的'\n'读取并丢弃 } while (c == 'y'); return 0;}const string lookupName(const string& tN, const string n[], const string pN[], int len) { string pFind; for (int i = 0; i < len; i++) { if (tN == n[i]) pFind = pN[i]; } return pFind;}
0 0
- 输入名字显示其电话号码
- 关于电话号码的分割(包括显示与输入两方面)
- javascript实现输入名字列表并排序显示
- 简易电话号码输入本
- 电话号码等数字型输入
- 通讯录取电话号码和联系人名字
- 输入一串字符,然后将其颠倒显示出来
- css显示电话号码
- 电话号码用图片显示
- iOS TextField电话号码输入限制
- Android 输入电话号码自动空格
- android 文件浏览。打开sdcard文件夹。只显示文件夹和txt文件。选择txt文件返回其名字
- 文本框中默认显示出用户名,当输入名字的时候会覆盖用户名
- 电话号码框限制输入以及电话号码合法性验证
- 显示所有缓存名字
- 通话记录名字显示乱码
- NPC名字的显示
- 3G总机中文电话---让公司名字作电话号码
- poj 1523 SPF 无向图关节点
- Python+OpenCV学习(4)---图像梯度及边缘检测
- 阿里2015校招研发面试经验分享(已经拿到阿里意向书)
- PHP彩信接口开发经验及具体开发实现
- UVA 1626 区间DP
- 输入名字显示其电话号码
- Android Material Design知识汇总
- iOS远程推送
- 全双工 半双工 单工 通信,同步和异步(待续)
- CocoaPods pod install/pod update更新慢的问题
- Java高效读取大文件
- 一篇小文章搞定jni
- 第二周项目0
- iOS项目部分-控件-TextField常用方法