Home / MCQ Bank / Computer
Computer Miscellaneous On Data Structures Difficulty: Medium

What will be output for the given code? #include<bits/stdc++.h> using namespace std; string encrypter(string keyword) { string encoded = ""; bool arr[26] = {0}; for (int i=0; i<keyword.size(); i++) { if(keyword[i] >= 'A' && keyword[i] <= 'Z') { if (arr[keyword[i]-65] == 0) { encoded += keyword[i]; arr[keyword[i]-65] = 1; } } else if (keyword[i] >= 'a' && keyword[i] <= 'z') { if (arr[keyword[i]-97] == 0) { encoded += keyword[i] - 32; alpha[keyword[i]-97] = 1; } } } for (int i=0; i<26; i++) { if(arr[i] == 0) { arr[i]=1; encoded += char(i + 65); } } return encoded; } string ciphertxt(string msg, string encoded) { string cipher=""; for (int i=0; i<msg.size(); i++) { if (msg[i] >='a' && msg[i] <='z') { int pos = msg[i] - 97; cipher += encoded[pos]; } else if (msg[i] >='A' && msg[i] <='Z') { int pos = msg[i] - 65; cipher += encoded[pos]; } else { cipher += msg[i]; } } return cipher; } int main() { string keyword; keyword = "cipher"; string encoded = encrypter(keyword); string message = "hello"; cout << ciphertxt(message,encoded) << endl; return 0; }

Select the correct option to test your answer:

More Computer Questions

What are Engine Adaptors? What is meant by vector in the container library contains? What is the result of an inorder traversal of a Binary Search Tree (BST)? What is the primary concern addressed by the European Union's ePrivacy Regulation (ePR) in data privacy? What is the output of the following code snippet? x = 5 while x > 0 puts x x -= 1 end