A Larger Example of Encapsulation

The next example is input expression verification. Again, for simplicity sake, I will limit the functionality of the example to verifying whether parentheses and brackets in the input expression properly match each other. Let us consider a function checkParen() that scans the characters of the expression in a null-terminated array one-by-one until it either finds the terminating null (end of expression) or it discovers a parenthesis or a bracket that does not have a match. For example, the expression a = (x[i] + 5)*y should be recognized as a valid expression, and the expression a = (x[i) + 5]*y should be declared invalid.

The example will use two global arrays, buffer[ ] and store[ ]. Index i retrieves a character ...

Get Core C++ A Software Engineering Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.