1. Homepage
  2. Programming
  3. CS2311 Assignment 2 - Message Encoding/Decoding Scheme

CS2311 Assignment 2 - Message Encoding/Decoding Scheme

Engage in a Conversation
C++CS2311Computer ProgrammingMessage Encoding/Decoding Scheme Hong KongCity University of Hong Kong

Assignment 2
- Message Encoding/Decoding Scheme CourseNana.COM

Due: 1st Apr. 2023, Saturday, 23:59 [Week 11] CourseNana.COM

1.    This assignment contains ONE question with Two parts. You are required to submit a complete C++ program (.cpp only) for each part on PASS before the deadline. CourseNana.COM

2.    Only a small set of the test cases are visible for the testing, and a more comprehensive set of test cases will be used for grading. In other word, passing all the visible test cases does not mean that you can get full mark for this assignment. Try your best to thoroughly test your program. Hidden test cases will not be released. CourseNana.COM

3.    Themarkingofeachquestionisbasedonthepercentageofthetotaltestcases that your solution can pass. If your submitted solution leads to a compilation error on PASS, zero mark will be given to that question and no manual checking to your solution is provided in such a case; but if there is no compilation error (on meaningful codes) while no test case is passed, we will check your programming style shown on the codes and some marks may be back. CourseNana.COM

4.    No late submission will be accepted. ALL submissions should be on PASS. CourseNana.COM

5.    Plagiarism check will be performed. CourseNana.COM

6.    You should ONLY use the library <iostream> and <cstring>. You are NOT ALLOWED to use objects from <string>. CourseNana.COM


CourseNana.COM

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

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. CourseNana.COM

Part A [2 marks] Header Encoding CourseNana.COM

Write a program that reads a line of printable characters and encodes these characters with a sequence of keys. Each key is a binary string of '0'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 (i.e., previous value times two and then plus one). The keys of the same length are in sequence of its binary value but excluding all '0's. CourseNana.COM

An example of the encoding scheme has shown as follows. CourseNana.COM

[Example] CourseNana.COM

Assume the input header is: CourseNana.COM

n(X+# $90\"? ... CourseNana.COM

Then the Keys are: CourseNana.COM

n(X+# $90\"?... CourseNana.COM

1 01 10 11 001010011100101110 111 0001 ... CourseNana.COM

To verify the correctness of the encoding, your program should also read an input character and print the key(s) of that character. CourseNana.COM

Notes: CourseNana.COM

1. The length of the header will NOT exceed 256, and the maximum length of the key string is seven, i.e., the longest key string is "1111111". CourseNana.COM

2. The header contains only printable characters including "space", i.e., any characters in the ASCII Table with values from 32 to 126. CourseNana.COM

3. The header may have repeated characters that lead to different keys.
4. We can assume the input is valid, i.e., no need to check the correctness of input.
CourseNana.COM

Sample Input and Output CourseNana.COM

(Text with blue color is output; text with green color is input) CourseNana.COM

Example 1 CourseNana.COM

Enter Header: CourseNana.COM

n(X+# $90\"? Character?$ 011 CourseNana.COM

Example 2 CourseNana.COM

Enter Header: CourseNana.COM

n(X+# $90\"?# Character?# 001
0010
CourseNana.COM

page3image19599296 CourseNana.COM

Example 3 CourseNana.COM

Enter Header: CourseNana.COM

n(X+# $90\"? CourseNana.COM

Character?_ 010 CourseNana.COM

input is a "space" CourseNana.COM

Part B [3 marks] Message Decoding
Extend your program in Part A to decode a message based on the keys generated in CourseNana.COM

Part A. CourseNana.COM

The encoded message is a sequence of binary digits (i.e., sequence of '0's and '1's). The message should be decoded in multiple segments. Each segment starts with the first 3 digits to represent the length of keys to be decoded in the subsequent digits. The end of the segment is signified by a sequence of '0's of that length. CourseNana.COM

[Example] CourseNana.COM

Assume the input header is: CourseNana.COM

n(X+# $90\"? ... CourseNana.COM

Then if the segment is 010100100, it would be decoded as follows.
010 10 01 00 CourseNana.COM

length of key decoded to be decoded to be end of segment 2X( CourseNana.COM

The message may have multiple segments and ends with the binary string "000". Your program should CourseNana.COM

1) read the header and an encoded message;
2) then decode the message and output the decoded message.
CourseNana.COM

Notes: CourseNana.COM

1. Refer to the Notes of Part A.
2. The encoded message is assumed to be in one line. 3. We can assume the
CourseNana.COM

Sample Input and Output CourseNana.COM

(Text with blue color is output; text with green color is input) Example 1 CourseNana.COM

Explain: the message code 011001010100000001100111110000101000000 can be divided into the following segments: CourseNana.COM

011001010100000 00110 011111000 0101000 000 CourseNana.COM

Example 2 CourseNana.COM

Enter Header: CourseNana.COM

n(X+# $90\"?
Enter code:011001010100000001100111110000101000000 # 9n"X CourseNana.COM

page5image19605440page5image19605632 CourseNana.COM

Enter Header: CourseNana.COM

:-+ lkC
Enter code:011011000010101000000 C++ CourseNana.COM

page5image19606592page5image19606784 CourseNana.COM

Example 3 CourseNana.COM

Enter Header: CourseNana.COM

=>?@A pqrstuv !"#$EFSTCabgh673rs-./01cde92ieo83r CourseNana.COM

Enter code: CourseNana.COM

10011001010000010110000001000101101011000001000011000010110001 00110000001000011110100000110100001001111000010110110011100000 01001101000001111100010000110000101011001001100000100000100001 011011000000011110000101011100000010001000000000 CourseNana.COM

CS2311 is a great course! CourseNana.COM

page5image19607744 CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
C++代写,CS2311代写,Computer Programming代写,Message Encoding/Decoding Scheme 代写,Hong Kong代写,City University of Hong Kong代写,C++代编,CS2311代编,Computer Programming代编,Message Encoding/Decoding Scheme 代编,Hong Kong代编,City University of Hong Kong代编,C++代考,CS2311代考,Computer Programming代考,Message Encoding/Decoding Scheme 代考,Hong Kong代考,City University of Hong Kong代考,C++help,CS2311help,Computer Programminghelp,Message Encoding/Decoding Scheme help,Hong Konghelp,City University of Hong Konghelp,C++作业代写,CS2311作业代写,Computer Programming作业代写,Message Encoding/Decoding Scheme 作业代写,Hong Kong作业代写,City University of Hong Kong作业代写,C++编程代写,CS2311编程代写,Computer Programming编程代写,Message Encoding/Decoding Scheme 编程代写,Hong Kong编程代写,City University of Hong Kong编程代写,C++programming help,CS2311programming help,Computer Programmingprogramming help,Message Encoding/Decoding Scheme programming help,Hong Kongprogramming help,City University of Hong Kongprogramming help,C++assignment help,CS2311assignment help,Computer Programmingassignment help,Message Encoding/Decoding Scheme assignment help,Hong Kongassignment help,City University of Hong Kongassignment help,C++solution,CS2311solution,Computer Programmingsolution,Message Encoding/Decoding Scheme solution,Hong Kongsolution,City University of Hong Kongsolution,