IT Notes Unit 8
IT Notes Unit 8
IT Notes Unit 8
Low level language is a programming language that deals with a computer’s hardware
components and constraints.
These are languages that are classified as machine dependent, meaning, only a particular CPU
will understand this type of language.
Different types of computers have various types of processors, this means that programming
codes that are written on any type of computer may not work on another.
There are two main types of low-level languages.
o First generation (1 GL) – machine language.
o Second generation (2 GL) – assembly language.
Translator – converts one language into another. A translator, in software programming terms, is a
generic term that could refer to a compiler, assembler, or interpreter;
Compiler – a special program that converts high level language (source code) to machine language. The
entire program is converted at once.
Interpreter – a special program that converts high level language (source code) to machine language.
The conversion takes place one line at a time.
Assembler - An assembler translates a program written in assembly language into machine language.
o Logic error – this error when there is a mistake in the design of the program. Although
the program would compile and no errors would show up during compiling, the results
of the program may not be correct.
Example below -
if mark <= 40 THEN
writeln (‘PASS’)
else
writeln (‘Fail’);
In the above lines of Pascal codes, these lines would compile and no
errors would show up. However, if a student scores 60 marks,
according to the codes the program would output “Fail” because
according to the test condition, if the mark is <= 40 then “Pass” will be
printed. The problem here is the LOGIC in the code.
o Run-time error
This occurs during the program execution stage when you attempt to run the
program.
Are detected during the execution and usually cause the program to terminate
abnormally.
o Summary of the 3 types of errors are illustrated in the diagram below.
Debugging techniques.
Debugging is the routine process of locating and removing computer bugs, errors or
abnormalities which is systematically handled by the software programmers.
Debugging checks, detects and corrects errors or bugs to allow proper program operation.
Some common debugging techniques are
o Correcting syntax errors.
o Correcting logic errors in the program codes.
o Activating the debug feature of the compiler (eg in the Pascal program, execute from
the menu, then choose debug)
o Variable checker – used to determine if the variables are of the correct data type.
o Step mode – If the next instruction is a call of a function block or a sub-program, the
execution passes over (step over) to the following instruction.
o Break point – The programmer can set break points in the code causing the program to
stop at scheduled intervals so that the status of the program can be examined in stages.
Examples of declaring variables and constants will be illustrated in advanced Pascal programs
that will be done.
program display;
begin
writeln('This is what will print.');
readln;
end.
end. This is used to end the program. You would notice that
this last statement has a period (.) instead of a semicolon.
In advanced programs, end is used within a program for a
different purpose for example for something called block
statements.
Consider the following program named moreDisplay. (Refer to program name p2 moreDisplay)
program moreDisplay;
begin
writeln('Hello form 4 Science');
writeln('My name is Siri');
writeln('Watch now all dem iPhone people feeling nice.');
writeln('I''ll stick to my $99 Digicel mee-too.');
readln;
end.
This is what the program will produce after is has been executed.
The explanation from the first program is applicable to this program as well. Pay attention to the
following;
Each new statement you want printed has to go in a new writeln(‘ ‘ );
The 3rd writeln statement has I''ll, notice there is 2 single quote after the I. The reason for this
is, whenever you want to use an apostrophe, you must use the double single quote. If you use
only 1 single quote, that will signal to the computer that the statement has ended because
remember the syntax of the writeln statement is writeln(‘abcdef’); That is, writeln, open
bracket, open single quote, close single quote, close bracket and semicolon.
Remember these codes from the program moreDisplay. The codes on the right was modified to
change the writeln to write. Although the program will still work error free, look at the
following output screen and note the differences.
So far we have learnt how to output information in Pascal using the write/writeln reserved
words.
For a program to allow the user to input data/accept data, whatever data is required to be
entered as input, must be stored in a variable. For example, if you want the user to enter his
name, you would need a variable to store the name. The variable can be any sensible name
such as name or Fname.
If the program requires you to enter 2 names, then you would need 2 variables to store the 2
names. For example, name1 and name2.
A good method to help you to determine how many variables you need is to refer to the IPO
chart. In the INPUT column, whatever is required to be input, you would need a corresponding
variable for each item.
Consider the following problem statement and IPO chart.
Write a program to allow a student to enter his name, maths mark and English mark. The
program should output the student’s name, maths mark and English mark.
From the above IPO chart, you would recognize that there are 3 items we need to input so we
therefore require 3 variables. Note, the same variables used for the input are the same
variables in the output column, so you don’t need separate variables or another 3 variables for
the output. The variables in the input and output columns are all the same.
When naming variables, there are some rules you should follow.
The name of a variable -
a. Can start with an underscore “_” or a letter, lowercase or uppercase, such as a letter from a
to z or from A to Z. Examples are Name, gender, _Students, pRice
b. Can include letters, underscore, or digits. Examples are: keyboard, Master, Junction, Player1,
total_grade, _Score_Side1
c. include special characters such as !, %, ], or $
d. Cannot include an empty space
e. Cannot be any of the reserved words
f. Cannot be longer than 32 characters (although allowed)
g. Can consist of one word such as country. A name could also be a combination of more than
one word, such as firstname or dateofbirth.
Given these rules we can safely use the following variables for the items in the input column above.
o Name – name
o Maths mark - MathMk
o English mark – EngMk.
The corresponding program for the IPO chart above would be displayed below.
(Refer to program p3 inputOutput)
program inputOutput;
var name:string;
mathMk, engMk:integer;
begin
writeln('what is your name ?');
readln(name);
writeln('Enter your Maths mark :');
readln (mathMk);
writeln('Enter your English mark :');
readln (mathMk);
writeln;
This is what the program will produce after is has been executed.