Congratulations! You’ve been inducted into the secret society of ~~~~~~~~. (Sorry, it’s so secret that I’m not allowed to tell you its name.)
Your mission is to read this uber-classified memo from the Grand Poobah of ~~~~~~~~. Of course, it’s in code, so you’ll need to write a program in C++ to decrypt your message.
The code is set up so that for the nth element in the array, you will need to read its nth letter. (Ex: if pirates is in array position 0, then print letter 0 of the word, which = p.
if gangway is in array position 4, then print letter 4 = w.)
To accomplish this, your main function should do the following:
A. Declare 4 arrays of strings called secrets1, secrets2, secrets3, & secrets4 and assign them the following values:
secrets1: { "platypus", "plethora","trend", "croak","almost", "toaster" };
secrets2: { "fire", "seen","trend", "produce" };
secrets3: { "tiretread", "chains", "stern", "bed bug" };
secrets4: { "oracle", "stetson","mother", "stie", "twigrot" };
B. Call the function decode 4 times – once for each array from #a (in order)
C. Write a void function called decode that will
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
#include<iostream>
using namespace std;
//method to decode the plain text hidden in an array of strings
void decode(string arr[], int length){
//looping through each element
for(int i=0;i<length;i++){
//printing ith character of element at index i
cout<<arr[i][i];
}
//line break
cout<<endl;
}
int main(){
string secrets1[] { "platypus", "plethora","trend", "croak","almost", "toaster" };
string secrets2[] { "fire", "seen","trend", "produce" };
string secrets3[] { "tiretread", "chains", "stern", "bed bug" };
string secrets4[] { "oracle", "stetson","mother", "stie", "twigrot" };
//decoding all 4 arrays
decode(secrets1,6);
decode(secrets2,4);
decode(secrets3,4);
decode(secrets4,5);
return 0;
}
/*OUTPUT*/
please
feed
the
otter
Congratulations! You’ve been inducted into the secret society of ~~~~~~~~. (Sorry, it’s so secret that I’m...