Thread: Need help with an assignment

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    6

    Need help with an assignment

    I can't figure out how to set up most of the program for this. Here is the assignment:

    Description
    Write a program that allows the user to enter any number of strings that will then be encoded, decoded and then displayed to the console. The program should request that the user enter a string to be encoded or ‘X’ (both X and x should work) to quit. The user will continue to enter strings, which you will immediately encode and store in the array, encodedData. When ‘x’/’X’ is entered, the program should then display all of the strings entered first in their decoded form, then their encoded form
    (should appear right beneath the decoded string; see sample run below). Each row of data should be numbered, starting with 1.


    Encoding
    Encoding should be done within a function called encode, which receives a string (raw data) and returns a string
    (encoded data). All keyboard characters, including white space, should be accepted and encoded, with the
    exception of our terminal value X/x. Each string is really just an array of characters, so you can loop through
    each string variable from 0 to yourStringVarName.length() and examine and encode one character at a time.
     Before you can start the encoding process, you will need to convert the character to its ASCII value,
    which is the (int) value of a character. Our encoding algorithms will be numerically based.
     The first alteration will be that each letter‘s ASCII value should decrease by three. This value (3 or -3,
    depending on how you write the code) should be stored in a constant. This variable should be used
    within the code, not the hard-coded number three.
     The second alteration will be that each odd (being in position 1, 3, 5, etc.) character’s ASCII value should
    be increased by five. The number five should be stored in a constant. This variable should be used
    within the code, not the number five.
     You will need to reverse this process to decode.
    You will need an array of strings called encodedData in which you will store the encoded string value returned from your encode function. You will not store the raw data entered by the user—only the encoded string. You will need to give the array a size when it’s declared, and you can use a value (CONSTANT) of 20. This is the
    maximum number of strings that can be stored in your array. Alternately you could use a vector to store the encoded data rather than an array, in which case you can just add “rows” as you go.


    Decoding
    Decoding should be done within a function called decode, which receives a string (encoded data) and returns a
    string (decoded data).

    Would someone help me by showing me an example of how this works? I got as far as this in the attachment.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,631
    Code:
    /*************************************************************
    	Author: Jordan Velez
    	Program Name: Lab #9 Chapter 7 - Arrays - Encoding Strings
    	Date: 4/8/2015
    
    	Program Description: This program loads the user's input 
    	into an array. The data of the user input is encoded with
    	a function and is then displayed. The encoded data then is 
    	received by a decoded function and is displayed in its ASCII 
    	value. When the user feels that he/she is finished, the user
    	will input the given input to terminate the program. 
    
    *************************************************************/
    
    #include<iostream>
    #include<string>
    #include<cstring>
    #include<cctype>
    using namespace std;
    
    //Function Prototypes
    string encode("raw data");
    string decode("raw data");
    
    //Global constant for string maximum length
    const int MAX_SIZE = 20;
    
    int main()
    {
    	string input = "", encodedData[MAX_SIZE];
    
    	cout << "Enter a string to be encoded or X to quit: " << endl;
    	cin >> input;
    
    }
    So in other words you haven't actually tried anything?

    You need to show some actual effort at trying to solve the exercise, not just dump your assignment with a basic "hello world" attempt.

    Jim

  3. #3
    Registered User
    Join Date
    Apr 2015
    Posts
    6
    No, I'm just a little lost on how to set it up. I had very little experience in programming and a little guidance would be helpful.

  4. #4
    Registered User
    Join Date
    Mar 2015
    Posts
    184
    well you need to keep getting input an undeterminded amount of times, until user inputs 'x' or 'X'... so what kind of basic flow control lets you do that?

    here I broke down the assignment into pseudocode for you:
    Code:
    //1: get input 
    //2: check if x or X (hint: check the available std::string methods)
    //3: if x/X display 2 arrays (with appropriate formatting):
      // encoded array
      // decoded array
    //4: then exit (return 0)  
    //5: if not x/X populate 2 arrays:
      // encoded array using function encode
      // decoded array using the plain input
    //go to 1: get input again
    Last edited by jiggunjer; 04-08-2015 at 12:56 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment help please
    By KC Teo in forum C++ Programming
    Replies: 4
    Last Post: 02-02-2014, 06:21 AM
  2. please i need help for my assignment
    By abo5aleil in forum C Programming
    Replies: 10
    Last Post: 04-22-2013, 06:31 PM
  3. my assignment
    By dalma in forum C Programming
    Replies: 3
    Last Post: 03-15-2011, 04:47 PM
  4. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  5. First assignment help
    By FirstC++ in forum C++ Programming
    Replies: 7
    Last Post: 07-01-2004, 07:57 AM