Beruflich Dokumente
Kultur Dokumente
Computer programmers write programs. But as set of instructions that we would understand is
very different from instructions that a computer would understand. To write a program, you have
to use a specific programming language range from the very basic binary system to complex
language with rules and syntax.
First generation
First-generation languages are low-level language-machine language or machine code. They
are programming language in their purest form. Machine language can be understood by a
computer, so it does not need to be translated. Binary is used to program in machine language,
Machine language executes very quickly, but it is difficult and time-consuming to write
programs in machine language. Here is an example of code written in binary:
100 0001
100 0010
Recall how chapter 4 used 1s and 0s to solve simple arithmetic problems. Now imagine trying to
use this system to write complex programs. It would be difficult to write them and it would be
easy to makes. That is why later generations of programming language evolved-to make it easier
for programmers to write sophisticated software.
Second generation
Second-generation languages are low-level languages and are often called assembly language.
They use short pieces of code instead of binary. Each code looks and sounds like the value or
action it represents, write programs in assembly language than in machine code. An assembler is
used to translate assembly language into machine code.
This command instructs the computer to add the value 20 to accumulator B:
ADD, 20
Third generation
Third-generation languages are high-level languages. Instead of using machine-specific code,
they use statements in English that are easy for programmers to use. Here are some common
third-generation languages:
Pascal
COBOL (Common Business-Oriented language)
FORTRAN (Formula translation)
BASIC (Beginners all-purpose symbolic instruction code)
C.
And here is a Pascal program that adds two values:
PROGRAM Addition;
VAR
numA, numb, numc : integer;
BEGIN
read(numA);
read(numb);
numC := numA + numb:
write(numC);
END.
The commends are English words that are fairly simple to write and understand. A program
written in third-generation language is easy to follow, because it is structured with statements
and keywords. The BEGIN and END keywords tell you where the processing begins and ends.
Fourth generation
Fourth-generation languages are very similar to third-generation language, except they are even
easier to use. They use English-like statements and offer extra help through, instructions and
wizards. Wizards are program assistants that guide the user. This means that programs can be
written very quickly and easily and may not require the expertise of a programmer. Fourth-
generation languages are often used in business because it is fairly quick and easy to train people
who are not computer experts on how to use them. Here are some fourth-generation languages:
Structured query language (SQL)
Visual Basic
C++
Oracle Report.
SQL is used for managing databases. The following SQL commands tell the computer to
search a collection of data called customer_information for data called cust_name and
select the data if purchases are over 100:
Fifth generation
Fifth-generation language is built on third-and fourth-generation languages. They are sometimes
called non-procedural languages. Require the programmer or user to write out the sequence of
steps to solve a problem. Non-procedural languages only require the programmer to write the
goals that have to be achieved and any constraints or parameters that are required. The computer
solves the problem-it works out the required steps.
For this to work, the computer must have a knowledge base to work, so its problem-solving
abilities are limited to what has already been programmed. This type of language. Here are two
commands in prolog:
?- fruit (apple).
?-fruit(x).
The first asks, is an apple a fruit? The second asks what things are fruits?
The computer could respond:
Yes
x = apple
Implementing a program
Chapter 7 introduced the steps for problem solving. Step 5 was write a program in a
programming language and step 6 was to test and debug the program. Steps 5 and 6 can be taken
together and expressed as five stages that ensure smooth progress:
Interpreters translate code one line at a time. Interpreters have to run on the same machine
that runs the program, because the program is interpreted every time it is run. Compilers
translate code in one go and create a stand-alone program. This program can be run on many
different machines, which makes compilers more efficient than interpreters.
If there are errors in a program, it will not translate properly. If there is a syntax error, the
translating and may return an error message.
Stage 3: Link
When you write a long or complex program, you will probably write it in pieces or sections.
Linking puts the sections together to create one piece of code.
Syntax errors
Code has to be written according to syntax rules, which dictate how you structure statements,
much like the rules of English grammar. A computer cannot understand code when there is a
syntax error. A good indicator that there is a syntax error in a program is when a translator
cannot translate the program properly. An example of incorrect syntax is an IF statement without
an accompanying THEN statement.
Logic errors
Logic errors occur when there is a mistake in the flow or sequence of a program. An example is a
calculation that uses a variable before the user has entered the variable into the program. The
program may run, but the output may be inaccurate. Logic errors can be picked up by doing tests
on paper and creating flowcharts that follow the logical flow of the program.
Run-time errors
Run-time errors occur when the program is being carried out. They may be the result of external
factors, such as lack of computer memory or getting stuck in a loop. Run-time errors can occur
when values lead to illegal operations, such as dividing by zero.
Types of testing
Test your program before you execute it. You can do this in two ways:
Testing on paper and computer testing. Dry-run tests and trace tables are methods of testing
on paper. Dry-run testing is a method of checking that a program does not contain any logic
errors. If the program uses loops, you can use trace table to trace the logic of a program through
multiple values. Both these methods are described and demonstrated in chapter 8.
Computer testing is where you test a program on a computer by running it with as many
different types and combinations of data as possible. In an IT environment, this task would go to
a program tester. The tester runs the program will run in all circumstances and conditions.
For example, if a program requires a user to input numeric data, a tester must ensure that all
kinds of numeric data will work, such as identical numbers, positive and negative numbers, and
values that are when the program is used in a live environment.
Internal documentation
Internal documentation is also called technical documentation. If you are looking at a long and
complex program that you did not write, internal documentation can help you see how it works.
There are several forms of internal documentation:
A programmer can insert comments into the code. Comments are sentences intended for
the user. They are coded so a computer does not read them. Comments are useful for
explaining a piece of code or are easy to read and do not require many comments.
Indentation groups sets of statements to reveal the structure and flow of a program.
White spaces are spaces in a program created by indentation and by writing statements on
separate lines instead of on one line. White spaces help to make programs clear and easy
to follow.
Identifiers are used for different items of data in a program. Good identifiers clearly
indicate the nature of the data. Chapter 10 has more about identifiers, comments and
program structure.
Programmers may write and update their own technical guides. These guides may have useful
indexes of the mnemonics used in coding plus details of how the program was written. Technical
guides may contain diagrams, flowcharts and algorithms to help explain the program. Other
programmers can refer to technical guides to help them modify and maintain programs.
External documentation
External documentation is often called user documentation or user manuals. User manuals
provide installation instructions, provide instructions and any other technical specifications that a
user needs to run or install a program. Most general-purpose applications have a built-in help
function, which is a digital copy of the user documentation. If you have installed a program on a
computer you may have seen a document called readme or similar in the folder that contains
the program. The readme document has instructions on getting started. Many popular general-
purpose applications, such as word, have instructions built into the program- as you install the
program; a wizard guides you through the steps. When you create a new version of a program
you have written, create new version of the documentation.
Test programs and algorithms for correctness and make required changes
Debugging debugging is the process of locating and fixing or bypassing bugs (errors) in
computer program code or the engineering of a hardware device. To debug a program or
hardware device is to start with a problem, isolate the source of the problem, and then fix it.
Test Run This is when you enter your test data to check if the program is working efficiently.
Test Data Sample data that mimics real data a program will process once it is in production.
Dry-Run A manual transversal of the logic of a program, for example using a trace table to
test the results of a program.
Source Code This is the typed program instructions that people write, the program is then
translated into machine instructions that the computer can execute.
Object Code In programming, the machine readable instructions created by a compiler from
source code.
Compiler This is a program that converts the entire source code into machine language (object
code) before executing it.
Executing The processor operation that carries out commands; part of the machine cycle
(fetching, decoding and executing).
Interpreter In programming a translator that converts each instruction into machine readable
code and executes it one line at a time. Interpreters are often used for learning and debugging,
due to their slow speed.
Loading This is the process of a computer transferring program instructions from storage to
memory.
Machine Level This is the native binary language consisting of 0s and1s that is recognized and
executed by a computers central processing unit.
Pseudo Code-Algorithms
A pseudo code is an imitation computer program written using mathematical notations and
English like statements to describe the logics to solve a problem or carry out a procedure.
Parts of Pseudo Code Algorithms:
1. Input Statements
2. Assignment Statements
3. Output Statements
4. Control Statements (sequence input for a program)
Output Statement-: Use to control the amount of time a statement or sequence of statement is
carried out based on some conditions.
Variable-: A named location in memory the value of which may change during the execution of
a program.
Constant-: This provides location for storing data which do not change during the execution of a
program.
The input statement is used to get data from outside the computer via some input device into a
variable for manipulation by the pseudo code. For input will use Read. We will use the
following conversion.
Example 1
Read A, B
Or
Read A
Read B
Example 2
Write a pseudo code algorithm to values into variables Month, Years, Date.
Assignments Statements
Assignment statements are used to give initial value to variables and to change the value assign
to a variable. The assignment statement has two parts:
1. The L Value
2. The R Value
The L value refers to variable as the storage location where the R value will be stored.
The R value refers to value which may be the result of an expression or the content of another
variable.
Salary = 2000
Write a pseudo code algorithm to read two numbers and find their sum
Read num 1
Read num 2
Sum = num1 + num2