C++ Given Code: #include <iostream> #include <string> using namespace std; int main() { //declare variables to store user input bool cont = true; //implement...

50.1K

Verified Solution

Question

Programming

C++
Given Code:

#include
#include
using namespace std;


int main()
{
//declare variables to store user input

bool cont = true;

//implement a loop so that it will continue asking until theuser provides a positive integer
// the following provides ONLY part of the loop body, which youshould complete
{
cout <<\"How many words are in your message? \n\";
cout <<\"Enter value: \";

// get user input integer here
  
cout <<\"\nInvalid value. Please Re-enter a number of positivevalue\n\";

}

//declare a dynamic array of string type with the specifiednumber of elements

  
  
//
while(cont)
{
cout <<\"\nSelect one of these options: (1) Get Message (2)Encrypt (3) Print (4) Quit\";
cout <<\"\nSelection: \";

// obtain user input option (an integer)

// based on the input the program will perform one of the followingoperations using switch statement
switch(selection)
{
case 1://Get Message

// Get the specified number of words from the user

break;

case 2: //Encrypt

// Based on the shifting encryption strategy described above,encrypt the individual words
// Be careful about the difference between the lower case lettersand upper case letters
  
break;

case 3: //Print

// Print out the encrypted words

break;

case 4:
cont = false;
break;

default:
break;
}
}
  
// Remember to release the memory you allocate above!!
  
return 0;

}


Encryption using Pointers and Dynamic Arrays

Objective:

Agent James Vond, one of our secret agents, Agent 008, hasrecently been captured in the Caribbean. We have been able toestablish contact with him, but need help sending him messages insecret to let him know help is on the way. We believe we can sendhim messages using a Caesar Cipher, but need your help encoding it.Agent Vond, we task you with encrypting the message and helpingAgent 008 escape the Caribbean

Sincerely, M.

Assignment:

The Caesar Cipher technique is one of the earliest and simplestmethod of encryption. It’s a substitution cipher, i.e., each letterof a given text is replaced by a letter some fixed number ofpositions down the alphabet. For example with a shift of 1, A wouldbe replaced by B, B would become C, and so on.

The encryption equation is E(x) = (x + n) % 26.

The x = the numeric letter value, n = number of shifts, and (%26) is so that whatever value your result is, it will stay withinthe alphabet range (0-25).

However, since we will be looking at characters in strings, youneed to implement ASCII code so that your equation will look morelike:

letter = ( ( (letter - 'A') + shift ) % 26 + 'A')) if it isupper case

Or

letter = ( ( (letter - 'a') + shift ) % 26 + 'a' ) ) if it islower case.

You subtract 'A' and 'a' in order to get the value of theletter. In ASCII code, letters are assigned values. For example,'B' is 66. If I subtract the value of 'A' (65) then I get 1. Thishelps me encode because I can get the values 0-25 for eachletter.

Your assignment is to implement a dynamic string array in orderto store a message of variable length, and then a pointer toiterate through each letter of the string in order to encrypt itusing the equations given above.

You will need to ask the user for the amount of words in themessage and then create your dynamic array that way. If the amountof words is a negative number or equal to zero you should output tothe screen \"Invalid value. Please Re-enter a number of positivevalue\" until they have the correct input.

Get Message

Use cin to get each word the user wishes to put into themessage.

After they have input all the strings required, ask for thenumber of letter shifts they would like to do

Encrypt

Encrypt each letter in each string using the equations providedabove if the getMessage pointer isn't null (aka if Get Messageoption has already been called)

Print Message

Print out the encrypted or unencrypted message

Quit

Simply quits out of the loop

Input:

You many assume that the input to be encrypted will only consistof capital and lower letters, and no other symbols such as whitespaces, numbers, or special characters will have to beencrypted.

In order to choose the different options you will take aninteger value as input. 1 is for Get Message, 2 is for Encrypt, 3is for Print, 4 is for Quit

Requirements:

  • Use a dynamic array to store a message of variable length (notusing dynamic array will receive 50% penalty)

  • Use a pointer to iterate through each string and encrypt it

  • Do not allow for number of letter shifts to be > 26 (Must bein the range of 0-25 aka the range of 26) [Ex: If I give you 27,your shift should end up being 1] [Hint: %]

  • Do not expect int to hold all possible values when I input thevalue of shift, test very large numbers

  • Print out your message using pointer arithmetic (ex: *p;p++;)

  • DO NOT iterate through your pointer like an array whenprinting!!

Answer & Explanation Solved by verified expert
3.8 Ratings (454 Votes)
PGM STARTinclude include    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students