For this question:
one of the answers noted that the code in the question appears to be copy/pasted from this homework assignment.
Should the question therefore be closed as off-topic?
Clarification: The code does not appear to be written by the question asker. The homework was basically: "How can you make this code better in these three places" and the OP pasted that code as his question and asked about those three places.