Question: Could you please show this program in C++ ? This is the assignment: Read in a code -- one character for each of the letters
Could you please show this program in C++ ? This is the assignment: Read in a code -- one character for each of the letters of the alphbet. Next, read in a message. Encode the message using the code. Repeat. For example: Enter the code: QWERTYUIOPASDFGHJKLZXCVBNM The code is: [Q][W][E][R][T][Y][U][I][O][P][A][S][D][F][G][H][J][K][L][Z][X][C][V][B][N][M] Incoming message: ABCD EFG: HIJ! Coded message: QWER TYU: IOP! Do you want to play again (Y/N)? N ALSO! You have to check that there are enough characters in the code. For example: Enter the code: [SOME CODE IS ENTERED WHICH IS LESS THAN 26 CHARACTERS] The code is not big enough! Do you want to play again (Y/N)? Y [CONTINUE]
This is what the output should be in C++
> Enter the code:
> The code is: > [Q][W][E][R][T][Y][U][I][O][P][A][S][D][F][G][H][J][K][L][Z][X][C][V][B][N][M]
> Incoming message: ABCD EFG: HIJ!
> Coded message: QWER TYU: IOP!
> Do you want to play again (Y/N)? Y
> Enter the code:
> The code is:
> [M][N][B][V][C][X][Z][L][K][J][H][G][F][D][S][A][P][O][I][U][Y][T][R][E][W][Q]
> Incoming message: ZYXW VUTS@
> Coded message: QWER TYUI@
> Do you want to play again (Y/N)? N
The begining of the program should be:
#include
#include
using namespace std;
int main()
string code; string message; char choice, ch; while(true) { cout << "Enter the code: "; getline(cin, code); if(code.size() < 26) { cout << "The code is not big enough!" << endl; } else { cout << "The code is:" << endl; for(int i = 0; i < code.length(); ++i) { cout << "[" << code[i] << "]"; } cout << " Incoming message: "; \\ here is where i am having the problem.. i can't get the program to output the message getline(cin, message); cout << "Coded message: "; for(int i = 0; i < message.size(); ++i) { ch = message[i]; if(ch >= 'A' && ch <= 'Z') { ch = code[ch-'A']; } cout << ch; } cout << endl; } cout << "Do you want to play again (Y/N)? "; cin >> choice; if(choice == 'N') { break; } getline(cin, code); }
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
