Tuesday, May 12, 2009

Problem Solving and Programming Logic

Computer Programs: The Power of Logic

A single program addresses a particular problem. When you write a program, you are solving a problem.

To solve a problem you must use your power of logic and develop an algorithm, or procedure, for solving the problem.

The algorithm is the finite set of step-by-step instructions that convert the input into the desired output, that is, solve the problem.

Structured Program Design: Divide and Conquer

Given a task, programmers were left on their own to create a solution any way they could.

Three major problems arose from this free-form method:
1.Long development time,
2.High maintenance cost, and
3.Low-quality software.

Structured programming stresses the systematic design and management of the program development process.

illustrates a common programming problem:

The printing of weekly payroll checks for hourly and commission employees. In the figure a structure chart is used to break the programming problem into a hierarchy of tasks. The most effective programs are designed to be written in modules, or independent task.

It is much easier to address a complex programming problem in small, more manageable modules than as one big task by using the principles of structured programming.

In structured programming, the logic of the program is addressed hierarchically in logical modules.

BY dividing the program into modules, the structured approach to programming reduces the complexity of the programming task.

Some programs are so complex that if taken as a single task.

Goals of structured programming :

Decrease program development time by increasing programmer productivity and reducing the
time needed to test and debug a program.

Decrease program maintenance costs by reducing errors and making program code easier to understand.

Improve the quality of software by providing programs with fewer errors.

Structured programming accomplishes these goals by incorporating these concepts:

  1. Top-down design and use of modules.
  2. Use of limited control structures (sequence, selection, and repetition).
  3. Management control.

Top-down design starts with the major functions involved in a problem and divides them into subfunctions until the problem has been divided as much as possible.

Each unit is small enough to be programmed by an individual programmer in the required time frame.

This forces an examination of all aspects of a problem on one level before considering the next level.

A programmer is left with small groups, or modules, of processing instructions, which are easy to understand and code.

A program consists of a main logic module that controls the execution of the other modules in the program.

Working from the top down avoids solutions that deal with only part of a problem.

A program that uses a main logic module to control smaller modules is easier to read, test, and maintain.

In structured programming, modules ensure these qualities by:

-having only one entrance and one exit

-performing only one program function

-returning control to the module from which it was received

No comments:

Post a Comment