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

Your task is to use a secret code to code the input vector of strings. The secre

ID: 3835962 • Letter: Y

Question

Your task is to use a secret code to code the input vector of strings. The secret coding proceeds as follows - Write the message in a rectangular block, one row at a time. Then writes down the letters as they appear in the columns. Use a '!' if a letter is missing. For example, consider the input role college year student book The output would be - rcysb ooeto llauo elrdk !e!c! !g!n! !e!t! Feel free to use any vector and string methods. # include # include # include using namespace std; void secretCode(vector ∈); int main() {vector in; in.push_back("role"); in.push_back("college"); in.push_back("year"); in.push_bavk("student"); in.push_back("book"); cout

Explanation / Answer

#include <iostream>
#include <string>
#include <vector>

using namespace std;

void secretCode(vector<string>&in)
{
int max = 0, temp=0, min = 99999, k=0;
int arr[] = {1,3};
for(int i=0;i<in.size();i++)
{
temp = in[i].size();
//max = temp;
if(temp>max)
{
//arr[k++] = i+1;
max = temp;
}
if(min>temp)
{
min = temp;
}
}
//cout<<endl;
//for(int n=0;n<k;n++)
// cout<< arr[n]<<endl;
for(int i=0;i<min;i++)
{
for(int j=0;j<in.size();j++)
{
cout<<in[j].at(i);
}
cout<<endl;
}
for(int i=min;i<max;i++)
{
int j=0;
cout<<"!";
cout<<in[arr[j]].at(i);
cout<<"!";
cout<<in[arr[++j]].at(i);
cout<<"!"<<endl;

}
}

int main()
{
vector<string> in;
in.push_back("role");
in.push_back("college");
in.push_back("year");
in.push_back("student");
in.push_back("book");

cout<< "Before Secret Coding : " << endl;
for(int i=0;i<in.size();i++)
{
cout<<in[i]<<endl;
}
cout<< "After Secret Coding : " << endl;
secretCode(in);

return 0;
}