You are on page 1of 36

Programming Language

➢ Language is a means of communication. A language(nepali, english) used by humans to


communicate is called natural language whereas language used by computer is called
programming language. Programming language helps us to develop programs or
applications in a computer.
➢ The process of writing code is called programming or coding.
➢ The person who writes program codes is known as programmer.
➢ There are two types of programming languages.
i. General purpose programming language
➢ used to solve almost all types of problems.
i. Specific purpose programming language
➢ Used to solve problems of specific nature.
Types of Programming Language
Programming Languages are classified into two categories. High Level Programming Language(HLL) and Low
level Programming Language(LLL).
Machine Language and Assembly Language are low level languages whereas Third Generation, Fourth
Generation and Fifth Generation Language are High level languages.

i. Machine Language
➢ Machine Language is the language of CPU which consists set of instructions composed with Os and 1s.
➢ It is the first language of Computer System

Advantages
➢ It doesnot require translator Program
➢ Execution time is extremely Fast

Disadvantages
➢ Programming is complex
➢ It is machine dependent
➢ Difficult to find errors
➢ Not suitable for complex problems
ii. Assembly Language
➢It was developed to reduce the complexity of machine language.
➢Programming is done by using alphanumeric characters.
➢Meaning symbols are used for programming.
Eg: ADD A, B
SUB A, B etc
Such symbols like ADD for addition, SUB for substraction are symbolic codes known as
mnemonics.

Note: Set of original Program instructions is source code. And the translator program
assembler translates the code written in assembly language to machine code or object
code.

Advantages
➢ Easier to understand than machine language.
➢ Easier to find errors.
➢ Execution time much less than HLL.
➢ Efficient to solve hardware interfacing problems.
Disadvantages
➢ It is machine dependent.
➢ Complex for programming
➢ Programmer should have deep knowledge about hardware
➢ Slower execution than machine language.
iii. Third Generation Language(3GL)
➢First general purpose programming language is 3GL.
➢FORTRAN (Formula Translation) is the first HLL.
➢The instructions in 3GL are expressed in more like English structure and mathematical
expression.

Advantages
➢Easy for program development
➢Machine Independent Language
➢Easy for modifying and finding erros
➢Doesnot require depth knowledge about the internal hardware while programming.

Disadvantages
➢Program Execution is slower.
➢Mostly CUI(Character User Interface) based languages.
➢Cannot solve specific type of real word problems.
iv. Fourth Generation Language (4GL)
➢Specific Purpose Programming Language.
➢They are specially developed for solving specific type of problems such as database
problems, web-based problems, application development etc.
➢Fourth Generation Language is specific purpose high level language in which the
instructions are expressed by using graphical components and English like structures.
➢Fourth Generation Languages are further classified into following
i. Database and Query Processing Language: They allow user to maintain database
management system. Eg: MySQL, Oracle etc
ii. Application Generator Language: They allow programmer to make any kind of
application software as well as system software.
Eg: Visual.net, java, C# etc
iii. Web Based Scripting Languages: They allow programmer to develop web based
application.
Eg: HTML, XML, PHP etc
Advantages
i. Efficient and user friendly language.
ii. Programmer can design, create and debug an application in very short period of time.
iii. Machine independent.

Disadvantages
i. More memory and disk storage required.
v. Fifth Generation Language (5GL)
➢Fifth generation language is a special type of future generation language in which the
statements will be expressed in more like human language(English, Nepali).
➢They are particularly used in the areas of robotics, artificial intelligence and expert
system.
➢PROLOG and LISP have been used as fifth generation language.
Language Translator (Language Processor)
➢A language translator is a system software which translates the program written in
assembly language and high level language into machine language program.
➢Program written in any programming language is called source code and the program
obtained after translation is called machine code or object code.
➢There are three types of language translators. They are
➢Assembler
➢Interpreter
➢Compiler
Assembler
➢Assembler is a language translator which translates program written in assembly
language into machine language program.
➢A computer doesnot understand assembly language program so it must be translated
into machine language program before execution.
Interpreter
➢An interpreter is a language translator which translates high level language program into
machine language program one instruction at a time. i.e It translates one statement of
program at a time and executes the statement immediately and moves to the next
statement. When a error is encountered in the program, the process of translation is
halted and error message is displayed.
➢Programming Languages such as BASIC, LISP use interpreter.
Compiler
➢A compiler is a language translator which translates high level program into machine
language program all at once.
➢If there is syntax error on source code then compiler produces system errors and causes
of the errors after compiling whole program.
➢Programming Languages such as C, C++, C# uses compiler
Types of Errors
i.Syntax Errors
Syntax errors are also known as the compilation errors as they occurred at the compilation
time, or we can say that the syntax errors are thrown by the compilers. These errors are
mainly occurred due to the mistakes while typing or do not follow the syntax(basic rules) of
the specified programming language. These mistakes are generally made by beginners only
because they are new to the language. These errors can be easily debugged or corrected.
• For example:
1.If we want to declare the variable of type integer,
2.int a; // this is the correct form
3.Int a; // this is an incorrect form.
• Commonly occurred syntax errors are:
• If we miss the parenthesis (}) while writing the code.
• Displaying the value of a variable without its declaration.
• If we miss the semicolon (;) at the end of the statement.
Types of Errors
ii.Logical Errors (Semantic Errors)
➢The logical error is an error that leads to an undesired output. These errors produce the
incorrect output, but they are error-free, known as logical errors. These types of
mistakes are mainly done by beginners. The occurrence of these errors mainly depends
upon the logical thinking of the developer. If the programmers sound logically good, then
there will be fewer chances of these errors.

iii.Run Time Errors


➢Sometimes the errors exist during the execution-time even after the successful
compilation known as run-time errors. When the program is running, and it is not able to
perform the operation is the main cause of the run-time error. The division by zero is the
common example of the run-time error. These errors are very difficult to find, as the
compiler does not point to these errors.
Program Design Tools
i. Algorithm
➢Algorithm is a step-by-step procedure, which defines a set of instructions to be executed
in a certain order to get the desired output.
➢Algorithms are generally created independent of underlying languages, i.e.
an algorithm can be implemented in more than one programming language.
➢In other words, Algorithm is finite sequence of instructions for solving a problem.
➢Some of the guidelines for writing an algorithm are as follows.
•The number of instructions should be finite
•Instructions should be in simple language
•Should not use ambigious instructions
•Should have input, process and desire output after executing the algorithm.
•Should not depend on any language
Advantages
➢Easy and simple to understand.
➢No hard rules for writing an algorithm
➢Doesnot require prior knowledge of programming while writing an algorithm

Disadvantages
➢Difficult to translate algorithm into program codes.
Algorithm for adding two numbers
Step 1:Start
Step 2:Declare two variables x,y and z.
Step 3:Input values for x and y
Step 4:Add x and y, store the result in z.
Step 5:display z
Step 6: Stop
An algorithm to find the largest number among three numbers
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Input variables for a, b and c.
Step 4: If (a>b)
If (a>c)
Display a is the largest
Else
Display c is the largest
Else
If (b>c)
Display b is the largest
Else
Display c greatest
Step 5: Stop
ii. Flowchart
➢A flowchart is a diagrammatic representation of an algorithm.
➢It shows the order of instructions and relationship between them.
➢It uses different meaningful symbols to solve a problem.
Flowchart to add two numbers
Flowchart to find largest numbers among two numbers
Flowchart to find largest numbers among three numbers
Advantages
➢Easy for converting flowchart into program codes.
➢it shows the types of instruction whether an instruction is input/ouput,
process or logical.
➢efficient tools for solving logical and mathematical problems.
Disadvantages
➢difficult for large and complex programs.
➢time consuming for designing a flowchart
➢difficult for modifying the flowchart
➢designer should be familiar twitch different symbols and their respective
meanings.
Advantages
➢Easy for converting flowchart into program codes.
➢it shows the types of instruction whether an instruction is input/ouput,
process or logical.
➢efficient tools for solving logical and mathematical problems.
Disadvantages
➢difficult for large and complex programs.
➢time consuming for designing a flowchart.
➢difficult for modifying the flowchart.
➢designer should be familiar twitch different symbols and their respective
meanings.
iii.Pseudocode
Pseudo code is a combination of two words: Pseudo and Code.
‘Pseudo’ means imitation and ‘code’ refer to instruction written in the
programming language. Pseudo code is not a real programming code. It is the
generic way of describing an algorithm without using any specific programming
language-related notations.

Pseudo code are written by using English phrase and mathematical expressions.

Advantages
-Complex problems could be solved by using pseudocode.
-easy for converting pseudocode into program codes.
-independent of any programming languages.

Disadvantages
-should have prior knowledge or programming while writing pseudocode.
-more complex than algorithm
Pseudocode to add two numbers

Start
Input a, b
Calculate sum=a+b
output sum
Stop

Pseudocode to find largest/greatest number among two numbers

Start
Input a, b
if( a>b)
output a is greater
else
output b is greater
Stop
Pseudocode to find largest/greatest number among three numbers

Start
Input a, b,c
if( a>b) AND (a>c) then
output a is greater
else if(b>c) then
output b is greater
else
output c is greater
Stop
Control Structures
Control Structures are just a way to specify flow of control in programs. Any
algorithm or program can be more clear and understood if they use self-
contained modules called as logic or control structures. It basically analyzes and
chooses in which direction a program flows based on certain parameters or
conditions. There are three basic types of logic, or flow of control, known as:

i.Sequence logic, or sequential flow

ii.Selection logic, or conditional flow

iii.Iteration logic, or repetitive flow


i.Sequence
➢“Sequence control structure” refers to the line-by-line execution by which statements
are executed sequentially, in the same order in which they appear in the program.

start

Statement 1

Statement 2

Statement 3

stop
ii.Selection
➢A selection structure is known as branching statement.
➢It has decision making capabilities based on given conditions, if the condition is true,
one set of instructions will be executed otherwise, another set of instructions will be
executed.
➢Some of the selection structures are if else, if else if, nested and switch case statement
etc.

Entry

False True
Condition

Statement 2 Statement 1

Stop
iii.Iteration/Looping/Repetition
➢In iteration, an instruction or group of instructions are executed repeatedly executed
until some condition has been satisfied.
➢It has three fundamental components: initialization, condition and counter.
➢Initialization: defines starting point of loop
➢Condition: Stopping point of loop
➢Increment/decrement: used as counters
➢There are three types of loops: while, do while and for loop.
entry
intialization

conditio false
n
True
Statements

Increment/
Decrement Exit
Absolute Binary, BCD, ASCII and Unicode (codes)
i.Absolute Binary
We use plus sign + and minus – sign to represent positive and negative numbers
respectively. But in computer system 0 is placed before binary number to represent
positive number and 1 is placed before binary number to represent negative number.
The binary number is expressed in 8-bits, 16-bits,32-bits or 64-bits format as per the word
length of word processor.
Eg: +12 in 8 bit binary number is 00001100 and -12 is 10001100.
ii.BCD
The Binary Coded Decimal Code is used to represent numberic data in computer. It uses 4
bits to represent a single digit number. For examples, BCD code for 7 is (0111) and BCD
code for 15 is (0001 0101).
iii.ASCII
The American Standard Code for Information Interchange is the standard code to represent
data in computer. It assigns numeric value for each character, number and symbol. It is
extensively used in most of the computers, peripherals and software. It is 8-bits code
which represents 256 characters or symbols. For examples, ASCII code for A-65, B-66, a-97,
B-98 etc
iv.EBCDIC
It stands for Extended Binary Coded Decimal Interchange Code. It is an eight bits code,
which defines 256 different characters or symbols. It is mostly used in IBM mainframe and
other minicomputers. IT is not used in personal computer.
v.Unicode
Unicode Worldwide Character Standard is a character set which provides 16 bits code to
represent 65536 different character, numbers, symbols etc. It includes characters of all the
languages of the world. It also includes all characters from ASCII character set. A newer
version of Unicode has 32 bits character set which represents more than 4 billion different
character or symbols of the world.
Assignments
Q. Write an algorithm and flowchart to add two numbers.
Q. Write an algorithm and flowchart to calculate area a circle.
Q. Write an algorithm and flowchart to check whether a number is odd or even.
Q. Write an algorithm and flowchart to check whether a number is positive or negative.
Q. Write an algorithm and flowchart to display multiplication table of 5.
Q. Write an algorithm and flowchart to 1,2…..5 .
Q. Write a pseudo code for calculating simple interest.

You might also like