Developing a program involves steps similar to any problem-solving process. There are five main steps in the programming process:
Defining the problem
Planning the solution
Coding the program
Testing the program
Documenting the program
Defining the problem. In this stage, you need to identify the input (the given data), and what you need to obtain (output - the result).
Planning the solution. Two common ways of planning the solution to a problem are to draw a flowchart and/or write pseudocode.
Coding the program. This step is to code the program - that is, to express your solution in a programming language. You will translate the logic from the flowchart or pseudocode to a programming language. A programming language is a set of rules that provides a way of instructing the computer on what operations to perform. (* An experienced programmer can often write code for simple programs directly on the computer, skipping the coding-on-paper steps. However, we do not recommend that beginners skip any steps. Even experienced programmers can get into trouble and waste a lot of time when they do not define the problem and plan the solution carefully before beginning to code.)
Testing the program. This step involves debugging process. Debugging means detecting, locating, and correcting bugs (mistakes) by running the program. Desk-checking is a process that will help you discover several errors and possibly save yourself several computer runs. In desk-checking, you simply sit down and mentally trace, or check, the logic of the program to ensure that it is error-free and workable.
Documentation is a written detailed description of the programming cycle and specific facts about the program. Typical program documentation materials include the origin and nature of the problem, a brief narrative description of the program, data-record descriptions, program listings, and testing results. Comments in the program itself are also considered an essential part of the documentation. Many programmers document as they code.
Before you write a program, you have to know what the program is supposed to do. Going straight to coding can be very confusing. It is a good idea to write it in a simple way first to ensure you have included everything you need. The best way to set this up is by using an algorithm.
The Algorithm is a procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed. An algorithm is merely a sequence of steps taken to solve a problem. The steps are normally 'sequence', 'selection', 'iteration', and a case-type statement.
There are two common tools of algorithms; chart-based (like a flow chart) and text-based. For this course, we will use a text-based algorithm called pseudo-code. Generally, flowcharts work well for small problems but Pseudo-code is used for larger problems.
Pseudo-code is a simple way of writing programming code in English. Pseudo-code is not an actual programming language. It uses short phrases to write code for programs before you actually create it in a specific language. Once you know what the program is about and how it will function, then you can use pseudo-code to create statements to achieve the required results for your program.
Pseudo-code makes creating programs easier. Programs can be complex and long. If using flow-chart, it is difficult to modify and display all parts of a program. It is challenging to find a mistake without understanding the complete flow of a program. That is why pseudo-code is preferred.
To use pseudo-code, all you do is write what you want your program to say in English (or any language). Pseudo-code allows you to translate your statements into any programming language (C, C++, java,etc) because there are no special commands and it is not standardized. Writing pseudo-code before you code can enable you to better organize and see where you may have left out needed parts in your programs. All you have to do is write it out in your own words in short statements. Let's look at some examples below.
Remember, writing basic pseudo-code is not like writing an actual coding language. It cannot be compiled or run like a regular program.
Basic Guidelines
Do not use language specific commands in your statements
Pseudo-code should be universal. So, when creating the task list you would not include commands that are for any specific language like C++, Java, C#, or Perl. The point of pseudocode is to design a program that can be translated into any language.
Example
If student's grade is greater than or equal to 60 Print "passed" else Print "failed" endif
Write only one task/statement per line
Make sure you put only one task on each line. Including too much information on one line can be confusing and increases the possibility of errors.
Capitalize Keywords
Capitalizing keywords like Read, Write, or Display helps to show when an action is occurring or when a specific command or processes will be necessary when coding in your specific language.
Some Keywords That should be used and additional points
For looping and selection, The keywords that are to be used include Do While...EndDo; Do Until...Enddo; While .... Endwhile is acceptable. Also, Loop .... endloop is also VERY good and is language independent. Case...EndCase; If...Endif; Call ... with (parameters); Call; Return ....; Return; When;
Always use scope terminators for loops and iteration
Example
If student's grade is greater than or equal to 60
Print "passed"
else
Print "failed"
endif
As verbs, use the words Generate, Compute, Process, etc.
Words such as set, reset, increment, compute, calculate, add, sum, multiply, ... print, display, input, output, edit, test , etc. with careful indentation tend to foster desirable pseudo-code. Also, using words such as Set and Initialize, when assigning values to variables is also desirable.
Example
If student's grade is greater than or equal to 60
Print "passed"
else
Print "failed"
endif
More on Formatting and Conventions in Pseudo-coding
indentation in pseudo-code should be identical to its implementation in a programming language. Try to indent at least four spaces.
Example
Set total to zero
Set grade counter to one
While grade counter is less than or equal to ten
Input the next grade
Add the grade into the total
endwhile
Set the class average to the total divided by ten
Print the class average.
Do not include data declarations in your Pseudo-code
But do cite variables that are initialized as part of their declarations. E.g. "initialize count to zero" is a good entry.
Decisions (Switching logic)
Switching logic consists of two components - a condition and a goto command depending on the result of the condition test. The computer can determine the truth value of a statement involving one of six mathematical relations symbolized in the table below:
Symbol Meaning
== Equals
!= Not Equal
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
Loops
Most programs involve repeating a series of instructions over and over until some event occurs. For example, if we wish to read ten numbers and compute the average, we need a loop to count the number of numbers we have read. Count loops are loops where the program must count the number of times operations are completed. The flowchart below illustrates a loop that counts from 1 to 10:
Function Calls, Function Documentation, and Pseudo-code
Call FunctionName (arguments: field1, field2, etc.)
Returns in functions should appear as:Return (field1)
Function headers should appear as:FunctionName (parameters: field1, field2, etc. )
Note that in C, arguments and parameters such as "fieldn" could be written: "pointer to fieldn ...."
Functions called with addresses should be written as:Call FunctionName (arguments: pointer to fieldn, pointer to field1, etc.)
Function headers containing pointers should be indicated as:FunctionName (parameters: pointer to field1, pointer to field2, ...)
is returned:Return (pointer to fieldn)
It would not hurt the appearance of your pseudocode to draw a line or make your function header line "bold" in your pseudocode. Try to set off your functions.
Try to use scope terminators in your pseudocode and source code too. It really hels the readability of the text.
A flowchart is a graphical representation of an algorithm. Certain special-purpose symbols connected by arrows called flow lines are used. It makes programs easy to build.
Symbols in Flowchart
The following flowchart shows how to find the sum of two numbers.
Exercise:Draw a flow chart to convert temperature in Fahrenheit to Celsius. Use formula
Fahrenheit = Celsius * (9/5) + 32
A computer program consists of many processes and flows. Flowcharts are used to visualize the processes and make them understandable for non-technical people. They are also used to visualize algorithms and comprehend pseudo-code which is used in programming.
What is Programming?
The process of designing, writing, testing, debugging / troubleshooting, and maintaining the source code of computer programs
Steps in Programming
Step 1: Problem analysis. The designer must fully understand the nature of the problem to be solved and the need for the solution.
Step 2: Problem statement. Develop a detailed statement of the problem to be solved with a computer program.
Step 3: Processing scheme. Define the inputs required and the outputs to be produced by the program.
Step 4: Algorithm. Design the step-by-step procedure using the top-down design process divide the overall problem into subordinate problems.
Step 5: Program algorithm. Translate or convert the algorithm into a computer language.
Step 6: Evaluation. Test all of the options and conduct a validation study of the computer program, compare results
with other programs that do similar tasks,
experimental data if appropriate
theoretical predictions.
Step 7: Application. Solve the problems using the program was designed to solve.
Good Programming Practice
A good program is:
Efficient
Correct (correct syntax & semantics)
Readable (Easy to read & understand)
Easy to maintain & enhance