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.
In: Computer Science
Hey, please write in c++. This a two-part lab but I did not put them on a separate question then it would be confusing to the who is answering it. The first part is already done and the code is down below but I wanted to provide the instructions for it just in case.
Please follow the instructions and provide comments helps me understand if you could, make sure the code meets all the criteria, It should be an easy assignment it should be creating a hangman game.
Please Help and thank you.
use the same code for part 2 use the code I provide, don't make
separate codes for each part.
If you have any questions please let me know
-----------------------------------------------------------------
First part
I already have the file don't worry about it
moon racecar program cat word
Sample Run #1 (bold, underlined text is what the user types):
Game? 3 L----+---- | | | X L----+---- | O | | X L----+---- | O | | | X L----+---- | O | /| | X L----+---- | O | /|\ | X L----+---- | O | /|\ | / X L----+---- | O | /|\ | / \ X You lost Answer: program
This the code for this first part, use it to do the second part, please.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int hangman_level = 0;
int game_no;
int guess_char;
int word_len;
int match_count = 0;
string word;
/*
*
* Getting initial inputs from user
*
*/
game_no = getGameNumberFromUser();
word = getWordFromFile(game_no);
word_len = word.length();
/*
* Drawing initial hangman figure
*/
drawHangman(hangman_level);
while (true)
{
/*
* Iterate until win or loose
*/
guess_char = getGussedCharFromUser();
/*
* Compare guessed char with word char
*/
if (guess_char == word[match_count])
{
match_count++;
}
else
{
hangman_level++;
}
/*
* Draw next level hangman figure
*/
drawHangman(hangman_level);
/*
* Checking if hangman drwan completely
* if so the user will loose geme
*/
void drawHangman(int level)
{
/*
* Drawing hangman levels
*/
switch (level)
{
case 0:
cout << 'L' << "----+----" << endl;
cout << '|' << endl << "|" << endl <<
"|" << endl << "X" << endl;
break;
case 1:
cout << 'L' << "----+----" << endl;
cout << "| O" << endl << "|" << endl
<< "|" << endl << "X" << endl;
break;
case 2:
cout << 'L' << "----+----" << endl;
cout << "| O" << endl << "| |" << endl
<< "|" << endl << "X" << endl;
break;
case 3:
cout << 'L' << "----+----" << endl;
cout << "| O" << endl << "| /|" << endl
<< "|" << endl << "X" << endl;
break;
case 4:
cout << 'L' << "----+----" << endl;
cout << "| O" << endl << "| /|\\" << endl
<< "|" << endl << "X" << endl;
break;
case 5:
cout << 'L' << "----+----" << endl;
cout << "| O" << endl << "| /|\\" << endl
<< "| /" << endl << "X" << endl;
break;
case 6:
cout << 'L' << "----+----" << endl;
cout << "| O" << endl << "| /|\\" << endl
<< "| / \\" << endl << "X" << endl;
break;
}
}
/*
* Getting a word from file
*/
string getWordFromFile(int pos)
{
string word;
ifstream ifstr;
ifstr.open("word.txt");
for (int i = 0; i < pos - 1; i++)
{
ifstr >> word;
}
ifstr >> word;
ifstr.close();
return word;
}
/*
* Getting game number from user
*/
int getGameNumberFromUser()
{
int game_no;
cout << "Enter game number: ";
cin >> game_no;
return game_no;
}
int getGussedCharFromUser()
/*
* Getting a guessed character from user
*/
{
char guess_char;
cout << "Enter ypur guess: ";
cin >> guess_char;
return guess_char;
}
if (hangman_level == 6)
{
cout << "You lost !!!" << endl;
cout << "Correct word: " << word << endl;
break; // break statement is encountered inside a loop, the loop is
immediately terminated and program control resumes at the next
statement following the loop
}
/*
* checking if whole word guessed correctly
* if so, user win
*/
if (match_count == word_len)
{
cout << "Congrats you won !!!" << endl;
break; // break statement is encountered inside a loop,
the loop is immediately terminated and program control resumes at
the next statement following the loop
}
}
cout << "Game Over" << endl;
return 0;
}
-------------------------------------------------------
Part 2
Sample Run #1 – user wins (bold, underlined text is what the user types):
Game? 3 L----+---- | | | X ******* ? a L----+---- | | | X *****a* ? b Oops L----+---- | O | | X *****a* ? c Oops L----+---- | O | | | X *****a* ? p L----+---- | O | | | X p****a* ? r L----+---- | O | | | X pr**ra* ? o L----+---- | O | | | X pro*ra* ? g L----+---- | O | | | X progra* ? m L----+---- | O | | | X Congrats! Answer: program
Sample Run #2 – user loses (bold, underlined text is what the user types):
Game? 3 L----+---- | | | X ******* ? a L----+---- | | | X *****a* ? b Oops L----+---- | O | | X *****a* ? c Oops L----+---- | O | | | X *****a* ? d Oops L----+---- | O | /| | X *****a* ? e Oops L----+---- | O | /|\ | X *****a* ? f Oops L----+---- | O | /|\ | / X *****a* ? g L----+---- | O | /|\ | / X ***g*a* ? h Oops L----+---- | O | /|\ | / \ X You lost Answer: program
In: Computer Science
What is the scientific explanation of daydreaming? Is there a word for it from the textbook? What kind of brain activity is observed during this time? What about dreaming at night? What is the underlying mechanism of dreaming? Do other animals dream? Provide at least 3 references
In: Biology
Design an algorithm for each of the exercises and type it into a word document. Upload the document to PE1 assignment folder.
Design an algorithm to find the real roots of a quadratic equation of the form ax2+bx+c=0, where a, b, c are all real numbers and a is nonzero
In: Electrical Engineering
define these definitions along with the word and
meaning of the teram
these the should be define term and the definition. in International relation course
5. Interstate/international system
6. Sovereignty
7. The New Deal
8. Cold War
9. Mutually Assured Destruction (MAD)
In: Economics
A palindrome is a string of characters (a word, phrase, or sentence) that is the same regardless of whether you read it forward or backward – assuming that you ignore spaces, punctuation and case. For example, Race car is a palindrome. So is A man, a plan, a canal: Panama.
1. Describe how you could use a stack to test whether a string is a palindrome.
2. Describe how you could use a queue to test whether a string is a palindrome.
In: Computer Science
In: Economics
please post a significant fact about the brain in your own words. Word count 150
In: Biology
IPE: Did the focus on sustainable development cause the failure of the Doha Round? Word Limit: 1000
In: Economics
PLEASE POST A SIGNIFICANT FACT ABOUT ASTHMA IN YOUR OWN WORDS. WORD MINIMUM 150
In: Biology