Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using C++ to program, read random contents from a file in the main have been written, requires to a function follow the steps: Given: encode_char
Using C++ to program, read random contents from a file in the main have been written, requires to a function follow the steps:
Given:
encode_char
encode_char(block, payload) current = 0; length = length of block for offset = 7, 6, 5, ..., 0 // Find the next alphabetic character while block[current] is not an alphabetic character and current is less than length increment current // Ensure we haven't walked past the end of the block if current is at least the length throw an error // Fix the output case if the offset bit of payload is a 1 set block[current] to a capital case letter else set block[current] lower case letter increment current return block
find_boundary
// Count how many characters after start you need to travel to find 8 alphabetic characters // If not enough are found, return -1 find_boundary(message, start) offset = 0 remaining = 8 while there are remaining characters if start + offset >= length of message return -1; if message[start + offset] is an alphabetic character decrement remaining increment offset return offset
Write program for:
encode_string
encode_string(message, payload) ret = "" start = 0; // Encode the payload for every character c in the payload block_length = find_boundary(message, start); if block_length == -1 throw an error block = substring of message starting at start, block_length chars in length append encode_char(block, c) to ret increase start by block_length // Encode a null terminator block_length = find_boundary(message, start); if block_length == -1 throw an error block = substring of message starting at start, block_length chars in length append encode_char(block, '\0') to ret increase start by block_length // Add remainder of message remainder = substring of message starting at start, going to the end of the string append remainder to ret return ret
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started