CSE101-Lec#2: Programming Methodologies
CSE101-Lec#2: Programming Methodologies
CSE101-Lec#2: Programming Methodologies
Programming Methodologies
Created By:
Amanpreet Kaur &
Sanjeev Kumar
SME (CSE) LPU
Outline
• Key software and hardware trends
• Procedural and Object Oriented Programming
• Program Development in C
• Structured programming (Algorithm and
Pseudo code)
Procedural Programming
• Involves procedures which are sequence of
statements
• The design method used in procedural programming
is called Top Down Design. This is where you start
with a problem and then systematically break the
problem down into sub problems.
• Traditional programming languages were procedural.
–C, Pascal, COBOL , etc
Problems with Procedural
programming language
• Software maintenance can be difficult
• Time consuming
• When changes are made to the main
procedure, those changes can cascade to sub
procedures of main, and sub-sub procedures
and so on..
Object-Oriented Programming
• Object-oriented programming is centered on
creating classes and objects rather than
procedures/ functions
• Class is a combination of state (data) and
behavior (methods)
• Data in an object are known as attributes
• Class is a data type and object is an instance
of that data type
• Examples- C++, Java,…
Principles of OOP
1. Object-oriented programming combines data
and behavior (or method). This is called
encapsulation.
2. Data hiding is the ability of an object to hide
data from other objects in the program.
3. Inheritance is the ability to inherit attributes
and behavior from existing classes (base
class)
Benefits of Object-oriented
programming
• Modularity
• Information hiding
• Code re-use
Save development time (and cost) by reusing code
– once an object class is created it can be used
in other applications
• Easy debugging
– classes can be tested independently
– reused objects have already been tested
Procedure oriented programming Object oriented programming
Program is divided into small parts called Program is divided into number of entities
functions called objects.
In Procedural programming, Data can In OOP, objects can move and
move freely from function to function in communicate with each other through
the system. member functions.
Procedural programming follows Top OOP follows Bottom Up approach
Down approach.
To add new data and function in OOP provides an easy way to add new data
Procedural programming is not so easy. and function.
Procedural programming does not have OOP provides Data Hiding so provides
any proper way for hiding data so it is less more security.
secure.
There is no concept of reusability Reusability concept is introduced here
Example of Procedural programming are : Example of OOP are : C++, JAVA, VB.NET,
C, VB, FORTRAN, Pascal. C#.NET.
C Program Development Environment
A C program must go through various phases such as:
Creating a program with editor
Compilation
Linking
Loading
Executing
Program is created in
Editor Disk the editor and stored
on disk.
Preprocessor program
Preprocessor Disk processes the code.
Compiler creates
Compiler Disk object code and stores
it on disk.
Linker links the object
Linker Disk code with the libraries,
creates a.out and
Primary Memory stores it on disk
Loader
Loader loads the program from disk to
main memory.
Disk ..
..
..
Primary Memory
Phase 6: CPU executes the Phase 5: A loader loads Phase 4: A linker links
program one instruction at the executable image the object code with the
a time. The load process in into memory (RAM). code in library or other
Windows OS is just input places to produce an
the name of the executable image.
executable file.
Program Development Tools
• Algorithm
• Flow chart
• Pseudo-code
Algorithm
• Algorithm is defined as “ the finite set of
steps, which provide a chain of action for
solving a problem”
• It is step by step solution to given problem.
• Well organized, pre-arranged and defined
textual computational module
Characteristics of good Algorithm
1. Correctness - terminates on ALL inputs (even invalid inputs!) and
outputs the correct answer.
2. Simplicity - each step of the algorithm performs one logical step in
solving the problem.
3. Precision - each step of the algorithm is unambiguous in meaning.
4. Comprehensibility - the algorithm is easy to read and understand.
5. Abstraction - presents the solution steps precisely and concisely
without referring to low-level (program code) details.
6. Efficient - Gives results rapidly based on the problem size; does
not waste any space or time.
7. Easy to Implement - relatively easy to translate into a
programming language.
Steps to create an Algorithm
1. Identify the Inputs
• What data do I need?
• How will I get the data?
• In what format will the data be?
• Step1. Start.
• Step2. Take the two numbers.
• Step3. Add them.
• Step4. Print the result.
• Step5. Stop.
Pseudo-Code
• Pseudo code is similar to everyday English language, its
convenient and user friendly
• It not a actual computer programming language.
• Pseudo code consist only of action statements
• In pseudo code representation
– Each of steps will be written via operators and statements
equivalent to some programming language instructions.
– The only difference will be that the exact syntax of the
programming language will not be followed.
– All pseudo codes will start with the keyword “START” and
complete with the keyword “STOP” or “END”.
Pseudo code: Add 2 Numbers
• Set A = 4.
• Set B = 2.
• Calculate Sum = A + B.
• Print Sum.
Flow Chart
• Flow Chart is pictorial representation of an
algorithm.
• Whatever we have done in algorithm we can
represent it in picture.
• It is easy to understand.
• Shows the flow of the instruction
Flow Chart Symbols
Flow Chart: Add 2 Numbers
START
TAKE TWO
NUMBERS A and B
FIND SUM=A+B
PRINT SUM
STOP
Program in C: Add 2 Numbers
#include<stdio.h>
void main()
{
int a = 4;
int b = 2;
int sum;
sum=a+b;
printf(“Sum is: %d”, sum);
}
Sum is : 6
Next Class: Components of C
identifier and keywords
Data Type
cse101@lpu.co.in