In: Computer Science
Introduction to Programming with C++ Third Edition. Y. Daniel Liang
Phone Key Pads:Write a program for Programming Exercise 4.15 on p.152 in the textbook.
Testing: Run the program for:
o The first three letters in your last name (all lowercase)
o The first three letters in your first name (all uppercase)
o Three invalid characters
use an old phone with 2 abc 3 def 4 ghi
#include<iostream>
using namespace std;
int main()
{
   char ch;
   cout<<"Enter a letter: ";
   cin>>ch;
   
   if(ch>='A' && ch<='Z'){
      ch = ch + 'a'-'A';
   }
   if(ch>='a' && ch<='z'){
      cout<<"The corresponding number is ";
      switch(ch){
         case 'a':
         case 'b':
         case 'c':
            cout<<"2"<<endl;
            break;
         case 'd':
         case 'e':
         case 'f':
            cout<<"3"<<endl;
            break;
         case 'g':
         case 'h':
         case 'i':
            cout<<"4"<<endl;
            break;
         case 'j':
         case 'k':
         case 'l':
            cout<<"5"<<endl;
            break;
         case 'm':
         case 'n':
         case 'o':
            cout<<"6"<<endl;
            break;
         case 'p':
         case 'q':
         case 'r':
         case 's':
            cout<<"7"<<endl;
            break;
         case 't':
         case 'u':
         case 'v':
            cout<<"8"<<endl;
            break;
         case 'w':
         case 'x':
         case 'y':
         case 'z':
            cout<<"9"<<endl;
            break;
         
      }
   }
       else{
          cout<<ch<<" is an invalid input"<<endl;
   }
       return 0;
}

