Good Structure from the Beginning
What Every Program Looks Like
This is a brief section on how all of your programs must look. Every program -- the part inside the main method -- must have five parts. These are explained below.
Initialize the program
- there will always be program initialization actions. Examples are:
- declaring and/or defining variables
- initializing or seeding a random number generator that is used elsewhere in the program
- initializing any I/O interface systems, such as the formatted I/O tools
- setting the title for the program
Get Input from the User
- this is pretty straight forward; many programs, although not all, will need some kind of user input to get started
Conduct the Program Processing
- almost all the mathematical operations, decision making, and any other processing should occur here. While some processing may rarely occur in other parts of the program, good structure and modularity require keeping the processing actions in one place.
Display the Program Output
- when the calculations are complete, the resulting data can be displayed in some formatted or easily understandable way
End the program
- there will always be some kind of program shut down process. Examples are:
- holding the program until the user closes it
- shutting down I/O interfaces if any special ones are used
- ending the main function by returning zero (0)
Good Program Structure
As stated above, this is a short topic but it is important. Unless otherwise specified, all of your programs must be developed using this five-part structure.