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

Unit 2

Structured programming is a programming paradigm that divides a program into smaller, modular components or functions to improve design, debugging, and maintenance of code. It allows programmers to break down problems into smaller, separate, and more manageable parts. Some key aspects of structured programming include dividing code into modules or functions, using selection statements like if/else, and iteration statements like for loops. Object-oriented programming is another paradigm that defines programs as objects that contain both data and functions to operate on that data.

Uploaded by

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

Unit 2

Structured programming is a programming paradigm that divides a program into smaller, modular components or functions to improve design, debugging, and maintenance of code. It allows programmers to break down problems into smaller, separate, and more manageable parts. Some key aspects of structured programming include dividing code into modules or functions, using selection statements like if/else, and iteration statements like for loops. Object-oriented programming is another paradigm that defines programs as objects that contain both data and functions to operate on that data.

Uploaded by

Ken 07
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

UNIT 2: PROGRAMMING

PARADIGMS
What is a computer program
• A computer program is a set of instructions for a computer to perform a task which is
written using a programming language. A programming paradigm can categorize the
programming language depending on language features.

• Types of Programming Paradigm

• Structured programming and Unstructured programming are two common programming


paradigms. The key difference between Structured and Unstructured programming is that
• Structured programming allows the programmer to divide the whole program into modules
or functions and in
• Unstructured programming, the code is written as one block.
What is structured programming
• In Structured Programming, is a type of programming that generally converts large or complex
programs into more manageable and small pieces of code.

• The code is divided into functions or modules. It is also known as modular programming. Modules
or functions are a set of statements which performs a sub task.

• As each task is a separate module, it is easy for the programmer to test and debug. It is also easy to
do modifications without changing the whole program.

• When changing the code, the programmer has to concentrate only on the specific module.

• C language and Pascal are some examples of Structural Programming languages.


A programming
language like C can use
user-defined functions.
Functions are called by
the main program.
Variables in the
functions are called
local variables, and
global variables can be
accessed by all the
functions. Structured
programming languages
also use selections (if/
else) and iterations
(for /do, while).
Types of structured programming
• There are three categories of structured programming:

• Procedural programming. Defines modules as procedures or functions that are called with a set of
parameters to perform a task. A procedural language begins a process, which is then given data.

• Object-oriented programming (OOP). Defines a program as a set of objects or resources to which


commands are sent. An object-oriented language defines a data resource and sends it to process
commands.

• Model-based programming. The most common example of this is database query languages. In
database programming, units of code are associated with steps in database access and update or run
when those steps occur.
What is unstructured programming
• Unstructured Programming is a type of programming that generally executes in sequential
order i.e., these programs just not jumped from any line of code and each line gets executed
sequentially.

• It is also known as non-structured programming that is capable of creating turning-complete


algorithms.

• In Unstructured Programming, the code is written as a single whole block. The whole program is
taken as a single unit. It is harder to do changes in the program.

• This paradigm was used in earlier versions of BASIC, COBOL, and FORTRAN. Unstructured
programming languages have a limited number of data types like numbers, arrays, strings.
Output :
Addition = 15
Subtraction = 5
Difference between structured and unstructured
programming
Object Oriented Programming
• Object-Oriented Programming or OOPs refers to languages that use objects
in programming. Object-oriented programming aims to implement real-
world entities like inheritance, hiding, polymorphism, etc in programming.

• The main aim of OOP is to bind together the data and the functions that
operate on them so that no other part of the code can access this data except
that function.
• OOPs Concepts:
• Class
• Objects
• Data Abstraction
• Encapsulation
• Inheritance
• Polymorphism
Class
• A class is a user-defined data type. It consists of data members and member
functions, which can be accessed and used by creating an instance of that
class.
• It represents the set of properties or methods that are common to all objects
of one type. A class is like a blueprint for an object.
• For Example: Consider the Class of Cars. There may be many cars with
different names and brands but all of them will share some common
properties like all of them will have 4 wheels, Speed Limit, Mileage range,
etc. So here, Car is the class, and wheels, speed limits, mileage are their
properties.
Object
• It is a basic unit of Object-Oriented Programming and represents the real-life entities. An
Object is an instance of a Class. When a class is defined, no memory is allocated but when it is
instantiated (i.e. an object is created) memory is allocated.

• An object has an identity, state, and behavior. Each object contains data and code to manipulate
the data. Objects can interact without having to know details of each other’s data or code, it is
sufficient to know the type of message accepted and type of response returned by the objects.

• For example “Dog” is a real-life Object, which has some characteristics like color, Breed,
Bark, Sleep, and Eats.
Data Abstraction
• Data abstraction is one of the most essential and important features of object-oriented
programming. Data abstraction refers to providing only essential information about the
data to the outside world, hiding the background details or implementation.

• Consider a real-life example of a man driving a car. The man only knows that pressing
the accelerators will increase the speed of the car or applying brakes will stop the car, but
he does not know about how on pressing the accelerator the speed is increasing, he does
not know about the inner mechanism of the car or the implementation of the accelerator,
brakes, etc in the car. This is what abstraction is.
Encapsulation

• Encapsulation is defined as the wrapping up of data under a single unit. It is


the mechanism that binds together code and the data it manipulates.
• In Encapsulation, the variables or data of a class are hidden from any other
class and can be accessed only through any member function of their class in
which they are declared.
• Encapsulation is a method for protecting data from unwanted access or
alteration by packaging it in an object where it is only accessible through the
object's interface. Encapsulation are often referred to as information hiding.
• As in encapsulation, the data in a class is hidden from other classes, so it is
also known as data-hiding.
Inheritance
• Inheritance is an important pillar of OOP(Object-Oriented Programming). The capability of a class
to derive properties and characteristics from another class is called Inheritance. When we write a
class, we inherit properties from other classes.

• So when we create a class, we do not need to write all the properties and functions again and
again, as these can be inherited from another class that possesses it. Inheritance allows the user to
reuse the code whenever possible and reduce its redundancy.
Polymorphism
• The word polymorphism means having many forms. In simple words, we
can define polymorphism as the ability of a message to be displayed in more
than one form.
• For example, A person at the same time can have different characteristics.
Like a man at the same time is a father, a husband, an employee. So the same
person posses different behavior in different situations. This is called
polymorphism.
Characteristics of good computer program
 A good programming language must be simple and easy to learn and use.
Characteristics:

 Portability: application to run on different platforms (operating systems)

 Readability: More user-friendly approach. The program should be written in such a way that it makes other programmers or

users to follow the logic of the program without much effort.

 Efficiency: Every program requires certain processing time and memory to process the instructions and data. As the processing

power and memory are the most precious resources of a computer, a program should be laid out in such a manner that it utilizes

the least amount of memory and processing time.

 Structural: To develop a program, the task must be broken down into a number of subtasks.

 Flexibility: A program should be flexible enough to handle most of the changes without having to rewrite the entire program.

Most of the programs are developed for a certain period and they require modifications from time to time.
 For example, in case of payroll management, as the time progresses, some employees may leave the company while some others may

join. Hence, the payroll application should be flexible enough to incorporate all the changes without having to reconstruct the entire

application.
 Generality: Apart from flexibility, the program should also be general. Generality means that if a program

is developed for a particular task, then it should also be used for all similar tasks of the same domain. For

example, if a program is developed for a particular organization, then it should suit all the other similar

organizations.

 Documentation: Documentation is one of the most important components of an application development.

Even if a program is developed following the best programming practices, it will be rendered useless if the

end user is not able to fully utilize the functionality of the application. A well-documented application is

also useful for other programmers because even in the absence of the author, they can understand it.

 Compactness :- In a good programming language, programmers should be able to express intended

operations concisely. A verbose language is generally not liked by programmers, because they need to

write too much.

You might also like