3.6k views
2 votes
Your mission is to read this uber-classified memo from the Grand Poobah of annan. Of course, it's in code, so you'll need to write a program 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 separate 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 variable (secrets1, secrets2, secrets3 & secreets4) from Step a. (You'll have to do this with 4 lines of code; you can't use a loop for it.) c. Write a void function called decode that will i. Accept an array of strings, and the integer array length as the parameters. ii. Read through each word in the array. If the word is in the nth position of the array, then print the nth letter for that word. (For array item 0, print the letter at position 0 in the word. For array item 1, print the letter at position 1 in the word...etc.) Print all of the letters from this array on one line. iii. Print a blank

User Ariadne
by
3.2k points

1 Answer

6 votes

Answer:

Following are the code to this question:

#include<iostream>//declaring header file

using namespace std;

void decode(string* arr, int n)//defining a method decode

{

for(int i = 0; i < n; i++)//defining a loop for print value

{

cout << arr[i][i] << " "; // using print method to print ith letter of the string

}

cout << endl;//line break

}

int main()//defining main method

{

string secret1[] = {"platypus","plethora","trend","croak","almost","toaster"};//defining string arry and assign value

string secret2[] = {"fire","seen","trend","produce"};//defining string arry and assign value

string secret3[] = {"tiretread","chains","stern","bed bug"};//defining string arry and assign value

string secret4[] = {"oracle","stetson","mother","stie","twigrot"};//defining string arry and assign value

decode(secret1, 6);//calling method decode and pass string array and integer number

decode(secret2, 4);//calling method decode and pass string array and integer number

decode(secret3, 4);//calling method decode and pass string array and integer number

decode(secret4, 5);//calling method decode and pass string array and integer number

return 0;

}

output:

Please find the attachment.

Step-by-step explanation:

In the above C++ language code, a method "decode" is declared that accepts a string array and an integer variable in its parameter, inside the method a for loop is declared, which is used "n" variable to print its
i^(th) letter value in the given string value.

In the main method, 4 string array "secret1, secret2, secret3, and secret4" is declared which assigns some value, and then we call the method "decode" and pass string array value and an integer value in its parameter.

Your mission is to read this uber-classified memo from the Grand Poobah of annan. Of-example-1
User Dardisco
by
3.4k points