7.1k views
2 votes
Write a C program that inputs a letter and outputs the corresponding International Civil Aviation Organization (ICAO) alphabet word (these are the words that pilots use when they need to spell something out over a noisy radio channel). Do not use case statements. If you do, you will receive no credit on this assignment! The alphabet is as follows: 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 use proper formatting and appropriate comments in your code. Provide appropriate prompts to the user. The output should be labeled clearly and formatted neatly. Be sure to properly comment your code.

User Brakke
by
5.7k points

1 Answer

3 votes

Answer:

Here is the C++ program:

#include<iostream> //to use input output functions

using namespace std; //to identify objects like cin cout

int main() { //start of main function

char input; // to store the input letter

string output; // to store the corresponding ICAO

string ICAO[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"}; // array of ICAO words

cout << "Enter a letter: " << endl; //prompts user to input a letter

cin >> input; //reads input letter from user

cout<<"You entered: "<<input<<endl; // prints the letter input by user

char letter; //declare a variable to hold the input letter

letter = tolower(input); //converts the input letter to lowercase

if(isalpha(letter)) //checks if the input is an alphabetic letter

{cout << "The corresponding International Civil Aviation Organization (ICAO) alphabet word: "; //prints this message

output = ICAO[letter - 'a']; //computes the corresponding ICAO for input letter

cout << output; } //prints the corresponding ICAO of input letter

else //if input is not a letter

cout << "Error: " << input << " is not a letter!" << endl; } //displays this error message

Step-by-step explanation:

The program first prompts the user to input a letter. It then converts the letter to lower case if the input letter is an uppercase letter. It stores that letter to letter variable. Now it checks whether the letter is an alphabet by using isalpha() method that return true if the letter is an alphabet. If the letter is an alphabet then it computes its corresponding ICAO by looking in to the ICAO array for the input letter. It then displays its corresponding ICAO word. If the value of letter is not an alphabet i.e. when isalpha returns false then else part is executed which displays an error message. The program along with its output is attached in a screenshot.

Write a C program that inputs a letter and outputs the corresponding International-example-1
User HeWillem
by
5.0k points