0% found this document useful (0 votes)
1 views17 pages

FOC Unit 5- Computer Programming

FOC is a subject for diploma 1st year students. It has topics related to digital electronics.

Uploaded by

Remya Sukumaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views17 pages

FOC Unit 5- Computer Programming

FOC is a subject for diploma 1st year students. It has topics related to digital electronics.

Uploaded by

Remya Sukumaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

UNIT 5

INTRODUCTION TO
COMPUTER PROGRAMMING
Flowchart Notations
Flowchart Notations
Programming Languages
The language which the user employs to interact with
the computer is known as programming language.
Programming languages can be divided into 3 major
categories :
1. Machine language – it uses only 0’s and 1’s to
represent data and instructions
2. Assembly language – Symbolic instructions are used
instead of 0’s and 1’s
3. High level language – these languages are written
using a set of words and symbols following some
rules similar to natural language such as English. The
programs written in high level language are called
source programs and these are converted into
machine readable form by compilers and
interpreters.
Generations of Languages
1. First Generation – Machine Language
• The first language – binary also known as machine language was
used in the earliest computers
• Computers can understand only 2 binary codes - 0 and 1. So, every
instruction and data was written using 0’s and 1’s
• An instruction in machine language consists of 2 parts – the 1st
part is the command which instructs the computer what functions
are to be performed. 2nd part is the operand which instructs the
computer where to find or store data.
• The machine language is difficult to write and remember
• Advantages of machine language :
1. Translation free – it is the only language that the computer can
directly execute without need for conversion.
2. High speed – Since no conversion is required, applications that are
developed using machine language are extremely fast.
Generations of Languages
Disadvantages of machine language :
1. Machine dependent – An application developed for a particular
type of computer may not run on other computers.
2. Complex language – Machine language is very difficult to read and
write since all data and instructions is in binary code
3. Error prone – Since the programmer has to remember all
commands and memory locations, it results in frequent
programming errors
4. Tedious – Programming becomes complex and time consuming
while modifying and correcting a program.
Generations of Languages
2. Second generation – Assembly language
• It was developed in the early 1950’s and its main developer was
IBM.
• This language assigns a mnemonic code to each machine language
instruction to make it easier to remember or write. For example
ADD for addition , MULT for multiplication.
• Assembly language is not a single language but a group of
languages and each processor family has its own assembly
language.
• The general format of assembly instruction is
[LABEL] <OPCODE> < OPERANDS> [; COMMENT]
Eg : BEGIN ADD A, B ; ADD B TO A
• The assembly language program must be translated to machine
code by a separate program called assembler.
Generations of Languages
• The original assembly language program is called source program
and the final machine language program is called object code.
• Advantages of Assembly language :
1. Easy to understand and use – Assembly language uses
mnemonics, so programs written in assembly language are much
easier to understand.
2. Less error prone – Since mnemonics are used, there are fewer
errors while writing an assembly language program. An assembler
also provides mechanisms to locate errors
3. Efficiency – Assembly programs run much faster and use less
memory than high level language.
4. More control on hardware – Assembly language gives direct
access to operating system kernel, device drivers etc.
Generations of Languages
• Disadvantages of Assembly language :
1. Machine dependent – Different computer architectures have their
own assembly languages, so programs are not portable.
2. Harder to learn – since it is machine dependent, every computer
architecture requires a different assembly language making it hard
for a programmer to learn all assembly languages
3. Slow development time – applications are slower to develop as
compared to high level language based applications .
4. No standardization – Each computer has a different instruction set
and therefore a different assembly language.
Generations of Languages
Third Generation : High level language
• During 1960’s , computers started to become popular and it became
necessary to develop languages that were more like natural
languages such as English.
• Languages such as COBOL, FORTRAN, BASIC and C are examples of
3rd generation languages.
• Programs written using high level languages can be machine
independent.
• Since computers understand only machine language, high level
language needs to be converted into machine language. This is done
by compilers and interpreters.
• A compiler is a translator that translates high level language into
machine language. When a program is compiled, its compiler is
loaded into the main memory. The compiler scans the entire high
level program and translates it into equivalent machine code.
Generations of Languages
• In case of errors, compiler will not create object code until all errors
are rectified.
• Interpreter is also a translator that translates high level language into
machine language. But it translates a statement in a program and
executes that statement immediately before translating the next
statement.
• Linker – An application usually consists of thousands of lines of code.
The code is divided into different modules so that debugging and
maintenance is easy. All these modules have to be linked together to
create a complete application. This job is done by a tool called the
linker.
• Loader – loader is part of the operating system that brings an
executable file from the disk into the memory and starts running. A
loader performs 4 basic tasks :
Generations of Languages
1. Allocation – it allocates memory space for the program
2. Linking – it links two or more object programs
3. Relocation – it prepares a program to execute properly from its storage
area.
4. Loading – It places data and instructions into the memory
Advantages of high level languages :
1. Readability – Since high level languages are close to natural languages,
they are easier to learn and understand
2. Machine independent- they can be used on different platforms with little
or no change at all
3. Easy debugging – Compilers and interpreters are designed in such a way
to detect and point out errors.
4. Low development cost – high level languages permit faster development
of programs.
5. Easy documentation – since high level program statements are similar to
natural languages, they are easily understood by users. There is no need
for too many comments in the program.
Generations of Languages
Disadvantages of high level languages :
1. Poor control on hardware – applications written in high level language
do not utilize the total power available at hardware level
2. Less efficient – high level languages are less efficient in terms of
computation time because of the process of translation. They take more
time to execute and require more memory space.
Generations of Languages
Fourth Generation :
• Third generation languages are considered as procedural languages
whereas fourth generation languages are non-procedural
• In non-procedural method, the computer is instructed what it must
do rather than how to do it.
• 4th generation languages make programs easier to write but they
require more processing time.
• 4th generation languages are divided into 3 categories :
1. Query languages – they allow the user to get information from
databases by following simple syntax rules.
2. Report generation – they produce customized reports based on data
stored in the database. The user can specify the data and format of
the data in the report.
3. Application generators – the user writes programs to allow the data
to be entered into the database. The program prompts the user to
enter data and also checks validity of data.
Generations of Languages
Advantages of 4th generation languages – the main advantage is that a
user can create an application in a much shorter time. Since it is non
procedural, it does not require the programmer to provide logic.
Disadvantages – they need more disk space and large memory
capacity compared to 3rd generation languages.
Fifth Generation programming languages :
• These languages will be able to process natural languages.
•The computers will be able to accept, interpret and execute
instructions in the native language of the end users.
• The programmers may simply type the instruction or tell the
computer via a microphone what it needs to do.
•These languages are closely linked to artificial intelligence.
General concepts of Variables and Constants
Constants and variables are essential to develop programs in any high
level programming languages.
A constant is a data item whose value cannot be changed during
program's execution. Constants can be classified as :
• Integer constant
An integer constant is a whole number and can be large without
including any decimal points. For example, 0, 1, 2, 123, 5767, 05, 0X23,
0xFFF, etc.
• Floating constant
The floating constants are real numbers that contain a decimal point,
fractional form and exponential form.
Here are some example of floating point constants:
0.5, 35.05, 2.3e6, 3.52f or 3.52F, PI = 3.14, etc.
• Character Constants
It is a single character enclosed within a single quotation mark (like 'a',
‘A’) There are some valid constants as: 'g', 'D', ' ', '#'.
General concepts of Variables and Constants
• String Constant
It denotes a sequence of one or more characters enclosed within
double quotes. The character may be letters, numbers, special symbols
and blank space. For example, "Hello Friends", "Computer", "5987", " "
, "A".
A variable is a data item whose value can changed during the program’s
execution. Example – sum=n1+n2, here n1 and n2 are variable names.
sum is also a variable name which holds the result after addition.
Rules for defining variable names:
• Variable names are are case sensitive.
• Variable names must start with an alphabet or underscore.
• Variable names can includes letter, digits and underscore and should
not contain special characters.
• There should not be a white space in a variable name.
• The name of a variable should not be any reserved keywords like int,
float, str, char, if etc.

You might also like