Question

In: Computer Science

Introduction to Programming with C++ Third Edition. Y. Daniel Liang Phone Key Pads:Write a program for...

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

Solutions

Expert Solution

#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;
}


Related Solutions

Book - Introduction to Programming Using Visual Basic 11th Edition by David I. Schneider Programming Language...
Book - Introduction to Programming Using Visual Basic 11th Edition by David I. Schneider Programming Language - Visual Studio 2017 RESTAURANT MENU Write a program to place an order from the restaurant menu in Table 4.13. Use the form in Fig. 4.70, and write the program so that each group box is invisible and becomes visible only when its corresponding check box is checked. After the button is clicked, the cost of the meal should be calculated. (NOTE: The Checked...
Write a Windows Form application named SumFiveInts. Microsoft Visual C#: An Introduction to Object-Oriented Programming,7th Edition....
Write a Windows Form application named SumFiveInts. Microsoft Visual C#: An Introduction to Object-Oriented Programming,7th Edition. Ch. 5, page 220. Take snip of program results.
Programming C: Write a program for a Rolodex of contact information (e.g., name, phone number, email)...
Programming C: Write a program for a Rolodex of contact information (e.g., name, phone number, email) implemented as a linked list. The program will ask the user to enter a new contact information, retrieve/print a person’s contact information, and to delete a person. It will maintain the linked list in alphabetical order by last name. It will also allow the user to search for a person’s contact information by last name. Assume that all last names are unique.
Introduction to CodeBlocks and C/C++ Program.
Introduction to CodeBlocks and C/C++ Program.
Python Programming 4th edition: Write a program that asks the user for the number of hours...
Python Programming 4th edition: Write a program that asks the user for the number of hours (float) and the pay rate (float) for employee pay role sheet. The program should display the gross pay with overtime if any and without overtime. Hints: Given base_hr as 40 and ovt_multiplier as1.5, calculate the gross pay with and Without overtime. The output should look like as follows: Enter the number of hours worked: Enter the hourly pay rate: The gross pay is $XXX.XX
Introduction Introduction to Data Structures programming assignments can be completed either in C++ (preferred) or in...
Introduction Introduction to Data Structures programming assignments can be completed either in C++ (preferred) or in Java. In both cases you cannot use libraries or packages that contain pre-built data structures, other than built-in support for objects, arrays, references, and pointers. Classes in C++ and Java can represent anything in the real world. This assignment is to write a compiler for Z++ programming language. The Z++ Programming Language Your program will test if an expression entered by the application user...
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a...
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program that uses repetition (i.e. “loops”) and decision structures to solve a problem. 2. PROBLEM DEFINITION  Write a Python program that performs simple math operations. It will present the user with a menu and prompt the user for an option to be selected, such as: (1) addition (2) subtraction (3) multiplication (4) division (5) quit Please select an option (1 – 5) from the...
Chapter 2, Problem 4E in An Introduction to Programming with C++ All of the employees at...
Chapter 2, Problem 4E in An Introduction to Programming with C++ All of the employees at Merks Sales are paid based on an annual salary rather than an hourly wage. However, some employees are paid weekly while others are paid every other week (biweekly). Weekly employees receive 52 paychecks; biweekly employees receive 26 paychecks. The payroll manager wants a program that displays two amounts: an employee’s weekly gross pay and his or her biweekly gross pay. Complete an IPO chart...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class definitions, one base class and three derived classes. The derived classes will have an inheritance relationship (the “is a” relationship) with the base class. You will use base and derived classes. The base class will have at least one constructor, functions as necessary, and at least one data field. At least one function will be made virtual. Class members will be declared public and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT