Starting from:

$25

Programming - Project - 5 - Processing strings - Solved

In this project, you must solve one of two tasks, depending on how your program is executed.

For the first task, you will be given a phoneword (a phone number that spells a word by using the letters on your telephone keypad – see the picture below), and you must print its respective phone number. For instance, the phoneword 1-800-FLOWERS refers to the phone number 1-800-3569377.

  

For the second task, you will be given a letter and a phrase, and you must print the percentage of words in this phrase that contains this letter. For instance, the letter 'a' appears in 33.3% of the words in the sentence "you will pass".

Execution specification: 

For this project, your program will be run with command-line arguments. For the first task, a program named "a.out" will be executed as follows:

./a.out phone 

where the first argument "phone" indicates that the current test case is a valid input for the first task. For the second task, a program named "a.out" will be executed as follows:

./a.out phrase [a-z] 

where the first argument "phrase" indicates that the current test case is a valid input for the second task, and the second argument is the letter for which you must count the words.

Input specification: 

For the first task, the input contains a single line with the phone word, which has at most 15 characters. It only contains digits ('0' to '9'), hyphens ('-') and uppercase  letters ('A' to 'Z').

For the second task, the input contains a single line with a phrase. A phrase is a sequence of words separated by a single space. There will be no consecutive spaces. The minimum number of characters in a sentence is 1 and the maximum is 1000. All words are composed of lowercase letters only.

Output specification: 

For the first task, your program must print a single line with the phone number for the given phoneword. Digits and hyphens in the input are also part of the output. Do not forget the new-line character in the end.

For the second task, your program must print a single line with a number representing the percentage of words in the input phrase that contains the letter provided as a command-line argument. This value must have a single digit after the decimal point. Do not forget the new-line character in the end.  

Example #1: 

Command 
 
./a.out phone 
 
Input 
Output 
APP-OQI-LNX-THF 
277-674-569-843 
 

Example #2: 

Command 
 
./a.out phone 
 
Input 
Output 
1234-5678 
1234-5678 
 

Example #3: 

Command 
 
./a.out phone 
 
Input 
Output 
JF-CD-SHQ 
53-23-747 
 

Example #4: 

Command 
 
./a.out phrase a 
 
Input 
Output 
you will pass 
33.3 
 

Example #5: 

Command 
 
./a.out phrase k 
 
Input 
Output 
tusafydaxofazi aoybeme ibiranupu jufynosomop yyaoxikisajyuacug iluqu lajubadykyyem aoipot oeytu imua otabybaqyly vijofem anoaaco yfyzyt epayoiut eotegic aemopyz agouyaye emyxueuoovauewun ysyoaqihitycoviwe oyzib edetejaiovud geeykak 
13.0 
 

Example #6: 

Command 
 
./a.out phrase e 
 
Input 
Output 
you will pass 
0.0 
 

More products