📄 phonekey.cpp
字号:
//**************************************************
// Filename: phonekey.cpp
//Enter letter and print the corresponding phone key
//Programming Problems No.4 on P347 of textbook.
//**************************************************
#include<iostream>
using namespace std;
void Convert(char,bool&); //To convert letter into telephone number
//and print it.
int main()
{
char inchar; //The character the user input
bool quit=false; //True if the user wants to quit
do
{
cout<<"Enter a letter:";
cin >>inchar;
Convert(inchar,quit);
}while(!quit);
return 0;
}
void Convert(char inchar,
bool& quit)
//While the user has entered a character,test it and if valid,
//convert it into telephone number and print it.
{
//Test data
if(inchar=='Q' || inchar=='Z')
{
cout<<"Quit."<<endl;
quit=true;
return;
}
else if(inchar<'A' || inchar>'Z')
{
cout<<"Invalid letter. Enter Q or Z to quit."<<endl;
return;
}
//Convert and print
cout<<"The letter "<<inchar<<" corresponds to ";
if(inchar=='A' || inchar=='B' || inchar=='C')
cout<<'2';
else if(inchar=='D' || inchar=='E' || inchar=='F')
cout<<'3';
else if(inchar=='G' || inchar=='H' || inchar=='I')
cout<<'4';
else if(inchar=='J' || inchar=='K' || inchar=='L')
cout<<'5';
else if(inchar=='M' || inchar=='N' || inchar=='O')
cout<<'6';
else if(inchar=='P' || inchar=='R' || inchar=='S')
cout<<'7';
else if(inchar=='T' || inchar=='U' || inchar=='V')
cout<<'8';
else if(inchar=='W' || inchar=='X' || inchar=='Y')
cout<<'9';
cout<<" on the telephone."<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -