Programming Concepts:

Your computer is a dumb machine until it has a program to follow - the program provides the power to make the computer accomplish!

From the minute you turn on your computer, it is following instructions. If you tell it to play a game it follows the instructions the programmer has written in the game. If you want to do a spreadsheet using Excel, it follows the instructions in the Excel application program. If you want to generate paychecks, the computer follows the instructions in the payroll program you provide.

Learning to program is a combination of learning to develop the logic to solve a problem and then learning to express that logic using a series of instructions written using a programming language.

Programming languages have specific vocabulary and syntax rules that are required to make what you are writing understood. When you learn a programming language, you are learning the vocabulary and syntax rules. But this is only part of programming - and in fact it is what many say is the easy part. The other part of programming requires the programmer to understand the logic to solve the problem that the programmer is trying to solve. If you are writing a game program you need to think through the logic needed to make the game exciting and write this logic into the program. If you are writing a program to generate payroll checks you must deal with the logic necessary to calculate the amount to be paid and then print this out on the check.

Now lets look at how this all works.

Machine Language:

The computer needs instructions in its native machine language, which is code represented using the binary system. Machine language essentially uses the on/off settings of circuits and these on/off settings can be represented using the 1/0 of the binary numbering system. To program in machine language, means writing instructions using these 1s and 0s. This is extremely time consuming and complex. So, programming needed a better approach. That is why programming languages were developed.

Programming Languages:

Assembly Language: The language closest to machine language is assembly language. It uses a simple code that is very closely aligned to the way machine language was written. Once the code is written, it needs to be turned into machine language because that is the native language of the computer. To do this an assembler is used. An assembler is a program that takes assembly language code and translates it into the machine language code that can be run on the computer. Assembly language is called a low-level language because it is so close to machine language. It is used for very technical programming. However, it is very time consuming and complex. So high level languages were developed.

High level languages: A high level language allows the programmer to write one instruction that will be transferred into many machine language instructions. For example, to do a calculation in a high level language involves one instruction telling the computer what the calculation is. To do the calculation in a low level language requires many instructions, as the answer is calculated one small step at a time. High level languages are also more portable. COBOL for example is machine independent. Any computer that has COBOL installed can be used to run your COBOL program. This is also true with other high level languages such as Visual Basic, C++ and Java.

When a programmer writes a program using COBOL or another high level language, that program can not be run on the computer because the computer needs the program to be in its native machine language. To move from COBOL to machine level language requires a compiler to translate COBOL into machine language.

Compilers: When the COBOL compiler is used, it does two things. First it checks to make sure that you have used the language correctly and then it converts your COBOL program to machine language. The COBOL you write is called the source program. The compiler takes that source code and translates it into machine language. This is called object code. Then a linker program is used to link in other required things and provide the addresses that will make the code executable. In the MicroFocus COBOL that you will be using, the linker is invisible. When you compile the program you get the results of the compiler and the linker returned as the executable object code. The compiler saves this executable object code as a program that can be executed without going through the compile stage. This executable object code is the native machine language.

Interpreters: Interpreters are another way to translate high level source code into object code. The interpreter translates the code as it executes. No executable object code is produced.

  

Programming Structures:

We are going to talk about three major programming structures that help define the logic that needs to be done in most programming:

Sequence means that you have one instruction following another - the control moves through the program one instruction at a time and when it reaches the end of the statement sequence the program is over.

For example:

  1. Take in a number and store it in a storage area called wkfirst
  2. Take in a wksecond number and store it in a storage area called wksecond
  3. Add the number stored in wkfirst to the number stored in wksecond and store the answer in wkresult
  4. Show the answer that is stored in wkresult

 

 

If wkfirst contains the number 12 and wksecond contains the number 15 than wkresult will contain the number 27.

 

 Condition means that processing asks a question (frequently with an IF) and the answer to that question determines what instruction will be processed next.

For example:

    1. take in a number and store it in wkfirst
    2. take in a number and store it in wksecond
    3. Add the two numbers and store it in wkresult

In our example wkresult is 27. Since 27 is greater than 20, we would display 27 and the word GREATER.

 

In this example because wkresult = 27, it is greater than 20 so the YES branch is taken from the condition and 27 GREATER is displayed.

 

Iteration means that we want to repeat something over and over until a condition ends the repetition.

For example: If we wanted to take in numbers, add them together and test the results 5 times this would be iteration. We are repeating the sequence of instructions 5 times. The condition that ends the iteration is when a count that we keep to count the number of iterations becomes greater than 5.