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

Unit No 4(Computer Programming Theory)

The document provides an overview of programming paradigms, detailing various types such as imperative, procedural, object-oriented, declarative, functional, data-driven, logic, event-driven, and aspect-oriented programming. It also outlines the programming process, including steps like problem analysis, algorithm design, coding, debugging, and testing, as well as the significance of algorithms and flowcharts in programming. Additionally, it explains different number systems (decimal, binary, octal, hexadecimal) and conversion methods between them.

Uploaded by

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

Unit No 4(Computer Programming Theory)

The document provides an overview of programming paradigms, detailing various types such as imperative, procedural, object-oriented, declarative, functional, data-driven, logic, event-driven, and aspect-oriented programming. It also outlines the programming process, including steps like problem analysis, algorithm design, coding, debugging, and testing, as well as the significance of algorithms and flowcharts in programming. Additionally, it explains different number systems (decimal, binary, octal, hexadecimal) and conversion methods between them.

Uploaded by

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

Unit 4

Computer Languages

What is the Programming Paradigm?

A programming paradigm refers to the way or approach to classifying


programming languages based on their features, patterns, coding
styles, frameworks, etc., to solve a particular problem.

In simple terms, it can be defined as a way of thinking and structuring the


functionalities of a program. Most of the programming languages that are being
used by software developers these days support multiple programming
paradigms simultaneously.

Types of Programming Paradigms

Some of the popular types of programming paradigms are:

• Imperative

• Procedural

• Object-Oriented

• Declarative

• Functional

• Data-Driven

• Logic

• Event-driven

• Aspect-Oriented

1. Imperative

Also referred to as algorithmic programming, it is a paradigm that gives explicit


instructions to a computer on how to execute a task. It uses statements to
change a program’s state. In imperative programming, functions are coded
implicitly at each necessary level to resolve an issue.
Some of the popular imperative programming languages are C, C++, Java,
Python, etc. Also, imperative programming doesn’t use pre-coded models. Some
of its types are as follows:

2. Procedural

It is a type of imperative programming where a program is coded using one or


more functions or procedures. Procedural programming is derived from
structured programming that is based on the concept of procedures, also called
subroutines, routines, and functions.

These procedures contain a series of computational steps that need to be


performed. Major examples of procedural programming languages include
BASIC, FORTRAN, COBOL, C, etc.

3. Object-Oriented

The object-oriented programming paradigm is based on the ‘object’ concept.


These objects can consist of data and code rather than functions and logic.
Here, data is in field format and code in procedure form.

These procedures are attached to objects, allowing easier access and data field
modifications. Java, C++, C#, Python, Swift, Objective-C, Ruby, and PHP are a
few examples of object-oriented programming languages.

4. Declarative

It is a high-level programming paradigm that is the opposite of imperative


programming. In descriptive programming, programs specify the required
results, not the way to achieve them. The declarative paradigm is further
divided into functional, data-driven, and logical programming styles.

It expresses computation logic without describing its control flow. SQL, HTML,
CSS, XAML, YAML, Haskell, and XML, are some most commonly used
declarative programming languages.

5. Functional

It is a programming paradigm where programs are coded by applying and


composing functions. Here the computation is treated as a mathematical
function evaluation and developers evade changing mutable data and state.
Simply put, in functional programming, functions can be assigned to variables,
returned from other functions, and passed as arguments. Some examples are
Erlang, Haskell, Lisp, Scala, PureScript, Elixir, and more.

6. Data-Driven

In data-driven programming, the flow and behavior of a program are


determined by data instead of hard-coded instructions. Here data is used to
control the decision-making and logic of the program. A few examples of data-
driven programming languages are Hadoop, SQL, R, and Python.

7. Logic

The logic programming paradigm uses a set of rules and facts, to describe
constraints and relationships within a problem domain. Here rules are written
as logical clauses and follow a declarative approach. This programming
paradigm can be used to express knowledge without depending on the
implementation.

8. Event-driven

This paradigm focuses on designing software programs that are based on


events. In the event-driven paradigm, asynchronous actions’ emitters and
listeners are used. Here the entities communicate indirectly with each other by
sending messages through an intermediary.

Instead of following a sequential or linear execution pattern, the control flow of


the event-driven paradigm is determined by events and event handlers. Java
with JavaFX and SWING, Python with Tkinter and PkQt, Objective-C, Unity,
and more are some examples of event-driven programming languages in the
market.

9. Aspect-Oriented

The Aspect-Oriented Programming paradigm (AOP) expands upon traditional


programming paradigms like procedural programming, object-oriented
programming, and functional programming. It complements object-oriented
programming by separating software application concerns to enhance
modularization.

AOP is largely used to manage cross-cutting issues due to code duplication and
maintainability of the program in software systems. C++, .NET, Ruby, Spring
AOP, AspectJ, etc. are some popular examples of aspect-oriented programming
languages.

Programming process
Programming is an art, although we can learn and taught it, but the creativity
and problem solving skills are God gifted.

Steps Involved in Programming:


1. Analyzing the Problem
2. Algorithm design / Pseudo Code
3. Flowchart
4.Coding
4. Debugging
5. Testing
6. Final output
7. Documentation

1. Analyzing the Problem:

This is indeed the first Step to creating a program. And it involves getting
information about the program you are about to create. It is In this stage that
you determine what you want to achieve with your program, how you want to
achieve it, etc.

These informations are very important for the programmer because it provides
him the basis for planning about the program and to control the possible
difficulties that may arise.

2. Algorithm Design:

In this stage all the instructions which are to be performed at different stages
in the program are listed in simple English language. We may call it as a
strategy.

Let's takes a simple calculator program as an example. The algorithm will be.

• Receive user input.


• Perform calculation on input (addition, subtraction etc.).
• Print out result.

3. Flowchart:

After writing the algorithm (i.e steps involved in the program), the next stage is
to present All the steps in a diagrammatic manner so as to make it easily
understandable. So the flowchart is simply the algorithm made clearer.

4. Coding:

In this stage the programmer writes the instructions in a language understood


by the computer to solve the problem(s) drafted out in the previous stages. It's
obvious how, many programmers jump the initial stages and start writing
bunch of codes. Because all the processes of Coding depends upon the
information we obtained in the previous stages.
5. Debugging:

In this stage we correct all the errors in the program, because there is a great
probability of mistakes occurring when coding.

Here the program is executed manually, called DRY RUN. This is done several
times until all the errors are removed from the program and the system become
error free.

6. Testing:

This stage is similar to debugging except that In this stage we test the program
by entering dummy data (includes usual, unusual and invalid data) to check
how the behavior of the program when given such data.

7. Final Output:

After going through all the above stages, the program is given the TRUE DATA.
Here the programmer expects the positive results of the program and expects
full efficiency of the program.
Algorithm

Definition:

An algorithm is a procedure that describes a set of instructions that must be


carried out in a specific order to get the desired result. An algorithm may be
performed in multiple computer languages since algorithms are often designed
independently of the underlying languages. A few properties of an algorithm are
clarity, excellence, efficacy, and language independence. An algorithm's
performance and scalability are what determine how important it is.

Characteristics of an Algorithm

o An algorithm needs specific input values. A number other than 0 may be


provided as input to an algorithm.
o An algorithm will provide one or more outputs when it is finished.
o Unambiguity: An ideal algorithm has specific instructions, which implies
that they should be simple and obvious.
o Algorithms must be finite to function. In this context, "finiteness" refers to
the requirement that an algorithm has limited instructions or instructions
that can be counted.
o Effectiveness: An algorithm should be sufficient since each instruction
impacts the whole procedure.
o An algorithm must be language-independent, which implies that its
instructions must work the same no matter what language is used to
implement them.

Flowchart

What are Flowcharts?


Flowcharts are the visual representations of an algorithm or a process.
Flowcharts use symbols/shapes like arrows, rectangles, and diamonds to
properly explain the sequence of steps involved in the algorithm or process.
Flowcharts have their use cases in various fields such as software
development, business process modeling, and engineering.

Why use Flowcharts?

Flowcharts are used due to the numerous amount of benefits they provide.

Below are some of the important reasons to use flowcharts:

• They provide clarity and simplification to the complex processes and


algorithms, which in turn helps other people to understand them easily.
• Flowcharts provide a universal visual language that can be understood by
anyone across different teams and helps reduce miscommunications.
• They are an optimal solution for documenting standard operating
procedures, workflows, or business processes. This makes it easier to train
new employees.
• Flowcharts help in increasing the visualization of the problem being solved
which enables more informed and data-driven choices.

Symbols used in Flowchart Designs


1. Terminal/Terminator
The oval symbol indicates Start, Stop and Halt in a program’s logic flow. A
pause/halt is generally used in a program logic under some error conditions.
Terminal is the first and last symbols in the flowchart.
2. Input/Output
A parallelogram denotes any function of input/output type. Program
instructions that take input from input devices and display output on output
devices are indicated with parallelogram in a flowchart.

3. Action/Process
A box represents arithmetic instructions, specific action or operation that
occurs as a part of the process. All arithmetic processes such as adding,
subtracting, multiplication and division are indicated by action/process
symbol.

4. Decision
Diamond symbol represents a decision point. Decision based operations such
as yes/no question or true/false are indicated by diamond in flowchart.
5. On-Page Connector/Reference
Whenever flowchart becomes complex or it spreads over more than one page,
it is useful to use connectors to avoid any confusions. connectors are used to
indicate a jump from one part of the flowchart to another without drawing
long or complicated lines. On-Page Connector is represented by a small circle.

6. Off-Page Connector/Reference
Whenever flowchart becomes complex or it spreads over more than one page,
it is useful to use connectors to avoid any confusions. connectors are used to
indicate a jump from one part of the flowchart to another without drawing
long or complicated lines. Off-Page Connector is represented by a pentagon.

7. Flow lines
Flow lines indicate the exact sequence in which instructions are executed.
Arrows represent the direction of flow of control and relationship among
different symbols of flowchart.
Rules For Creating a Flowchart

A flowchart is a graphical representation of an algorithm. It should follow


some rules while creating a flowchart

• Rule 1: Flowchart opening statement must be ‘start’ keyword.


• Rule 2: Flowchart ending statement must be ‘end’ keyword.
• Rule 3: All symbols in the flowchart must be connected with an arrow line.
• Rule 4: Each decision point should have two or more distinct outcomes.
• Rule 5: Flow should generally move from top to bottom or left to right.

Difference Between Algorithm and Flowchart

Algorithm

• It is a procedure for solving problems.


• The process is shown in step-by-step instruction.
• It is complex and difficult to understand.
• It is convenient to debug errors.
• The solution is showcased in natural language.
• It is somewhat easier to solve complex problem.
• It costs more time to create an algorithm.

Flowchart

• It is a graphic representation of a process.


• The process is shown in block-by-block information diagram.
• It is intuitive and easy to understand.
• It is hard to debug errors.
• The solution is showcased in pictorial format.
• It is hard to solve complex problem.
• It costs less time to create a flowchart.
Examples on Algorithm and Flowchart
Data Representation
A number system, or numeral system, is a method for representing numbers
using symbols, crucial in mathematics and programming for data
representation. It involves using digits to construct numbers, where each digit’s
value is determined by its position and the base value of the system. While
computers primarily use the binary system of 0s and 1s, number systems are
broadly applied in various fields for calculations, measurements, and labeling,
among other uses. There are several types of number systems, each suited to
different applications.

Types of Number System

Now, there are various types of number systems that have their use cases. Let us discuss them
briefly.

Refer to the complete chart of number systems given below for a better understanding.
1. Decimal

The decimal number system or the base 10 number system uses 10 digits
ranging from 0 to 9 to represent any number. The first position from the
rightmost part of a decimal number is known as one’s place or unit’s place,
then the second position is known as ten’s place, and so on. Every decimal
number is represented by the power of base 10.

2. Binary

The binary number system or the base 2 number system uses only two digits i.e. 0 and 1 to
represent any number. For example, the decimal number 14 is represented as 1110 in the binary
number system. We need to keep dividing the decimal number by 2 until the quotient
becomes 0 and along with that, we need to remember the remainder. When the remainders
obtained in the division are represented in reverse order, a binary number is generated.

3. Octal

The octal number system or the base 8 number system uses 8 digits ranging
from 0 to 7 to represent any number. The octal number is very commonly used
the computer systems.

Every octal number is represented by the power of base 8.

4. Hexadecimal

The hexadecimal number system or the base 16 number system uses 16 digits
ranging from 0 to 9 (i.e. 10 digits) and A to F (i.e. 6 digits) to represent any
number. Refer to the chart shown below to know the representation of
hexadecimal numbers.
We can convert a decimal number into a hexadecimal number. We need to keep
dividing the decimal number by 16 until the remainder becomes 0 and along
with that, we need to remember the remainder. When the remainders obtained
in the division are represented in reverse order, the hexadecimal number is
generated.

Conversion between number System


Converting Decimal to Binary
• Step 1: Divide the decimal number by 2, the base for binary numbers.
• Step 2: Record the remainder; this becomes the least significant digit
(LSD) of the binary number.
• Step 3: Use the quotient as the new dividend and divide again by 2.
• Step 4: The new remainder becomes the next digit of the binary number,
positioned to the left of the previous digit.
• Repeat steps 3 and 4 until the quotient is 0. The last remainder obtained
is the most significant digit (MSD).

Example: Convert decimal 13 to binary.

1. 13 ÷ 2 = 6, remainder 1 (LSD)
2. 6 ÷ 2 = 3, remainder 0
3. 3 ÷ 2 = 1, remainder 1
4. 1 ÷ 2 = 0, remainder 1 (MSD)

• Binary equivalent: 1101

Converting Decimal to Octal:

• Step 1: Divide the decimal number by 8, the base for octal numbers.
• Step 2: The remainder becomes the least significant digit of the octal
number.
• Step 3: The quotient is used as the new dividend, divided again by 8.
• Step 4: The new remainder becomes the next octal digit, positioned to
the left of the previous digit.
• Continue until the quotient is 0. The final remainder is the most
significant digit.

Example: Convert decimal 95 to octal.

1. 95 ÷ 8 = 11, remainder 7 (LSD)


2. 11 ÷ 8 = 1, remainder 3
3. 1 ÷ 8 = 0, remainder 1 (MSD)

• Octal equivalent: 137

Converting Decimal to Hexadecimal:

• Step 1: Divide the decimal number by 16, the base for hexadecimal
numbers.
• Step 2: The remainder becomes the least significant digit of the
hexadecimal number. Use 0-9 for remainders 0-9 and A-F for remainders
10-15.
• Step 3: Use the quotient as the new dividend and divide by 16.
• Step 4: The new remainder becomes the next hexadecimal digit, to the
left of the previous one.
• Repeat steps until the quotient is 0, with the last remainder being the
most significant digit.

Example: Convert decimal 254 to hexadecimal.

1. 254 ÷ 16 = 15, remainder 14 (E, LSD)


2. 15 ÷ 16 = 0, remainder 15 (F, MSD)

• Hexadecimal equivalent: FE

Converting Binary to Decimal:

•Step 1: Starting from the right (least significant bit, LSB), multiply each
binary digit by 2 raised to its position number, counting from 0.
• Step 2: Sum up the results of these multiplications to get the decimal
equivalent.
Example: Convert binary 11101011 to decimal.

• Calculation: (1 * 2^7 + 1 * 2^6 + 1 * 2^5 + 0 * 2^4 + 1 * 2^3 + 0 * 2^2 + 1


* 2^1 + 1 * 2^0)
• Result: 128 + 64 + 32 + 0 + 8 + 0 + 2 + 1 = 235

• Decimal equivalent: 235

Converting Binary to Octal:

• Step 1: Group the binary digits into sets of three, starting from the right.
If necessary, pad the leftmost group with zeros to make it a trio.
• Step 2: Convert each trio into its octal equivalent, which will range from
0 to 7.

Example: Convert binary 11101011 to octal.

• Grouping: 1 110 101 011


• Converting each group: 1 is 1, 110 is 6, 101 is 5, 011 is 3

• Octal equivalent: 1653

Converting Binary to Hexadecimal:

• Step 1: Divide the binary number into groups of four, starting from the
right. Pad the leftmost group with zeros if it’s not already a quartet.
• Step 2: Convert each group into its hexadecimal equivalent, which will
be in the range 0-9 and A-F for 10-15.

Example: Convert binary 1110101101101 to hexadecimal.

• Grouping: 1110 1011 0110 1


• Converting each group: 1110 is E, 1011 is B, 0110 is 6, 0001 is 1 (after
padding)

• Hexadecimal equivalent: 1E6B

Converting Octal to Decimal:

• Step 1: Starting from the right (least significant digit, LSD), multiply
each octal digit by 8 raised to its position number, counting from 0.
• Step 2: Sum up these products to get the decimal equivalent.

Example: Convert octal 247 to decimal.

• Calculation: (2 * 8^2 + 4 * 8^1 + 7 * 8^0)


• Result: 128 + 32 + 7 = 167

• Decimal equivalent: 167

Converting Octal to Binary:

• Step 1: Write down each octal digit separately.


• Step 2: Convert each octal digit into a corresponding group of three
binary digits (bits).
• Step 3: Concatenate these binary groups to form the complete binary
number.

Example: Convert octal 247 to binary.

• Octal digits: 2, 4, 7
• Binary equivalents: 010 (for 2), 100 (for 4), 111 (for 7)

• Binary equivalent: 010100111

Converting Octal to Hexadecimal:

• Step 1: Convert the octal number to binary by following the steps for
octal to binary conversion.
• Step 2: Group the binary digits into sets of four, starting from the right.
If necessary, pad the leftmost group with zeros to make it a quartet.
• Step 3: Convert each binary group into its hexadecimal equivalent, using
0-9 for values 0-9 and A-F for values 10-15.

Example: Convert octal 5456 to hexadecimal.

1. Convert to binary: 5456 octal = 101 100 101 110 binary


2. Group into fours: 0101 1001 0111
3. Convert each group: 0101 is 5, 1001 is 9, 0111 is 7

• Hexadecimal equivalent: 597

Converting Hexadecimal to Decimal:

• Step 1: Understand the decimal values of hexadecimal symbols. For


digits 0-9, the values are the same, and for letters A-F, they represent
10-15 respectively.
• Step 2: Multiply each digit of the hexadecimal number by 16 raised to its
position number, starting from the right (LSB to MSB).
• Step 3: Sum up all the results from step 2 to get the decimal equivalent.
Example: Convert hexadecimal 8EB4 to decimal.

• Calculation: (8 * 16^3 + 14 * 16^2 + 11 * 16^1 + 4 * 16^0)

• Result: 36532
• Decimal equivalent: 36532

Converting Hexadecimal to Binary:

• Step 1: Convert each hexadecimal digit to its decimal equivalent.


• Step 2: Convert each decimal digit to a 4-bit binary group.
• Step 3: Concatenate all the 4-bit groups to get the full binary number.

Example: Convert hexadecimal B2E to binary.

• Decimal equivalents: B=11, 2=2, E=14


• Binary conversions: B=1011, 2=0010, E=1110

• Binary equivalent: 101100101110

Converting Hexadecimal to Octal:

• Step 1: Convert the hexadecimal number to binary by following the steps


in the Hexadecimal to Binary conversion.
• Step 2: Group the binary digits into sets of three, starting from the right.
If necessary, pad the leftmost group with zeros.
• Step 3: Convert each binary group to its octal equivalent.
• Step 4: Concatenate these octal digits to get the octal equivalent.

Example: Convert hexadecimal B2E to octal.

• First, convert B2E to binary: 101100101110


• Group into threes: 010 110 010 111
• Convert to octal: 2=010, 6=110, 2=010, 7=111

• Octal equivalent: 2627

You might also like