You are on page 1of 18

CS112 - PROGRAMMING FUNDAMENTAL

Lecture # 02 - Program design methodology


Syed Shahrooz Shamim
Junior Lecturer,
CS Department, UIT
What is Program?
A computer program is a collection of instructions
that performs a specific task when executed by
a computer. A computer requires programs to
function, and typically executes
the program's instructions in a central processing
unit.
What is Programming?
“Computer programming (often shortened
to programming) is a process that leads from an
original formulation of a computing problem to
executable computer programs.”
Programming Language Concepts
• What is a programming language?
• Why are there so many programming languages?
• What are the types of programming languages?
• Does the world need new languages?
What is a Programming Languages
• A programming language is a set of rules that
provides a way of telling a computer what
operations to perform.
• A programming language is a set of rules for
communicating an algorithm
• It provides a linguistic framework for describing
computations
What is a Programming Languages
A programming language is a notational system for
describing computation in a machine-readable and
human-readable form.

A programming language is a tool for developing


executable models for a class of problem domains.
What is a Programming Languages
• English is a natural language. It has words, symbols
and grammatical rules.
• A programming language also has words, symbols
and rules of grammar.
• The grammatical rules are called syntax.
• Each programming language has a different set of
syntax rules.
Why Are There So Many Programming Languages

• Why does some people speak French?


• Programming languages have evolved over
time as better ways have been developed to
design them.
– First programming languages were developed in
the 1950s
– Since then thousands of languages have been
developed
• Different programming languages are
designed for different types of programs.
Levels of Programming Languages
class Triangle {
...
float surface()
High-level program return b*h/2;
}

LOAD r1,b
LOAD r2,h
Low-level program MUL r1,r2
DIV r1,#2
RET

0001001001000101001
Executable Machine code 0010011101100101011
01001...
Programming Language Translator
• Assembler
• Interpreter
• Compiler
Program design methodology
• Procedural driven design
• Event-driven design
• Data driven design
Procedural Driven Design
• Procedural programming is the standard approach used in
traditional computer language such as C, Pascal,
FORTRAN & BASIC.

• The basic idea is to have a program specify the sequence of


steps that implements a particular algorithm .

• Procedural programming is a term used to denote the way in


which a computer programmer writes a program.

• This method of developing software, which also is called an


application, revolves around keeping code as concise as
possible. It also focuses on a very specific end result to be
achieved.
Procedural Driven Design
• Procedural programming creates a step by step program that
guides the application through a sequence of instructions. Each
instruction is executed in order.

• Procedural programming focuses on processes. In procedural


programming data and functions are stored in separate
memory location, while in OOP data and functions are stored
in same memory location.

• Programs are made up of modules, which are parts of a


program that can be coded and tested separately, and then
assembled to form a complete program.
Procedural Driven Design
• In procedural languages (i.e. C) these modules are procedures,
where a procedure is a sequence of statements.

• In C for example, procedures are a sequence of imperative


statements, such as assignments, tests, loops and invocations
of sub procedures. These procedures are functions, which map
arguments to return statements.
Procedural Driven Design
• The design method used in procedural programming is called Top
Down Design.
• This is where you start with a problem (procedure) and then
systematically break the problem down into sub problems (sub
procedures).
• This is called functional decomposition, which continues until a sub
problem is straightforward enough to be solved by the corresponding
sub procedure.
• When changes are made to the main procedure (top), those changes
can cascade to the sub procedures of main, and the sub-sub
procedures and so on, where the change may impact all procedures in
the pyramid.
• The problem with PP approach is its handling of data. PP approach
gives no importance to data. By ‘data’ we mean the information
collected from user, the new results obtained after calculations etc.
Procedural Driven Design
• In C, a data member must be declared GLOBAL in order to make it
accessible by 2 or more functions in the program.
• What happens when 2 or more functions work on the same data
member ?
• If there are 10 functions in a program, all these 10 functions can
access a global data member. It is possible one function may
accidentally change values of this global data member.
• If this data member is a key element of the program, any such
accidental manipulation will affect the whole program. It will be too
difficult to debug & identify which function is causing the problem if
the program is really big.
Fibonacci series program in c using recursion
#include<stdio.h>
int Fibonacci(int);
main()
{
int n, i = 0, c;
printf("Enter the number of terms\n");
scanf("%d",&n);
printf("Fibonacci series\n");
for ( c = 1 ; c <= n ; c++ )
{
printf("%d\n", Fibonacci(i));
i++;
}
return 0;
}
Fibonacci series program in c using recursion

int Fibonacci(int n)
{ if ( n == 0 )
return 0;
else
if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) +Fibonacci(n-2));
}

You might also like