Questions
C++. Write a program that asks the user to enter a single word and outputs the...

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...

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

  • This program is part 1 of a larger program. Eventually, it will be a complete Hangman game.
  • For this part, the program will
    • Prompt the user for a game number,
    • Read a specific word from a file,
    • Loop through and display each stage of the hangman character
      • I recommend using a counter while loop and letting the counter be the number of wrong guesses. This will help you prepare for next week
    • Print the final messages of the game.
    • NOTE: Look at the sample run for the prompt, different hangman pictures, and final messages.
  • You must have at least 3 functions other than main:
    • Function to prompt the user for a game number.
    • Function to read the appropriate word from the file based on the game number
      • If number is 1, then read the first word
      • If number is 2, then read the second word and so on
    • Function to print the correct hangman picture based on the number of wrong guesses

I already have the file don't worry about it

  • The file with the game words is called, word.txt. An example is:
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

  • This program is part 2 of the Hangman program. keep building on last week’s Hangman.cpp
  • For this part, the program will need to:
    • If the user enters a number less than 1 for the game, then randomly select a game between 1 and 5
    • Add a function to make a copy of the word. Replace all characters with a ‘*’. You can use this to display the current state of the hangman game to the user
      • You can get the number of characters in string s, by calling s.length()
      • You can access a single character in the string with s.at(i) where i is a number between 0 and the length-1. For example, s.at(i) = ‘*’ will change the first character of s to ‘*’
      • And here’s an example to print each character in the string, one per line:
        • for (int i = 0; i < s.length(); i++)
        • {
          • cout << s.at(i) << endl;
        • }
    • Add a function to let the user make the next guess.
      • It should update any of the *’s to the guess letter if it matches
      • It should update the number of wrong guesses if the guess doesn’t match any letter in the word AND print a message to the user
    • main() will need to call your 2 new functions, stop when the user has solved the puzzle or exhausted all of its wrong guesses, and it must print a congratulations message instead of the lost message if needed
    • You may add additional functions if you want.
    • Make sure that you display the current state of the game before each guess

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 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....

      Design an algorithm for each of the exercises and type it into a word document. Upload the document to PE1 assignment folder.

  1. The roots of quadratic equation:

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 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...

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

money problem because of covid 19 (500 word) for example why people need money

money problem because of covid 19 (500 word) for example why people need money

In: Economics

please post a significant fact about the brain in your own words. Word count 150

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:...

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

PLEASE POST A SIGNIFICANT FACT ABOUT ASTHMA IN YOUR OWN WORDS. WORD MINIMUM 150

In: Biology