Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a C++ assignment It wants editor use string function to create an anagra

ID: 3667351 • Letter: T

Question

This is a C++ assignment

It wants editor use string function to create an anagrammatism. But I don’t know how to make a word become a charade. Such as I want make “world” become “_ _ _ _ _“. I want make each letters in word “world” means independent“_”, if user guess letter “ l ” the answer will be show as “_ _ _ l _”.

(This is a part of example:

Do you want to spin (1), solve the puzzle (2), or buy a vowel (3): 1

Guess a letter: n

The message is N _ _ _ _ n _ _    _ _ _ _ _    _ _ _ _ _ _)

Also there is a word group, not just simple word.

Just tell me how to create a puzzle, please. Thank you.

Explanation / Answer

Let W be your word and l be the length of the word.
Take two char arrays of size l.
One array is for storing the word.
other array to store the message that has to be printed.

Code: May be helpful.

string w="World";
int l=w.length();
char arr1[l];
char arr2[l];
for(int i=0;i<l;i++){
   arr1[i]=w[i];
}
for(int i=0;i<l;i++){
   arr2[i]="_";
}


When an user inputs a character(Let it be c) ,traverse the arr1 to know where the character matches the character in the array(let it be index) and replace "_" in arr2 at index with the character c.


Example:

arr1="World"
arr2="_ _ _ _ _";
c=r
c matches with the index 2 in arr1.
So go to index 2 in arr2 and replace "_" with c.
Now arr2 will look as follows.

arr1="World"
arr2="_ _ r _ _";

Now you can directly print arr2 directly to the console.
Hope this helps you.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote