



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




The first programs that were written were not structured. The program usually consisted of a sequence of individual instructions that were executed one after another. This resulted in one massive program consisting of several thousands of lines of code that was not grouped in any logical way. Maintaining such programs was time consuming and expensive, since changing even one line of code could affect the entire program.
Structured Program Design
Structuring a program breaks it down into understandable chunks. Structured programming is an approach to writing programs that are easier to read, test, debug and modify. The approach assists in the development of large programs through stepwise refinement and modularity. Programs designed this way can be developed faster. When modules are used to develop large programs, several programmers can work on different modules, thereby reducing program development time. In short, structured programming serves five purposes to: i. Increase programmer productivity ii. Program reliability (readability and execution time) iii. (^) Program testing iv. Program debugging and v. Serviceability. Structured Programming Techniques There are three techniques; Modular programming, Top-down Programming and bottom-up approach. Modular Programming
This technique involves breaking down the entire problem into smaller, more manageable units. Features
Advantages of modular programming
The program design process is frequently tackled by adopting a top-down approach. An outline program is designed first, showing the main tasks, or components of the program and the order in which they are to be executed. Each main component is then reduced to a number of smaller, simple and more manageable components and this process continues at each level until there is sufficient detail to allow the coding stage to proceed. The process of reducing components into sequences of smaller components is often referred to a stepwise refinement and forms the basis of structured programming. Top-down approach allows a program to be designed methodically by providing a complete definition of the program at each level of complexity. Example: Exam Results Consider a class of twenty students who sat for examinations in four subjects. A student must get an average of 50% in all four subjects to pass. A report is required that will show the marks obtained by each student per subject, the average mark and whether the student has passed or not.
Name Subjects AVERAGE PASS/FAIL MATHS ENGLISH BIO PHY Jane Mary
Rodney
Winston
Bottom-up Approach In this design approach, the application is developed starting at the bottom of the hierarchy i.e. the single task modules. As each category of programs is completed on the hierarchy, the controlling program for that category is created.
Program Design Tools Algorithms An algorithm is a sequence of steps, which results to a plan or strategy on how to go about solving a problem. There are different ways of presenting an algorithm. Some common ways include-
Input/output – Input/output operations are represented in a parallelogram.
Decision – This symbol is used to indicate decision making and branching. The criterion is shown inside the symbol and the lines (paths) out show the results.
Connectors – A small circle containing a number or letter that is used to split a large flow chart into smaller parts.
Design of Exam Results using Flow Charts
YES Average >50%?Calculate AveragePrint ‘FAIL’Print ‘PASS’ EndPrint ReportCompleted all Students?Get Student
Marks
Get Student
Name
Start
The flow chart for the Exam results example is as shown on the previous page. The repetition construct is shown by using a decision symbol to loop back until the condition becomes true.
Useful tips when drawing flow charts.
i. Use standard flow chart symbols ii. (^) Try to keep logic from top to bottom and from left to right iii. Use arrow to indicate flow (direction) iv. Use connectors to reduce the number of flow lines. v. Add notes if necessary but do not clutter the diagram. vi. Lines should be ideally vertical or horizontal. Program Coding
Syntax Errors
Every programming language (like any natural language) has a set of rules concerning formal spelling, punctuation, naming of variables and other conventions that must be obeyed by the programmer. An error in language usage is called a syntax error. Special system programs called translators detect syntax error.
A program that has syntax errors can produce no results. You should look for the error in the line suggested by the compiler. Syntax errors include; Missing semi colon at the end of a statement e.g. Area = Base * Length Use of an undeclared variable in an expression Illegal declaration e.g. int x, int y, int z; Use of a keyword in uppercase e.g. FLOAT, WHILE Misspelling keywords e.g. init instead of int Logical Errors
Although the compiler will detect syntax errors, it will not find errors in programming logic. While syntax errors result from program language mistakes, logical errors occur when the program does not function as intended.
A logical error can lead to one of the two results: