0% found this document useful (0 votes)
507 views

Unit 5 Programming Logic and Concept

This document discusses programming concepts and logics. It defines a program as a set of step-by-step instructions written in a programming language to perform a task. Programming involves writing code to perform specific tasks. Good programming languages are accurate, clear, simple, efficient, modular, general, robust, and secure. Languages can be low-level like machine language or assembly, or high-level like procedural, problem-oriented, and natural languages. Translators like assemblers, compilers, and interpreters are used to convert between language levels.

Uploaded by

Supreme Phuyal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
507 views

Unit 5 Programming Logic and Concept

This document discusses programming concepts and logics. It defines a program as a set of step-by-step instructions written in a programming language to perform a task. Programming involves writing code to perform specific tasks. Good programming languages are accurate, clear, simple, efficient, modular, general, robust, and secure. Languages can be low-level like machine language or assembly, or high-level like procedural, problem-oriented, and natural languages. Translators like assemblers, compilers, and interpreters are used to convert between language levels.

Uploaded by

Supreme Phuyal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Unit-5

Programming Concept and


Logics
• A specification of sequence of step by step
procedures in a particular programming language to
perform certain operation is called program.
• A program is a set of instructions for the computer
that tells it what to do. These instructions are
written in special programming languages that allow
people to communicate with or instruct the machine.
• The process of writing code for computer in order to
perform the specific task is called programming.
 Features of a good programming language
 Integrity: - The calculation used in the program should very
accurate.
 Clarity: - The program should be well readable to aid maintenance.
 Simplicity: - The program should be able to express the logic
in a considerably simple way.
 Efficiency: - The program should have a good compromise
between time and space used.
 Modularity: - Program should be separated to different logical
and self-contained modules.
 Generality: - The program should be as general as possible
within certain limits.
 Robustness: - Program must be fault-tolerant as much as possible.
 Security: - a program must be secured enough so as to avoid
tampering from unwanted people.
Programming
Language

Low level High level


language language

(4GL)
(3GL) Procedural (5GL) Natural
Machine level Assembly level Problem oriented
Language language
language
Low-Level Languages
Low-level computer languages are machine dependent language. The
language designed for one computer is not suitable for other computer.
These languages are not portable. There are two types of low-level
languages:
1. Machine Language:
2. Assembly Language:
• Machine language:
• Machine language is the lowest and most elementary level of
programming language and was the first type of programming language
to be developed. Machine language is basically the only language that a
computer can understand.
• The lowest level of programming language in which information is
represented as strings of 0s and 1s (binary digits or bits) is called
machine language.
• Every CPU has its own unique machine language.
Advantage Machine Language: Disadvantages Machine Language:
1. The only advantage is that 1. It is very difficult to program in
program of machine language run machine language. The
very fast because no translation programmer has to know details
program is required for the CPU. of hardware to write program.
2. It is directly understood by 2. It is difficult to debug the
the computer. program.
3. Machine language makes fast 3. Programs are not portable to
and efficient use of the computer. other computers.
4. It is machine dependent
Assembly Level Language: -
• The difficulties faced while writing a program in a machine language
led to the development of assembly language. It uses symbolic
notations to represent the instructions of the machine language. These
symbolic notations are called mnemonic codes. For example, ADD for
addition, SUB for subtraction etc.
• The program written in assembly language is called source program.
Source program translated into machine language by a translator
program is called object program. Computer viruses are mostly written
in Assembly language.
• Source Program=>Assembler=>Object Program
OP code Operand Comment
ADD A,B; Add B to A
Advantages of Assembly Level Language:
1) Simple to understand and use than machine language.
2) Easy to write programs.
3) Easier to debug programs than the programs of machine language.
Disadvantages of Assembly Level Language:
1) It is low level language so knowledge of hardware is required.
2) Programming is a lengthy and time consuming process in
assembly level languages.
High Level Languages(HLL):
• High-level computer languages use formats that are similar to English. The
purpose of developing high-level languages was to enable people to write
programs easily.
• High level languages are platform independent. They are portable.
• Example: FORTRAN (Formula Translation), BASIC (Beginners All-purpose
Symbolic Instruction Code),C,C++,JAVA,LISP,PROLOG,Python,etc.
• Procedural Oriented Language (3GL):
• General-purpose programming languages are called
procedural languages or third generation languages.
• They are languages such as Pascal, BASIC, COBOL, and
FORTRAN, which are designed to express the logic, the
procedure, of a problem.
• Because of their flexibility, procedural languages are able to
solve a variety of problems.
Advantages include: Disadvantages include:
1. The program statements are in 1. Program executes more slowly.
English and hence are easier to 2. They are mostly CUI based
work with. language.
2. Because of their English-like
nature, less time is required for
coding.
3. Programs are easier to
understand and modify.
4. The programming languages are
machine-independent.
Problem Oriented Language/Fourth Generation Language (4GL):
 Fourth generation language, also known as problem oriented language, are high level
language designed to solve specific problems or develop specific applications such as
database, web based application,etc.
 Fourth-generation languages may be categorized into several kinds of application
development tools:
• Personal computer application software
• Query languages and report generators
• Decision support systems and financial planning languages
• Application generators
 It is more user-friendly and enhances programming efficiently with usage of English like
words and phrases, use of icons, graphical interface, and symbolic representation.
 Dbase, PHP, JavaScript, ORACLE, etc. are the examples of 4GL
Advantages include: Disadvantages include:
1. Simplified the programming 1. Programs run slower than those
process. of earlier language because their
2. They possess friendly interface. machine code is longer and more
complicated to execute.
3. They are easier to use than
previously used high level 2. It requires more memory, disk
language. storage so more execution time
needed.
Natural Language (5GL):
Natural languages are still in development stages, but they promise to have
profound effect, particularly in the areas of artificial intelligence and expert
systems. Natural languages have two characteristics:
• They are designed to make the connections that humans have with
computers more naturals-more humanlike.
• They are designed to allow the computer to become “smarter”-to
actually simulate the learning process by remembering and improving
upon earlier information.
Two popular natural languages are LISP and PROLOG.
• Advantages include: • Disadvantages include:
• 1. It answers questions when • 1. It doesn’t recognize
given a human question. homonyms. E.g. RAM, Keyboard,
• 2. Language processing is Mouse
focused on developing efficient • 2. May require more
algorithm to process task. keystrokes
• 3. Relieves burden of learning • 3. May not show context
syntax
• Language Translator
• A language translator is a special type of
computer software that has the capacity of
translating the source code or program codes
into machine codes.
• It translate high level and assembly level
language into machine level language.
Assembler:
An assembler is language translator that converts programs written in
assembly language (source code) into machine language (object
code).The resulting program can be executed only when assembly
process is completed.
Source
Code

Assembler

Object Error
Code message
Compiler:
A compiler is software that converts programs written in high level language
(source code) into machine code (object code), whole program at a time. The
machine language code is called the object code and high level language code is
called Source code. Some programming languages which use compiler are
COBOL, C, C++, FORTRAN, etc.

Source
Code

Compiler

Object Error
Code message
Interpreter:
An interpreter is software that converts programs written in high level
language to machine language code, one instruction at a time. If there is
any error in any line, it is reported to the user. The most frequently used
interpreted language is BASIC. It requires less memory.

Source
Code

interpreter

Object Error
Code message
SN Compiler Interpreter
1 It translates entire program into machineIt translates one statement of a program at a time into
language at once. machine language.

2 Syntax errors are not known untilSyntax errors are known at each line, while writing the
compilation is at the end. program.

3 It is larger than interpreter. It is smaller than compiler.


4 Debugging process is complex in compiler. Debugging process is easier in interpreter.

5 Compiler generates executable code. Interpreter does not generate executable code, each
statement is interpreted and then only executed.

6 It is appropriate for developing heavyIt is appropriate for developing light weight and small
weight and large application. application.

7 Example: C, C++, Pascal, FORTAN, etc. Examples: QBASIC, GWBASIC, PERL, etc.
Program Software

1. A collection of instructions that 1. A set of instruction given to the


performs certain tasks and is written in computer in machine code that tells to
the form of computer language is the computer what to do and how to
called Program. perform the given task of the user is
called Software.

2. The main objective of program is to 2. The main objective of software is to


make software for general or specific enhance the performance capability of
purpose. hardware.

3. Examples: - Finding total, 3. Examples:- Windows XP, MS-


percentage, division and result of Excel, MS-Access etc.
students in college.
Programming Error
• If any program contains any mistake due to violation
rules of programming language then it is said to be errors
or bugs.
• The process of findings bugs is called debugging.
• Mainly there are three types of errors in program: syntax
Errors, Logical (Semantics) Errors and run-time error.
•• Syntax Error: -
• A syntax error is occurred due to the violation of syntax of a
programming language.
• The key words and the structure of the instructions must be
in correct form.
• A syntax error is very easy to debug because compiler itself
detects syntax error and also describes the causes of the
errors.
• So a programmer does not need to trace errors.
• For Example : if we write the spelling for printf is written
pritf , this is a syntax error in C programming.
Logical Error (Semantics error): -
• A logical error is occurred due to the violation of semantics of a
programming language.
• It is also called semantics errors.
• A compiler does not detect the logical errors therefore they are very
difficult to find out.
• The actual output does not come as per the given data therefore; sample
data are supplied to the program to examine the logic errors.
• For example: if we decide to find the rank of student in a test according
to their percentages and if two students obtained the same percentage (%)
then , there may program get confused and occur a logical error.
Run-time Error:
• A run time errors occur during the running time of the
software.
• This kind of error is occurred due to the problem of system
or mishandling of the software.
• Anytime run time error might be occurred so a good
programmer has to handle the errors using different error
handling mechanism during software development time.
• For example: Crashing of a program during working on that
software is a run time error.
Program design tools:
Algorithm, Flow chart and Pseudo Code
• Planning is the process of finding the steps to solve a
problem.
• It is very important to solve any problem through computer.
• A planning indicates the direction of flow of the process,
accurate calculations, points of decisions and other
information in the program.
• There are three tools of planning to solve problems.
• They are:
a)Algorithm: Algorithm can be defined as a sequence of
instructions designed in a manner that, if the instructions are
executes in the specified sequence, the desired results will be
obtained.
Importance / Characteristics of a good algorithm:

Each and every instruction should be precise and unambiguous.


Each instruction should be performed in a finite time.
One or more instructions should not be repeated infinitely.
After performing the instruction i.e. after the algorithm terminates, the
desired result must be obtained.
Q.N. 1) Write an algorithm to read two numbers M and N, add
them and print the result.
Solution: To solve the questions
Step 1: Start
Step 2: Read values of two numbers M and N
Step 3: Add M and N
Step 4: Print the sum of M and N
Step 5: Stop
b) Flow chart:
A flow chart is the diagrammatic or pictorial representation of procedure proposed to solve
problem.
Since it charts flow of program, that’s why it is called flow chart.
• # Rules for developing Flow chart:
• The flow of direction flows from top to bottom or left
to right.
• All the flow lines must use arrow heads to indicate the
flow.
• Only one flow line should enter a processing symbol,
decision symbol and a terminal symbol.
• Flow line should not cross each other.
• When drawing flowchart from one page to another the
connector symbol should be correctly reformed.
c)Pseudo code:
Pseudo-code is a kind of algorithm in which the instructions
are expressed in a more English like structure and
mathematical expressions. The instructions of pseudo code
are similar to the program instructions.
Example of a Pseudo code:
# Pseudo code to calculate sum of M and N
Start
Input M and N
Sum=M+N
Output Sum
Stop
Code:
In programming, code (noun) is a term used for both the statements
written in a particular programming language - the source code, and
a term for the source code after it has been processed by a compiler
and made ready to run in the computer - the object code.
To code (verb) is to write programming statements - that is, to write
the source code for a program. Code is often used generally to mean
any kind of concealed writing, including ciphers. "Breaking the
code" usually means the discovery of a way to read one or a series
of encrypted messages without being given the key to decrypt them.
Absolute Binary:
It uses two digits -0 and 1 to represent binary number. Data is represented
in a computer system by either the presence or absence of electronic or
magnetic signals in its circuitry or the media it uses. This is called binary
or two state representations of data since the computer is indicating only
the two possible states or conditions. In absolute binary 0 is to represent
+ve number and 1 is used to represent –ve number. It uses 8 bits, 16 bits,
32 bits or 64 bits format.
For example: +16 for absolute binary=00010000
-16 for absolute binary=10010000
Binary Coded Decimal (BCD):
Short for Binary Coded Decimal, BCD is also known as packet decimal and is
numbers 0 through 9 converted to four-digit binary. A binary-coded decimal (BCD)
is a type of binary representation for decimal values where each digit is represented
by a fixed number of binary bits, usually between four bits. Binary-coded decimals
are an easy way to represent decimal values, as each digit is represented by its own
4-bit binary sequence which only has 10 different combinations.
For example, the binary coded decimal "1001 0101 0110," which has three groups
of
4 bits, means there are three decimal digits. In order, from left to right, the resulting
decimal value is 956.i.e. each decimal digit is represented by 4-bits binary number.
The following are the 4-bit binary representation of decimal values:
Digits Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
ASCII (American Standard Code for Information Interchange)
It is the most common format for text files in computers and on the Internet.
In an ASCII file, each alphabetic, numeric, or special character is
represented with a 7-bit binary number (a string of seven 0s or 1s). i.e.
27=128 possible characters are defined.
ASCII was developed by the American National Standards Institute (ANSI).
ASCII is a code for representing English characters as numbers, with each
letter assigned a number from 0 to 127. For example, the ASCII code for
uppercase M is 77. Most computers use ASCII codes to represent text, which
makes it possible to transfer data from one computer to another.
ASCII Character ASCII Character

32 Blank 65 A

33 ! 66 B

34 “ 90 Z

48 0 97 a

49 1 98 b

127 DEL 122 z


Unicode:
A standard for representing characters as integers. Unlike ASCII, which uses 7
bits for each character, Unicode uses 16 bits, which means that it can represent
more than 65,000 unique characters. This is a bit of overkill for English and
Western-European languages, but it is necessary for some other languages, such
as Greek, Chinese and Japanese. Many analysts believe that as the software
industry becomes increasingly global, Unicode will eventually supplant ASCII
as the standard character coding format.
Unicode is an entirely new idea in setting up binary codes for text or script
characters. Officially called the Unicode Worldwide Character Standard, it is a
system for "the interchange, processing, and display of the written texts of the
diverse languages of the modern world." It also supports many classical and
historical texts in a number of languages.

You might also like