39.7k views
5 votes
C++ code. Important: You should ONLY use the library and . You are NOT ALLOWED to use objects from.

In this assignment, you will write a C ++ program that can decode a message under the following encoding scheme.

There are two parts in this encoding scheme. The first part is a character set (header) that covers all possible characters of the messages to be decoded. The second part is an encoded message to be decoded based on the keys in the encoding scheme of the first part.

Part A. [2 marks] Part 1 Header Encoding
Write a program that reads a line of printable characters and encodes with a sequence of keys with each key is a binary string of ' θ 's and ' 1 's. The sequence of keys starts with a key with length 1 , followed by three keys with length 2 , seven keys of length 3, fifteen keys of length 4 , etc. The keys of the same length are in sequence of its binary value but not with all '0's.
The encoding scheme is as follows. Assume the input header is: key string: To verify the correctness of the encoding, write a function to read in a character and print the key(s) of that character.

Notes:
1. The length of the header will NOT exceed 256 .
2. The maximum length of the key string is seven. That is, the longest key string is "111111". Hint: A character string should have a ′∣θ′ at the end of the string.
3. The header contains only printable characters including "space", i.e. any characters in the ASCII Table with values from 32 to 126.
4. We assume the input is valid, i.e., no need to check the correctness of input.
5. The header may have repeated characters that lead to different keys. Sample Input and Output

1 Answer

2 votes

Final answer:

A college-level C++ programming task requires coding a decoding program and a function for verifying an encoding header, obeying a specific key pattern. Students should use loops, arrays, and bitwise operations to handle the encoding logic.

Step-by-step explanation:

The student is tasked with writing a C++ program for decoding a message with a specified encoding scheme. This scheme uses a header of printable ASCII characters and an encoded message that is translated into keys consisting of binary strings of '0's and '1's.

The sequence of keys increases in length and follows a specific pattern: one key of length 1, three keys of length 2, seven keys of length 3, and so on, with a maximum key length of seven. All keys are in binary sequence but do not include all '0's. To verify the encoding, a function should be able to read a character and print its corresponding key(s).

The constraints include:

  • The length of the header does not exceed 256 characters.
  • The key strings will not be longer than '111111'.
  • The header can include any printable character from the ASCII table.
  • Inputs are assumed to be valid.
  • There may be repeated characters in the header leading to different keys.

This encoding structure suggests use of loops, arrays, and bitwise operations to manage the pattern and store keys. The function for verification is crucial for testing the correctness of the encoding scheme implemented.

User Hammad Khalid
by
7.8k points

Related questions