3.0 How to design and write programs?


If you want to write a program, you must first design it. But before you can do any designing, you must first know what it is that you want and what you want to achieve. All these are part of a process called the software development life cycle (SDLC).

3.1 Software development life cycle

What is SDLC? When you decide to write a program, it is to solve a problem faced by a user or to perform a certain task as required by a user. Writing a program in real life will in many cases involve large, complex and usable software. Writing and designing the program itself is not enough. A program, or in the case of a large and complex program we usually call software, the story does not end with the design and the coding. The software has a life cycle. There are six steps in the software development life cycle and they are as follows:

Analysis (define the problem)
Design the software (algorithm design)
Implementation (writing the program code using a specific language)
Testing (test the program)
Maintenance
Obsolescene



3.0 How to design and write programs?


In this course, we will concentrate on the first three steps; analysis of the problem, designing the program, and writing the program code.

3.2 Problem Solving

As mentioned in the earlier section, before you can write a good program, you must first analyse the problem that you want to solve, and then to design the algorithm of the program before you can write the program codes.

You have to understand the problem before you can attempt to solve it. To understand the problem, you need to analyze it. The purpose of analyzing the problem is for you to determine what is it that the program must to do. This is the first important step and you must be able to determine what is task the program need to perform, and you must specify this completely and precisely. One way that can help you get started is by determining the output that the program must produce. In order to get an output, the program requires input. You must determine what that input is , and how does the program process the input to produce the output. It is important for you to remember that a program consist of the following:




3.0 How to design and write programs?


Many times, you will have to consult with the program’s potential users - the person for whom you are creating the program, to get a description of the program’s output, and input. An output can be what the user wants to see displayed on the computer screen, or what the user wants to see printed on a page, or what the user wants to store in a file on a storage device. An input is the information or data that the computer need in order to produce the output. Input can be given to the program through the keyboard, or it can be a data taken from a file in a storage device, or in can be any from any other input devices. Let us look at a simple example.

Problem:

Ali is a businessman who runs a foreign exchange bureau, exclusively for exchange currencies from US dollars to Malaysian Ringgit. The conversion rate between these two currencies varies daily. Ali wants a program that would help him calculate the conversion and display it on the computer’s monitor for his customer to see.

Let’s analyze this problem. You can start with determining the output of the program. What is it? The output of the program is to display the amount in Malaysian Ringgit on the computer screen. What is the input? The input of the program is the amount of US dollar, keyed in by the user from the keyboard. And you also must have the conversion rate. Conversion rates for foreign exchange fluctuates daily. Therefore, this information must be given to the computer. So, this is another input which is required by this program.


3.0 How to design and write programs?


After you have determined the input and the output of the program, the next step is to figure out the process that will take the input and produce the output that you want. Besides the analysis of the problem, this is another challenging phase in writing a program. This is called the problem-solving phase and the end of this phase you should have something that is called an algorithm. An algorithm is a sequence of instructions that leads to a solution.

Deriving an algorithm is an iterative process. After you have prepared the first version of your algorithm, you have to check the algorithm by performing a process called desk-checking or hand-tracing. This process requires you to execute each step of the algorithm in your mind, or with the help of pen and paper. The purpose of this process is to verify that the algorithm is not missing any steps and will produce the correct output. If the algorithm does not perform as it should, then it has to be redesigned. This iterative process will go on until the desk-checking confirms that the algorithm is correct. After you are satisfied with the algorithm which you have derived, you may now code your program in a chosen programming language. After you have written the codes to your program on a computer, you may run the program, and hope that you program will run and perform the tasks as you expected.

However, most of the time, you will find that your first few tries at running the program will not be successful even though you have checked and rechecked the algorithm. We will discuss why in later sections. When this happens, you will need to figure out the reason why your program does not perform as it should, you will have to make some changes to your codes (and maybe even your algorithm), and you will have to do this over and over again until you get the result that you want.


3.0 How to design and write programs?


The following diagram summarizes the steps that are involved in writing a program.