Computer programming - Week 4 practice problems

Revisit the problems from lab 3 (e.g., C comments, word count). New exercises:

1.Reformat text. Write a program that reads a text until EOF and prints it out transformed with the following three rules:

2. Reverse line. Write a recursive function that reads a line of text (until newline or EOF) and prints it with characters in reverse order.
Use the following recursive definition of reversal: reverse(empty) = empty . reverse(cS) = reverse(S)c where c is a char and S is a string.

3. Balanced parantheses. Write a program that reads input until EOF and checks that any parantheses ( ), brackets [ ] or braces { } are properly nested and matched.

4. From infix to postfix. An expression in postfix form is either a natural number, or two expressions followed by an operator + - * / and separated by any whitespace.
Example: 7 4 2 + - 5 - means 7 - (4 + 2) - 5
Adapt the expression calculator done in class to read an expression (in usual infix notation) from input and print it in postfix form.
Instead of returning values, each of the functions will now print. No parantheses are needed or used in postfix form.

Marius Minea
Last modified: Tue Oct 18 8:45:00 EEST 2016