Programming Problem 1 in chapter 5 asked you to write a program that inputs a le
ID: 3621651 • Letter: P
Question
Programming Problem 1 in chapter 5 asked you to write a program that inputs a letter and outputs the corresponding word in the Internation Civil Aviation Organization (ICAO) phonetic alphabet. This problem asks you to turn that program into a function, and use it to convert a sring input by the user to the series of words that would be used to spell it out phonetically. For example:
Enter string: program
Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha Mike
For ease of reference, the ICAO alphabet is repeated here:
A Alpha
b Bravo
C Charlie
D Delta
E Echo
F Foxtrot
G Golf
H Hotel
I India
J Juliet
K Kilo
L Lima
M Mike
N November
O Oscar
P Papa
Q Quebec
R Romeo
S Sierra
T Tango
U Uniform
V Victor
W Whiskey
X X-ray
Y Yankee
Z Zulu
Be sure to user proper formatting and appropiate comments in your code. Provide appropiate prompts to the user. The output should be labled clearly and formatted neatly.
Explanation / Answer
#include<iostream.h>
#include<ctype.h>
int main()
{
char s[]="program";
cout << "Enter the String :" ;
char phonetic[][26] = {"Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India","Juliet","Kilo","Lima","Mike","November","Oscar","Papa","Quebec","Romeo","Sierra","Tango","Uniform","Victor","Whiskey","X-ray","Yankee","Zulu"};
for(int i=0; s[i]!=''; i++)
{
if(islower(s[i]))
s[i] = s[i]-32;
cout <<phonetic[s[i]-65]<<" ";
}
cout<<""<<endl;
return 0;
}
// compile online using codepad.org.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.