In: Computer Science
C++.
Write a program that asks the user to enter a single word and
outputs the series of ICAO words that would be used to spell it
out. The corresponding International Civil Aviation Organization
alphabet or ICAO words are the words that pilots use when they need
to spell something out over a noisy radio channel.
See sample screen output for an example:
Enter a word: program Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha Mike |
The specific requirement is that you write the program so that it
determines the word corresponding to a specified letter
using a Switch statement instead of an If
structure.
As a point of reference, the ICAO alphabet is included
below:
A Alpha N November B Bravo O Oscar C Charlie P Papa D Delta Q Quebec E Echo R Romeo F Foxtrot S Sierra G Golf T Tango H Hotel U Uniform I India V Victor J Juliet W Whiskey K Kilo X X-Ray L Lima Y Yankee M Mike Z Zulu |
HINT: You may consider using character (char) array related processing or if you prefer to work with strings, determine the length of the variable string word and iterate through each letter in the string word using a for loop with a nested switch statement that has the necessary case labels matching the ICAO alphabets. Suggest converting all letters to uppercase to match the ICAO alphabet format.
Be sure to use proper formatting and appropriate comments in your code. Provide appropriate prompts to the user. The output should be clearly labeled and neatly formatted.
Code Explanation:
Code:
#include <iostream>
#include<string.h>
using namespace std;
int main()
{
int n, i = 0;
char word[100];
cout << "Enter a word: ";
cin >> word;
n =strlen(word);
cout << "Phonetic version is: ";
while(i!=n)
{
switch((char)toupper(word[i]))
{
case 'A' : cout << "Alpha ";
break;
case 'B' : cout << "Bravo "; break;
case 'C' : cout << "Charlie "; break;
case 'D' : cout << "Delta "; break;
case 'E' : cout << "Echo "; break;
case 'F' : cout << "Foxtrot "; break;
case 'G' : cout << "Golf "; break;
case 'H' : cout << "Hotel "; break;
case 'I' : cout << "India "; break;
case 'J' : cout << "Juliet "; break;
case 'K' : cout << "Kilo "; break;
case 'L' : cout << "Lima "; break;
case 'M' : cout << "Mike "; break;
case 'N' : cout << "November "; break;
case 'O' : cout << "Oscar "; break;
case 'P' : cout << "Papa "; break;
case 'Q' : cout << "Quebec "; break;
case 'R' : cout << "Romeo "; break;
case 'S' : cout << "Sierra "; break;
case 'T' : cout << "Tango "; break;
case 'U' : cout << "Uniform "; break;
case 'V' : cout << "Victor "; break;
case 'W' : cout << "Whiskey "; break;
case 'X' : cout << "X-Ray "; break;
case 'Y' : cout << "Yankee "; break;
case 'Z' : cout << "Zulu "; break;
default: cout << "default char";
}
i++;
}
cout << "\n";
return 0;
}
Sample O/P1:
Enter a word: program
Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha
Mike
Sample O/P2:
Enter a word: Apple
Phonetic version is: Alpha Papa Papa Lima Echo
Sample O/P3:
Enter a word: NewYork
Phonetic version is: November Echo Whiskey Yankee Oscar Romeo
Kilo
Code Screenshot:
Sample O/P1 screenshot:
Sample O/P2 screenshot:
Sample O/P3 screenshot: