Problem Solving and Program Design

Introduction to Programming


Programming Languages


Software is a name given to computer programs that tell (instruct) the hardware how to work. Software therefore includes computer programs that create system and application software.

Programming is the art of putting the solution to a problem into a language that a computer can understand. A programmer actually instructs the computer how to solve a problem since it cannot come up with a solution to a problem itself.

A computer program is a set of instructions that tell a computer what to do and how to do it. These instructions are usually converted into a sequence of numeric codes called machine code which is stored in memory. The central processing unit (CPU) interprets this code in order to carry out the instruction of the program.

There are many programming languages that can be used to write programs or create other kinds of software. These languages are grouped into two categories:

  • low-level languages
  • high-level languages




Low-level
These languages are machine dependent. In other words, the code written can only be understood by the exact computer or processor that was used to write the code.

The first generation language, called machine language, used the digits 0 and 1 that make up the binary code. an instruction might be written as 10110000 01100001.

The advantage is that the code runs fast and efficiently because it is directly executed by the CPU; however, the disadvantages are that the programmer may become confused with the massive amount of 0s and 1s in the program and it is also machine dependent.



The second generation language, called assembly language, has the same structure and commands as machine language but allows programmers to use abbreviated words, called mnemonics, instead of binary. Thus, instead of writing the code as 10110000 01100001, the equivalent assembly language code may be 'add A, B', normally meaning 'add the contents of A and the contents of B'.

The advantage is that it can be easily converted to machine code by a program called an assembler. While, the disadvantages are that it is still difficult to understand comparing to the higher-level languages and it is machine dependent as well.
 

 


High-Level languages

High-Level languages are different from low-level languages in that they are not machine dependent. Therefore, programs written on one computer can generally be used on another similar computer. They also use keywords similar to English and are easier to write.

Third generation languages (3GLs)
are designed to be easier for you to understand. These languages are converted to machine code, rather like translating from one language to another, so that the computer can carry out the instructions in the CPU.

Examples of third generation languages are, FORTRAN, BASIC, Pascal and C. This generation of languages support procedural languages, which simply means that the program will execute a sequence of instruction in a specific order.

  • FORTRAN (Formula Translator) first high level language, used to express mathematical formulae, scientific problems and engineering problems.
  • BASIC (Beginner's All-purpose Symbolic Instruction Code) a very easy to learn language that was created to teach programming. There are many versions of this language the most popular being Visual BASIC.

  • Pascal - this third generation language was named after 17th century mathematician Blaise Pascal - a language that uses structured programming mostly used for teaching purposes. Pascal is an easy to learn language that is an alternative to BASIC.
  •  C - a language used mostly to write operating system, database management software and scientific applications. C is a general-purpose language that can be used in many computers.

  • C++ an object-oriented programming language that was originally an extension of C but has now become very powerful.

The advantage is that it can use English-type words to write program code, making it easier to create. While the disadvantage is that programs also have to be converted to machine language.


 Fourth generation languages (4GLs) are non-procedural that is programs such as COBOL (Common Business Oriented Language) are written to provide easy ways of designing screens and reports, and using databases. They contain commands to read and process the data and place the results in report-form on the page.


  • COBOL (Common Business Oriented Language) a language used in commercial and business application. The program consists of four sections called the identification, environment, data and procedure divisions.

The advantage is that it is useful for generating reports and the disadvantage is that it can become very wordy.

 Fifth generation languages (5GLs)
are sometimes regarded as very-high-level languages. In theory, 5GLs are non-procedural languages, meaning that the programmer states the goal to be achieved, but not the steps required in order to achieve the goal. Prolog (Programming Logic) is a fifth generation language.


  • Prolog (Programming Logic) a language used to develop artificial intelligence application programs like natural language and expert systems. It accomplishes its tasks by declaring facts, asking question and defining rules about a specific area of knowledge.
The advantage is that computers will be able to communicate in natural spoken language with their users and the disadvantage is that it is very complex to design, programmer must be highly trained.


Solving the Problem

The most important part of a programmer's job is solving the problem first. You should first think about a method and develop an algorithm to solve the problem. An algorithm is a sequence of precise instructions, which results in a solution. The keyword here is precision. If your algorithm is vague and has conflicting logic, you will not get the correct answer.

Problem solving is usually broken into two phases.

Algorithm Phase

In the first phase, there are three (3) steps:

  1. Clearly define the problem that you want to solve.
  2. Design an algorithm that is precise and well thought out to solve the problem.
  3. Test your algorithm on paper. Make sure your algorithm work correctly before you can write a program for it.

Implementation Phase

In this phase, there are two steps:

  1. Translate your algorithm into programming language such as BASIC, Pascal, C or C++. If you have a correct and precise algorithm, the translation should be almost line-by-line. This translation must be correct and free of:

    • Syntax errors - these are errors that result from not obeying the rules (syntax) of the programming language
    • Logic errors  made by the programmer, such as dividing by 0.
  2. Test the program to make sure it produces the correct results

Solving the Problem

The most important part of a programmer's job is solving the problem first. You should first think about a method and develop an algorithm to solve the problem. An algorithm is a sequence of precise instructions, which results in a solution. The keyword here is precision. If your algorithm is vague and has conflicting logic, you will not get the correct answer.
Problem solving is usually broken into two phases.
Algorithm Phase
In the first phase, there are three (3) steps:

  1. Clearly define the problem that you want to solve.
  2. Design an algorithm that is precise and well thought out to solve the problem.
  3. Test your algorithm on paper. Make sure your algorithm work correctly before you can write a program for it.

Implementation Phase
In this phase, there are two steps:
  1. Translate your algorithm into programming language such as BASIC, Pascal, C or C++. If you have a correct and precise algorithm, the translation should be almost line-by-line. This translation must be correct and free of:

    • Syntax errors - these are errors that result from not obeying the rules (syntax) of the programming language
    • Logic errors made by the programmer, such as dividing by 0.
  2. Test the program to make sure it produces the correct results.

For further reading on this topic you can get additional information on this website:

http://www.stmonicascollege.org/cxcit/2012/topics/programming/programming-made-simple-ch3.pdf
  • Information includes:
  • Defining the Problem
  • Designing the Program
  • Coding the Solution in Pascal


    You can also visit your public library to get additional information from the "Oxford Information Technology for CXC/CSEC" By: Glenda Gay & Ronald Blades

     

 References and Further Reading

Gay, Glenda & Blades, Ronald (2005). Oxford Information Technology for CXC CSEC 'Introduction to Programming' (p.49&50).

     

No comments:

Post a Comment