Section 1: Introduction
*Adapted from Introduction to Pascal and Structured Design by Dale and Orshalik
In order to write a sequence of instructions for a computer to follow, we must go through a certain process. This process is composed of a problem-solving phase and an implementation phase.
PROBLEM-SOLVING PHASE
Analyze – Understand (define) the problem.
General Solution (Algorithm) – Develop a logical sequence of steps to be used to solve the problem.
Test – Follow the exact steps as outlined to see if the solution solves the problem.
IMPLEMENTATION PHASE
Specific Solution (Program) – Translate the algorithm into a programming language (code).
Test – Have the computer follow the instructions. Check the results and make corrections until the answers are correct.
Use – Use the program.
The programmer must arrive at the solution and communicate it to the computer. The problem solving is done by the programmer – not the computer.
Section 2: Algorithms
The programmer analyzes the problem and develops a general solution called an algorithm. Understanding and analysis of a problem require a great deal of time. They are the heart of the programming processes.
Algorithm – a step-by-step procedure for solving a problem in a finite amount of time.
This topic will be covered in more detail later
Section 3: Testing
After developing a general solution, the programmer then "walks through" the algorithm by performing each step mentally or manually.
- If the testing of the algorithm doesn’t produce the correct answers, the process is repeated by analyzing the problem and coming up with another algorithm.
- When the programmer is satisfied with the algorithm, it is then translated into a programming language.
Translating the algorithm into a programming language is called coding the algorithm.
- The resulting program is tested by running it (executing each statement) on the computer.
- If the program fails to produce the desired results, the programmer must analyze and modify the program as needed.
All programs are algorithms. An algorithm can be in English, but when it is specified in a programming language it is also called a program.
Some students try to take a shortcut in the programming process by going directly from the problem definition to the coding of the program.
- This shortcut is very tempting and it might seem at first to save a lot of time.
- However, for many reasons which will become obvious to you as you become more experienced, this approach actually takes more time and effort.
- By not taking the time initially to think out and polish your algorithm, you will spend a lot of extra time correcting errors (debugging) and revising an ill-conceived program.
- So, think first and code later! The sooner you start coding, the longer it will take to get a correct program.
Program documentation and maintenance are also part of programming.
- Documentation is written text and comments that make a program readable, understandable and more easily modified.
- Maintenance is the modification of a program to take care of changing requirements or any errors (bugs) that might show up after the program is put into use
Programming involves more than simply writing a program.
- A programmer must understand and analyze the problem in order to develop a correct solution, because the program must solve the specific problem and do so correctly.
- Developing a general solution before actually writing the program helps the programmer manage the problem, keep thoughts straight and avoid unnecessary errors.
- In addition, most programs will be used over and over again.
- Program modification often becomes necessary. Problem requirements may change and/or errors may show up.
- Careful design and good program documentation prove invaluable during this maintenance phase.
Section 4: Summary
Before writing a computer program to solve a problem, you go through the problem-solving phase and come up with a general solution (algorithm).
- When you have hand-tested your algorithm and feel that you have a working solution, you can proceed to translate your algorithm into a programming language.
- This implementation phase is similar to the problem solving phase in that the program (algorithm) must be tested with input data to see that it produces the desired output.
- If it doesn't, you must locate the errors in the program.
- If your algorithm is faulty, you must go back to the problem-solving phase to see where you went wrong.
- Sometimes you have a correct algorithm, but have failed to translate it correctly into a programming language