Example #1 (and walking through it): Consider the following input data stream: 5
ID: 3639627 • Letter: E
Question
Example #1 (and walking through it):Consider the following input data stream:
5
00110101
and processing instructions stream:
0R1, 0R2
1S3, 0S3
end
The position of your pointer (#5) is where the * is, below -- pointing at a 0 underneath, in the output sequence):
*
00110101
The meaning of these three elements of an instruction is as follows:
? The first character (either '0' or '1') is the character that your program needs to write to the output sequence in place of (i.e., at the same position) the character that has just been read from that sequence is.
? The second character (one of 'L', 'R', or 'S') represents how the sequence pointer will move at the end of the current instruction. Namely, 'L' moves it to the left by one; 'R' moves it to the right by one; and 'S' means that the pointer will stay in place (i.e., no movement).
? The positive number at the end of each instruction represents the index of the row of instructions that needs to be looked at next, upon completion of the operations for the present row of instructions. (Once again, remember that row indices start from 1, not 0.)
”(If you read 0 in the input stream,) write 0 to the output stream, move the pointer to the right, and execute instruction #1 next.”
So, as a result, the output stream doesn't change (0 is replaced with 0), but the position pointer has moved and now points at the neighboring 1 to the right:
*
00110101
Explanation / Answer
#include #include "Text File Reader Wrapper.h" using namespace std; // Constructor of the class: associates the given filename with an input stream handle TextFileReaderWrapper::TextFileReaderWrapper( char * pcFilename ) { // associates a file stream with a given file (as specified by its filename) oInputFileStream.open(pcFilename); if (!oInputFileStream) { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.