Question: Create a multithreaded program in C + + ( All in a main.cpp file ) using the Shannon coding data compression algorithm. Given an input
Create a multithreaded program in CAll in a main.cpp file using the Shannon coding data compression algorithm.
Given an input string representing the message to encode using the Shannon coding technique the input string can have any symbol from the ASCII alphabet:
AAABAAABAAAAMMAAAAAU
The expected output is:
Message: AAABAAABAAAAMMAAAAAU
Alphabet:
Symbol: A Frequency: Shannon code:
Symbol: M Frequency: Shannon code:
Symbol: B Frequency: Shannon code:
Symbol: U Frequency: Shannon code:
Encoded message:
Process:
Your solution must execute the following steps:
Read the n lines from STDIN, where each line has an input string to encode using the Shannon coding algorithm.
Create n POSIX threads where n is the number of input strings Each child thread executes the following tasks:
Receives the input string used to encode the values.
Creates the alphabet based on the received input string.
Sorts the alphabet in decreasing order based on the symbols' frequency. If two or more symbols have the same frequency, you must sort them in decreasing order based on their ASCII value.
Determines the Shannon codes for the symbols in the alphabet.
Generates the encoded message by using the Shannon codes.
Stores the alphabet with the Shannon codes and the encoded message on a memory location accessible by the main thread.
Print the information from the child threads into STDOUT.
Given the following input:
COSC COSC
COSC COSC
COSC COSC
The expected output is:
Message: COSC COSC
Alphabet:
Symbol: C Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: S Frequency: Shannon code:
Symbol: O Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Encoded message:
Message: COSC COSC
Alphabet:
Symbol: C Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: S Frequency: Shannon code:
Symbol: O Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Encoded message:
Message: COSC COSC
Alphabet:
Symbol: C Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: S Frequency: Shannon code:
Symbol: O Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Symbol: Frequency: Shannon code:
Encoded message:
Notes:
You can safely assume that the input will always be in the proper format.
You must use the output statement format based on the example above.
You can define additional functions if needed.
You must take full advantage of multithreading.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
