Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function that returns the digit value (an integer) corresponding to the

ID: 3543214 • Letter: W

Question

Write a function that returns the digit value (an integer) corresponding to the letter passed to it as an argument based on the encoding on your telephone handset. For example, if the argument is the letter a, b, or c (uppercase or lowercase), your function should return the digit 2. If the argument is not one of the letters of the alphabet, return a value of -1.  Implement two versions of the function: one using a switch statement and one using a nested if statement. Provide a program which tests each function (you may provide two separate source code files or combine them in one source code file which gives you the choice of which function to run).Analysis and Design Documentation,Make sure to incorporate decision steps in your algorithms (and code) to validate your inputs. The goal of validation is to verify that your input parameters meet the preconditions of the function.

Programming Project Analysis and Design Sheet

(Repeat this section for each of your functions). Provide the function prototype here.

Write a function that returns the digit value (an integer) corresponding to the letter passed to it as an argument based on the encoding on your telephone handset. For example, if the argument is the letter a, b, or c (uppercase or lowercase), your function should return the digit 2. If the argument is not one of the letters of the alphabet, return a value of -1. Implement two versions of the function: one using a switch statement and one using a nested if statement. Provide a program which tests each function (you may provide two separate source code files or combine them in one source code file which gives you the choice of which function to run).Analysis and Design Documentation, Make sure to incorporate decision steps in your algorithms (and code) to validate your inputs. The goal of validation is to verify that your input parameters meet the preconditions of the function.

Explanation / Answer

Program Analysis: Getting equaivalent integer for telephone character.
Program Inputs:    character
Program Outputs:   integer representing telephone character
Program Algorithm: recevie character from standard keyboard and call function to get corresponding integer
Program Test Plan: read several characters using input keyboard and call function to find corresponding integers.
Program Test Results: will be providied.
Functions
(Repeat this section for each of your functions). Provide the function prototype here.
Function Analysis: function to get equivalent integer.
Function Preconditions and Post Conditions: valid character..post condition is corresponding integer will be returned.
Function Inputs and Outputs: input character. output corresponding integer.
Function formulas: None
Function Algorithm: use switch

Function Analysis: function to get equivalent integer.
Function Preconditions and Post Conditions: valid character..post condition is corresponding integer will be returned.
Function Inputs and Outputs: input character. output corresponding integer.
Function formulas: None
Function Algorithm: use if check for every character....

#include<iostream>
using namespace std;
int equivalent_char(char ch)
{
switch(ch)
{
case 'a':
case 'b':
case 'c': return 2;
case 'd':
case 'e':
case 'f': return 3;
case 'g':
case 'h':
case 'i': return 4;
case 'j':
case 'k':
case 'l': return 5;
case 'm':
case 'n':
case 'o': return 6;
case 'p':
case 'q':
case 'r':
case 's':return 7;
case 't':
case 'u':
case 'v': return 8;
case 'w':
case 'x':
case 'y':
case 'z':return 9;
}
return -1;
}
int tele_char(char ch)
{
if(ch=='a' || ch=='b' || ch=='c') return 2;
else if(ch=='d' || ch=='e' || ch=='f') return 3;
else if(ch=='g' || ch=='h' || ch=='i') return 4;
else if(ch=='j' || ch=='k' || ch=='l') return 5;
else if(ch=='m' || ch=='n' || ch=='o') return 6;
else if(ch=='p' || ch=='q' || ch=='r' ||ch=='s') return 7;
else if(ch=='t' || ch=='u' || ch=='v') return 8;
else if(ch=='w' || ch=='x' || ch=='y' || ch=='z') return 9;
return -1;
}
int main()
{
char ch1,ch2,ch3,ch4;
cout <<"Enter a character (from a to z) :";
cin >> ch1;
cout << endl;
cout << "For character : " << ch1 << " corresponding integer using switch case is "<< equivalent_char(ch1) << endl;
cout <<"Enter a character (from a to z) :";
cin >> ch2;
cout << endl;
cout << "For character : " << ch2 << " corresponding integer using switch case is "<< equivalent_char(ch2) << endl;
cout <<"Enter a character (from a to z) :";
cin >> ch3;
cout << endl;
cout << "For character : " << ch3 << " corresponding integer using nested if is "<< tele_char(ch3) << endl;
cout <<"Enter a character (from a to z) :";
cin >> ch4;
cout << endl;
cout << "For character : " << ch4 << " corresponding integer using nested if is "<< tele_char(ch4) << endl;
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote