The Tape() function is fairly simple, and is coded in main.cpp.
Line 3 controls the maximum size of the arrays. Arrays require a constant expression to identify their size when they are created, and line 3 sets up that constant and gives it a name. Because the arrays are static, their size constant needs to be static too, or it will not have been initialized when the arrays are created at the start of the program run.
Lines 5 and 6 are the operator and operand arrays that are the actual tape. You might say they are parallel, because the operator in the first element of the myOperator array is the one used with the operand in the same element of the myOperand array.
Line 8 keeps a count of how many elements there are in the arrays so far. You need this because the arrays have a fixed size, and you have to throw an exception when the user has entered so many operator/operand pairs that the array will overflow. Line 32 updates this count.
Lines 10 and 11 provide a little reminder.
Line 13 checks to see whether theOperator is the array that causes the tape contents to be displayed. If so, control flows to line 27.
Line 15 checks to see whether there is room left on the tape. If myNumberOfEntries == myTapeSize, the index is about to go one past the end of the array. Rather than allow this, line 23 throws a runtime_error exception, which is caught in main().
Line 17 starts to actually add to the tape. This line sets the appropriate element of each of the arrays using an index that is, by definition, one above the last element used—myNumberOfEntries. This is a C++ trick based on the fact that arrays are indexed from 0, and the element count is based on 1, so the index of the new entry is always the same as the count.
Line 19 introduces a new arithmetic operator—the double plus (++). This is the postfix increment operator, a very commonly used operator. It will add 1 to the variable named before it. This line updates myNumberOfEntries to the appropriate count, so you can check it the next time through and make sure that you don't overrun the array bounds.
Line 28 is in the block that is performed when theOperator is ?, which means “display the tape.” In that block, a for loop is used to move through the array so that the elements can be displayed with cout.
3.141.107.60