In: Computer Science
Sample input: Sample Output:
800-MATTRESS 800-628-8737 (leave off the last “S”)
800-mattress 800-628-8737 (leave off the last “S”)
Sample input: Sample Output:
8 8
0 0
0 0
M 6
A 2
T 8
T 8
R 7
E 3
S 7
(2) If they do not wish to convert a telephone letter pattern, the program should
terminate
(3) Valid values that the user can enter as to whether they wish to execute the
program are: ‘Y’ or ‘y’ or “N’ or ‘n’ .
(a) All other responses should error out and user the should be requested to
enter a valid response.
1 |
2: ABC |
3: DEF |
4: GHI |
5: JKL |
6: MNO |
7: PQRS |
8: TUV |
9: WXYZ |
* |
0 |
# |
A counter should keep track of how many telephone button conversions have been processed on and printed on the report.
A solid line of separators such as the **** or #### should be placed between each telephone button conversion done.
Place a good descriptive heading at the top of the report below the required first several output lines indicated at the top of this document.
At least three separate conversions should be processed.
D. Save the program with the name: Lab4tele.cpp
E. Test Data:
Test Case Number |
Phrase |
Output |
1 |
800-Compute |
? |
2 |
808-Science |
? |
3 |
888-Program |
? |
F. For this program, hand in:
PLEASE USE ANY LOOP(FOR, WHILE, DO). DO NOT USE STRINGS OR ARRAYS.
thanks for the question, here is the complete code in C++.
Have used two while loops and have not used string or arrays : )
thanks, let me know for any questions or help. if you are satisfied please do rate.
===================================================================
# include <iostream>
using namespace std;
// takes in a character and decodes the character and returns it
char getDigit(char letter){
if('0'<=letter && letter<='9') return letter;
switch(letter){
case 'a':case 'b' : case 'c' : case 'A':case 'B' : case 'C' : return '2';
case 'd':case 'e' : case 'f' : case 'D':case 'E' : case 'F' : return '3';
case 'g':case 'h' : case 'i' : case 'G':case 'H' : case 'I' : return '4';
case 'j':case 'k' : case 'l' : case 'J':case 'K' : case 'L' : return '5';
case 'm':case 'n' : case 'o' : case 'M':case 'N' : case 'O' : return '6';
case 'p':case 'q' : case 'r' : case 's':case 'P' : case 'Q' : case 'R': case 'S': return '7';
case 't':case 'u' : case 'v' : case 'T':case 'U' : case 'V' : return '8';
case 'w':case 'x' : case 'y' : case 'z':case 'W' : case 'X' : case 'Y': case 'Z': return '9';
}
}
int main(){
char repeat;
do{
cout<<"Enter the 10 letter sequence you like to convert : ";
int digitsPrinted = 0;
char character;
while (digitsPrinted<10){
cin>>character;
if(('0'<=character && character <='9') ||
('a'<=character && character <='z') ||
('A'<= character && character <='Z') ){
cout<<getDigit(character) ;
digitsPrinted++;
if(digitsPrinted==3 || digitsPrinted==6) cout<<"-";
}
}
cin.ignore(1024,'\n'); // flush all extra characters
cout<<endl<<"============"<<endl;
do{
cout<<"Do you want to repeat again (y/Y/n/N): ";
cin>> repeat;
if((!(repeat=='Y' || repeat=='y' || repeat =='n' || repeat == 'N')))cout<<endl<<"Sorry: Invalid character entered\n\n";
}while(!(repeat=='Y' || repeat=='y' || repeat =='n' || repeat == 'N'));
}while(repeat=='y' || repeat =='Y');
}
===================================================================