Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following input data stream: 5 00110101 and processing instructions

ID: 3639571 • Letter: C

Question

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

Meaning of R L & S

If 0 or 1, write this character in the place of position (ex.5)

If 2nd character L R or S, move left L, move right R, stay S.

Don't worry about the 2,3 at the end; that's just the index of next instructions

I have the methods to read in the files. I need help on how to start it, or what methods to write.

Thank You
c++

Explanation / Answer

#include #include #include #include #include #include using namespace std; char notZeroOrOneToZero(char); typedef enum { NoMove, Left, Right } Move; class Instruction { public: Instruction() : _bit('0'), _dir(NoMove), _nextRow(0) { } Instruction(const string &instr) : _bit('0'), _dir(NoMove), _nextRow(0) { if ((instr[0] == '0') || (instr[0] == '1')) { _bit = instr[0]; } switch (instr[1]) { case 'L': _dir = Left; break; case 'R': _dir = Right; break; case 'S': _dir = NoMove; break; default: break; } if (isdigit(instr[2])) { _nextRow = instr[2] - '0'; } } inline char bit() const { return _bit; } inline Move dir() const { return _dir; } inline int nextRow() const { return _nextRow; } private: char _bit; Move _dir; int _nextRow; }; class BitStream { public: BitStream() { _theBits[0] = '0'; _pos = 1; } BitStream(const string &s, size_t p) : _theBits(s.begin(), s.end()), _pos(p) { // make sure pos and theBits are valid if (_theBits.size() == 0) { _theBits[0] = '0'; } _pos = min(_pos, _theBits.size()); transform(_theBits.begin(), _theBits.end(), _theBits.begin(), notZeroOrOneToZero); } void nextState(const Instruction &i) { _theBits[_pos - 1] = i.bit(); if (i.dir() == Left) { if (_pos > 0) --_pos; } else if (i.dir() == Right) { if (_pos < _theBits.size() - 1) ++_pos; } } void display() const { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote