Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views

Unit 5 Programming Concepts

Uploaded by

Dipesh SAPKOTA
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Unit 5 Programming Concepts

Uploaded by

Dipesh SAPKOTA
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Computer Science Class 11

Unit 7 Programming Concepts

Programming:
It is the process of writing a program following the grammar of the programming language.
When we write a program, we’ve to follow the grammatical rules. When such statements are
written in chronological order then the program is created, which finally performs some task.
 Apple
 Ball
 Cricket

Programming Language:
Communication between two parties whether they are human beings, animals,
birds or computers requires a language which they understand. The language like Nepali,
English, Hindi etc used by human beings is called natural language whereas the communication
language used between user and computer is called programming language. The language
which is used to develop program in computer is called programming language.
Hence, it is the set of codes that a computer programmer uses to give instruction
to computer to perform some specific task. The set of rules to write the code is called syntax.
Types of programming language:
There are two types of programming language which can be categorized into
following ways:
1. Low Level Language
a. Machine Language or First generation language (1GL)
b. Assembly Language or Second generation language (2GL)
2. High Level Language
a. Procedural Oriented Language or Third generation language (3GL)
b. Problem Oriented Language or Fourth generation language (4 GL)
c. Natural Language or Fifth generation language (5GL)
1. Low Level Language: The low level language is a machine-oriented language which is
understood by the machine itself. It is machine dependent language. It is difficult to write
program using low level language. Programmers require detailed knowledge of hardware
architecture to use this language. It is further categorized as:
a. Machine Level Language (1GL): It is a first programming language used to make
program in computer. It is directly understood by machine itself. It consists of
binary numbers (i.e. 0s and 1s). it is very fast execution speed and efficient use of
primary memory but use of this language is very tedious, difficult and time
1
Computer Science Class 11
consuming. It also needs the detail knowledge of machine in order to write the
program. It is very difficult to debug.
Advantages of Machine Level Language:
 It is directly understood by the computer.
 It does not require any translating program like compile, interpreter or
translator because program itself is in binary form.
 Execution speed of the program developed in this language is faster.
 Use of hardware components like memory, processor is efficient.
Disadvantages of Machine Level Language:
 It is tedious, difficult and time consuming to develop and debug the
program.
 All operation codes have to be remembered.
 All memory address has to be remembered.
 It is machine dependent language, so program written in one machine may
not be used in another machine without modification.
 Programmers require detailed knowledge of hardware architecture.
b. Assembly Language (2GL): This language is developed to overcome the difficulties
of Machine Language. In machine level language, all the codes have to be
remembered. So, in assembly language, mnemonics code (symbols) like ADD, SUB,
DIV, MOD, JMP etc is used in order to perform the different types of tasks and
calculation. The program written in assembly language is converted into machine
language by assemble. Although it saves time, reduce errors, and easy to debug, it
has certain limitations like programmer has to remember all the mnemonics codes
to perform the task.
Advantages of Assembly Language:
 It is easier to write, debug and understand than machine level language due
to the use of mnemonics.
 Programmer does not need to know the exact storage location of data and
instruction.
 Execution speed of the program developed in this language is faster than
high level language.
 Use of hardware components like memory, processor is efficient than high
level language.
 It is useful for developing hardware oriented system software like device
driver, remote control system, microprocessor based devices, traffic light
system, robotics.

2
Computer Science Class 11
Disadvantages of Assembly Language:
 Program developed in this language cannot be executed directly. It needs to
be translated into machine code.
 Additional software, assembler is required to translated program into
machine code.
 It is also machine dependent language.
 Programmers require detailed knowledge of hardware architecture.
2. High Level Language: This language is closer to human language or English like
words or sentences and mathematical notations to perform the task. It is easier to
learn and requires less time to write and is easier to maintain errors. This language
is converted into machine language by the use of translator programs such as
interpreter or compiler. It is machine independent. So, program developed for a
system can also be used in similar systems without modification. Examples of high-
level languages are BASIC, FORTAN, ALGOL, COBOL, PASCAL, C, C++ etc. High level
language can be further categorized as:
a. Procedural oriented language (3GL)
b. Problem oriented language (2GL)
c. Natural language (5GL)
a. Procedural oriented language (3GL): This language uses simple English and
mathematical statements to develop program. It includes languages such as PASCAL,
BASIC, COBOL, C, FORTAN etc. These languages are designed to express the logic and the
procedure of problem. Because of their flexibility, procedural languages are able to solve
a variety of problems.
Advantages of using Procedure Oriented Language:
 It is easier to develop and debug program compared to low level language.
 More advanced and user friendly software can be developed.
 It is machine independent language. So, program developed for a system
can also be used in similar systems.
 Programmers don’t require detail knowledge of hardware architecture.
Disadvantages of using Procedure Oriented Language:
 Program developed in this language cannot be executed directly. It needs to be
translated into machine language code.
 An additional software, compiler or interpreter is required to translate program
into object code.
 Program execution will be slower.
 Programmers need to working process of the program in detail.

3
Computer Science Class 11
b. Problem Oriented Language (4GL): It is a non-procedural or problem oriented language.
It allows to specify what the output should be, without describing all the details of how
the data should be manipulated to produce the result. This is one step ahead from 3GL.
These are result oriented and include database query languages. There are fewer options
for programmers but the programs are much easier to write than in lower level
languages. These languages are also needed to be translated either by compiler or
interpreter. Example are: Visual Basic, c#, PHP etc.
Advantages of Problem Oriented Language:
 It is even easier to develop and debug program than procedure oriented language.
 More advanced and user friendly software can be developed.
 Web based software can be developed.
 It is also machine independent language.
 Programmers don’t require detail knowledge of hardware architecture.
Disadvantages of Problem Oriented Language:
 It needs to be translated into machine language code.
 An additional software such as compiler or interpreter is required to translate into
machine code.
 Program execution will be even slower.
 It is difficult to develop hardware oriented software.
c. Natural Language (5GL): This type of language uses simple statement of common
communication languages where we could write statements that would look like normal
sentences. It is still in developing stage computer scientists are working hard for
developing such languages. However, programming language named PROLOG is in use,
which would support 5GL to some extent.
Advantages of natural language:
 It will even easier to develop and debug program.
 More advanced and user friendly software can be developed.
 It will also be machine independent language.
 Programmers will not require detail knowledge of hardware architecture.
Disadvantages of natural language:
 It also needs to be translated into machine code.
 A language translator is required to translate program into object code.
 It is difficult to develop hardware oriented software.

Language Translator

4
Computer Science Class 11
Language Translator is system software that translates instruction written in assembly or
high level language (source code) into machine language (object code). Programs developed in
assembly or high level language are not understood by computer. So, translator program is
used which converts that statements in computer executable format.
Different types of language translators are:
 Assembler
 Compiler
 Interpreter

 Assembler: Assembler is a translator that converts the program written in assembly


language into machine language which the computer can understand for execution. It
also read each line of Assembly Language code and if it is bug free, then it translates the
line into object program.

 Compiler: A compiler is a translator which converts the program written in high level
language into machine code whole program at a time. It has features like:

o It translates complete program at once if the program doesn’t contain syntax


error.
o It provides fastest method of translating a program.
o In compiler, the syntax errors are found only after the compilation of complete
program.
o Debugging can be complex and time consuming.
o It saves object code for future reference. So, translation is not required for every
time the program is used.
o Programming languages like C, C++, Java, COBOL, AND PASCAL use compiler.
 Interpreter: A interpreter is a translator which translates high level language into a
machine language, one line at a time. Although the task of interpreter and compiler is
same, the working method is different. Unlike compiler, the interpreter reads each line
of source program and if it is bug free, then it converts program code into machine
language. So it takes more time than compiler to convert into machine language. It has
features like:
o It translates one line at a time if the statement is free from syntax error.
o It is slower for translation.
o In translator, the syntax error is found only after interpretation of the complete
statements.

5
Computer Science Class 11
o It doesn’t save object code for future reference. So, translation is required for
every time before the program is used.
o It is usually a smaller program and requires less memory space.
o Programming languages like BASIC, Visual Basic, C#, and PHP use interpreter.
Syntax and Semantics:
Programming language helps us to communicate with the compiler, which is governed by
a set of codes that a computer programmer writes to instruct the computer hardware to
perform specified tasks. These codes are governed by a set of rules called syntax. In other
words, it is the set of rules for combining the elements of a programming language into
permitted instructions. Semantics is the meaning attached to individual words or symbols in
programming language. It is the logic or concept or idea of the program.
Error (Bug):
Error is the mistakes in the program which can be in syntax or logic (concept or idea) of
the program. If a program contains error, it will either not produce output or may produce
inaccurate output. The process of detecting and correcting error is known as debugging.
Different types of error are:
 Syntax Error: It is the error in the syntax or format of the program which is happens
when it does not conform to the syntax of the programming language. For example in C
language, whenever we do not use semicolon in a simple statement causes syntax error.
It is detected by language translator at the translation process. If a program contains
syntax error, it is not translated into object code. So, it will not be executed and will not
produce output. This type of error is easier, faster and cheaper to debug. Reference
materials like help file, book, and documents are available for the syntax of the program.
 Logical Error (Semantic Error): It is an error in a logic/ concept/ idea of the program that
causes it to operate incorrectly but not to terminate the program abnormally. It is not
detected by language translator during translation process. If the program contains only
the logical error, it is translated into object code, executed and also produces output.
However, the output may not be accurate. For example, to calculate the simple interest
the formula is i=(p*t*r)/100 but if we write i= (p*t*r)/10 then it will produce semantic
error. This type of error is difficult, slower and expensive to debug. Experience
personnel’s is required. Reference materials are usually not available for logic of the
program.
 Run-time Error: when a program is running or executing, it is said to be in runtime. A
runtime error is an error that happens while the program is executing. For example, a
memory leak, where the program takes up excessive amounts of system memory is also
a runtime error, peripheral devices may not be turned on. If a program contains only the
runtime error, it is not detected by the translator. So, it will be translated into object
6
Computer Science Class 11
code and the execution will start. However, execution may not be completed and may
not produce output.
Differences between Logical Error and Syntax Error:
Logical Error Syntax Error
1. It is the error in the program’s logic 1. It is the grammatical error or
structure error
2. It is not identified by the compiler 2. It is identified by the compiler and
and interpreters during the interpreters during the transaltion.
translation.
3. If a program contains only logical 3. If a program contains syntax error, it
error, it produces output but it will will not produce output.
not be accurate.
4. Documentations, reference or 4. Documentation, reference or
guideline of logic is not available to guideline of set rules is available to the
the users. users.
5. It can be solved only by the 5. Normal graduates can debug syntax
experienced programmers. error.
6. Cost is high in correcting semantic 6. Cost is low, since normal users can
error, since program development solve the problem.
teams are needed to be involved to
solve.
7. It is complex and time consuming to 7. It is easier and not time consuming
debug to debug as logical error.

Introduction to Data Type:


A data type defines a set of values that a variable can store during the execution of the
program along with a set of operation that can be performed on that variable. It specifies the
type of data to be used in a program. The types of data types are as follows:
 Integers: Integers refers to the positive and negative whole numbers including zero. In
computer programming too, integer is a basic data type which allows a variable to store
integer numbers like 45, 755, -23 etc.
 Characters and string: character data type contains any printable alpha-numeric
character (a, b,c, ………..z , A, B, ……., Z, 0, 1,2 ………..,9) as well as some other special
characters such as @, #, $ etc. Generally in program, character or string data types are
written in single or double quotation mark like ‘A’, ‘B’, “welcome”, “Gaindakot-12” etc.
 Real: Real number refers to any type of numbers such as integer as well as fractional
(decimal) numbers. The real data type allows a variable to store any numeric values such
as signed, unsigned, fractions, exponential as well. For example: 5.5,-4.256, 3.0E-4, 5.0
etc
7
Computer Science Class 11
 Boolean: A Boolean data type can only take one of the two data values: etiher True(1) or
False (0). For example: Marital status of a person is either married (True) or unmarried
(False).
Keyword, Variable and Constant:
Keyword is a special reserved word in programming language whose meaning has been
already defined to the compiler. A keyword performs a specific task in computer program. For
example int, float, if, while, etc are few keywords of C programming language.
Variable is a named location in memory of computer which can hold some values. The
value assigned to the variable may be changed during the execution of the program, hence it is
called variable. For example: L = 10 and B= 5, here L and B are variables which contains values
10 and 5 respectively.
Constant is a value which does not change during the execution of the program. For
example 10 and 5 are constants.
Operation, Operand and Operator:
An operation in program is defined as an action upon the given data. The example of
operation are as follows:
a) Arithmetic operation
b) Relational operation
c) I/O operation
d) Data moving operation
Operand is the different type of data on which different operations take place. The data
may be value or variable. For example, 5+x where 5 and x are operands and addition
operation takes place between them.
An operator is a sign or symbol which performs an operation or evaluation on one or
more operands. For example 5+10 where + sign is an operator which indicates addition
operation.
Program Design Tools
Program design tools used to design a program before it is actually developed. It is used
by the designers.
Some of the commonly used tools in programming are:
a) Algorithm
b) Flowchart
a) Algorithm: An algorithm is the finite set of step by step of statements that solve a
particular problem. It is used to solve a particular problem. It is written in simple human
readable English language. To develop an algorithm it requires a clear understanding of
the problem.
Algorithm should have following properties.
8
Computer Science Class 11
i.It should have an input
ii.The steps mentioned in an algorithm can be executable by the computer.
iii.Each and every instruction should be in simple language.
iv. The number of steps should be finite.
v. It should not depend on a particular computer language or computer.
vi. The algorithm should give an output after executing the finite numbers of
steps.
Example: Find the sum of the two numbers
Step 1: start
Step 2: read the two number A and B.
Step 3: Add the number A and B and store in Sum
Step 4: display sum or print sum
Step5: stop
b. Flowchart: It is a graphical representation of an algorithm. It is used in programming to
diagram the path in which data and instruction are processed to obtain desired output. After
designing an algorithm, the next stage is to design a flowchart to check the flow of logic running
through it. It used different predefined graphical symbols to show the data flow within a
program or a system.
Advantages of Flowchart
 It is easier for a programmer to explain the logic of a program through flowchart.
 It helps in effective analysis of the program.
 Easy to detect, locate and remove bugs in a program.
 Efficient means of communication
 With the help of flowchart coding becomes effective and faster
 Serve as documentation
Disadvantages of Flowchart
 Very time consuming and laborious job.
 Flowcharts are difficult to maintain.
 Occupies space while documentation
 Translation of flowchart to computer program is difficult.
Types of Flowchart
 System Flowchart: It plays a vital role in system analysis. The flowchart which shows the
overview of the data flow and sequence of operations in a system is called system
flowchart. It is drawn by the system designer while developing the new system. It does
not focus on the process to solve a particular problem. It helps for designing of a system
and to show business problems.

9
Computer Science Class 11

Sequential Manual Input


Access storage Magnetic Disk

Store data Display Document

 Program Flowchart: The flowchart which shows the detailed diagram to solve a particular
problem of the program is called flowchart. It is the most commonly used flowchart. It is
used by the programmer while developing a program. It is design for specific input and
output, calculation and text manipulation, logic and comparison etc. There are some
basic flowchart symbols having different function.
Symbol Function Meaning
Terminal Box Start/ Stop Used to indicates starting points and ending
points in the program
Input/Output Box Input/ Used to indicates input or output operation
Output

Processing Box Processing Used to indicates the movement of data,


operation the editing of data or calculations.

Decision Box Decision Used to check the logical condition.

Connector Connector Used to connect flowchart from one page


to another page.

Flowlines Direction of Used to indicates the direction of flow of


logic logic.

10
Computer Science Class 11
Comment Box Comment Used to include any comments for clarity of
program

Example 1: Flowchart to calculate the sum of two numbers.

Start

Read a and b

Sum= a+b

Display sum

Stop
c. Pseudo Code: A pseudo code uses English phrases and mathematical statements to describe
the processing steps of a program or module. The instruction of pseudo code is written by using
English phrase and mathematical expression. It has no hard and fast rules for writing instruction
in pseudo code but the instructions are closer to high level language instructions.
Example: Pseudo code for calculating area of rectangle
Input length and breadth
Calculate area = length * breadth
Output area
Codes
 Absolute Binary: we use positive and negative numbers by + and – sign respectively but
in computer system 0 is placed before the binary number to represent positive number
and 1 is placed before the binary number to represent negative number. The most
significant bit in binary number denotes the sign bit and the rest bits represent the actual
number. For example:
+25 is represented as follows:
0 0 0 1 1 0 0 1

Sign bit Actual number


-25 is represented as follows:
1 0 0 1 1 0 0 1

Sign bit Actual number


 BCD (Binary Coded Decimal): BCD is a simple system for converting decimal numbers
into binary form to avoid rounding errors, where each decimal number is converted

11
Computer Science Class 11
separately into binary and placed spaces in between numbers. Each decimal number
converted as 0= 0000, 1= 0001, 2= 0010, 3= 0011, 4= =0100 etc. In BCD, each decimal
digit occupies 4-bit. For example, the decimal number 7629 can be represented in BCD as
(0111 0110 0010).
 ASCII (American Standard Code for Information Interchange): ASCII is a standard coding
system that assigns numeric values to letters, numbers, punctuation marks, and control
characters, to achieve compatibility among different computers and peripherals. It was
developed in 1968 to standardize data transmission among dissimilar hardware and
software systems and is built into most mini computers and all PCs. In ASCII, each
character is represented by a unique integer value from 0 to 255. The values 0-31 are
used for non-printing control codes, and the range from 32 to 127 is used to represent
the letters of the alphabet and common punctuation symbols. For example: the ASII code
for Capital letter ‘A’ is 65 which checks by holding down ‘Alt’ key on keyboard and
pressing 6 and 5 respectively, and free the ‘Alt’ then ‘A’ can be seen on the monitor.
 EBCDIC (Extended Binary Coded Decimal Interchange Code): EBCDIC is the character set
commonly used on large IBM mainframe computers, most IBM minicomputers, and
computers from many other manufactures. It is an 8-bit code, allowing 256 different
characters to be represented in computer. The 8-bits are divided into Zone bit (first 4
bits) and digit (last 4 bits).
 Unicode: Using ASCII 8 bit code, maximum characters can be represented is 256 which is
sufficient for English language but not for all languages such as Chinese, Japanese etc
which needs more than 256 characters. To overcome the drawback of ASCII, a new
coding system has been developed which is called Unicode. It is a 16 bit character that
supports up to 65,536 different characters. It allows all the characters and symbols in any
language in the world to be represented by a single code. For example, the Chinese
language has almost 10,000 basic characters which can be represented by Unicode only.

12
Computer Science Class 11

13

You might also like