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

Lect 1

This document describes a Programming Logic Design course. The course objectives are to understand programming methodologies like flowcharts and algorithms, program development steps, and structured programming. The course outcomes include demonstrating an understanding of software development, applying structured programming concepts, and identifying different programming paradigms and constructs. The teaching scheme includes theory lectures, assignments, mid-semester exams, and an end-semester exam. The document also covers understanding computer systems, the problem solving process, types of problems, program logic, and the program development cycle. Pseudocode and flowcharts are discussed as tools for planning programs.

Uploaded by

nchoudhari873
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Lect 1

This document describes a Programming Logic Design course. The course objectives are to understand programming methodologies like flowcharts and algorithms, program development steps, and structured programming. The course outcomes include demonstrating an understanding of software development, applying structured programming concepts, and identifying different programming paradigms and constructs. The teaching scheme includes theory lectures, assignments, mid-semester exams, and an end-semester exam. The document also covers understanding computer systems, the problem solving process, types of problems, program logic, and the program development cycle. Pseudocode and flowcharts are discussed as tools for planning programs.

Uploaded by

nchoudhari873
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 46

Subject: Programming Logic Design

Subject Code: 20 UCS304D

Teaching Scheme : Theory 2 Hrs/week

Credit: 02

Examination scheme: CA1 – 10 Marks


MSE 20 Marks
CA2 10 Marks
ESE 60 Marks

Subject In charge : Mrs. Anuja R. Tungar ( ME CSE), CSE Department


Subject: Programming Logic Design

Course Objectives:

• To understand importance of Flowcharts and algorithms in program development

• To understand the various steps in program development.

• To learn the usage of structured programming approach in solving problems.

• To understated and formulate algorithm for programming script

• To Understand various programming paradigms


Subject: Programming Logic Design

Course Outcomes

• CO1 : Demonstrate a fundamental understanding of software development methodologies,


including modular design, pseudo code, flowcharting and structure charts
• CO2 : Apply concepts of structured program design such as modularity, sequence, selection, and
repetition for given problem statement
• CO3 Identify and apply different programming constructs to solve problems using procedural
programming
• CO4 Choose different structures of logic programming to build simple applications
• CO5 Develop simple applications using functional programming
• CO6 Apply different concept of object-oriented programming to simple real time problems

Perquisite : Nil
Understanding the Computer System

Computer systems

Software Hardware

System Application
Software Software
Understanding the Computer System

Hardware and software together perform following tasks:


• Input
• Output
• Processing
Some Basic terms:
• Programming Language
• Program code
• Coding the program
• Syntax
• Semantics
• Syntax errors
• Logical errors
• Semantic errors
• RAM/ ROM
• Volatile and Non volatile memory
Understanding the Computer System
• Source Code
• Object Code
• Executable code
• High Level Language (HLL)
• Low Level Language (LLL)/ Machine Language/ Binary Language
• Middle Level Language (MLL)
• Compiler
• Interpreter
• Assembler

Source Code (HLL) Compiler/ Interpreter Object Code (LLL)

Assembly Language
Assembler Object Code (LLL)
Code (HLL)
Understanding the Computer System
problem Solving

6 Steps to solve any problem:


1. Identify the problem.
2. Understand the problem: understand what is involved in the problem.
3. Identify alternative ways to solve the problem
4. Select the best way to solve the problem from the list of alternative solutions: Decide
criterion(Rubrics) for selecting or rejecting the alternatives
5. List instructions to solve the problem using the selected solution: numbered, step-by-step
instructions
6. Evaluate the solution: check its result to see if it is correct, and to see if it satisfies the needs

If any of these six steps are not completed well, the results may be less than desired.
Types of problems

1. Algorithmic problems: The problems that can be solved using step-by-step approach
• Writing a program
• Making a balance sheet
2. Heuristic problems: Solutions that cannot be reached through a direct set of steps
• Expand business of an organization
• Share market

Step #6 will be different in the two types of problems


Algorithmic problems: Correctness and appropriate is certain
Heuristic problems : 6 steps may be required to execute more than once to get appropriate
answers
Understanding the Program Logic

• Program is a sequence of instructions


• Importance of sequencing
• Every program has : Input(Optional), processing, and output.
• Importance and significance of variable names: I am buying Potato for Parathas
• Memory and its numeric address
Understanding the Program Development Cycle

1. Understand the problem.


2. Plan the logic.
3. Code the program.
4. Use software (a compiler or interpreter) to translate the program into machine language.
5. Test the program.
6. Put the program into production.
7. Maintain the program.
Understanding the Program Development Cycle

1. Understand the problem.


1. Programmers are providing a service to these users so programmers must first understand
what the users want
2. Think of the output first
3. After you understand what the desired result is, you can plan the input and processing steps
to achieve it.
4. Documentation: eg original requests for the program from users, sample output, and
descriptions of the data items available for input.
Understanding the Program Development Cycle

1. .
2. Plan the logic.
1. Success of any program depends on this step
2. Plan of what steps to include and how to order them
3. Flowcharts and pseudocode
4. No concern for syntax of any language
5. Figuring out what sequence of events will lead from the available input to the desired output.
6. Process of walking through a program’s logic on paper (Hand Run)
Understanding the Program Development Cycle

1. .
2. .
3. Code the program.
1. Write the source code for a program
2. Choice of programming language
3. Syntax of a language
Understanding the Program Development Cycle

1. .
2. .
3. .
4. Use software (a compiler or interpreter) to translate the program into machine language.

Creating an executable program


Understanding the Program Development Cycle

1. .
2. .
3. .
4. .
5. Test the program.
6. 1. A program that is free of syntax errors is not necessarily free of logical errors.

ax2 + bx +c=0 ; r1 = ( -b + √b*b – 4*a*c)

(2*a)

Should be r1 = ( -b + sqrt (b*b – 4*a*c) ) / (2*a)

Logical error might be r1 = -b + sqrt (b*b – 4*a*c ) / (2*a) // Hierarchy of operations?


Understanding the Program Development Cycle

1. .
2. .
3. .
4. .
5. .
6. Put the program into production.
7. Maintain the program: Changes as and when needed in the program
Planning a Program

1. Pseudo-Code
• Pseudocode is an English-like representation of the logical steps it takes to solve a
problem.
• Pseudo is a prefix that means false
• To code a program means to put it in a programming language
• Pseudocode simply means false code, or sentences that appear to have been written in a
computer programming language but do not necessarily follow all the syntax rules of any
specific language.

2. Flowchart : is a pictorial representation problem understanding


Pseudo Code

Writing Pseudo code = writing steps of program in a sequence

eg: Conducing a lecture


1. Start
2. Goto a class room
3. Open a book
4. explain the concept
5. Discuss with students
6. Ask questions
7. students answer
8. Repeat steps 6 and 7 ____ times
9. If Step 7 not satisfactory repeat steps 4 to 8 till Satisfactory
10. Take attendance
11. Close the book
12. Leave the hall
13. Stop
Pseudo Code

Pseudocode Standards
• Programs begin with start and end with stop; these two words are always aligned.
• Whenever a module name is used, it is followed by a set of parentheses.
• Modules begin with the module name and end with return. The module name and return are
always aligned.
• Each program statement performs one action—for example, input, processing, or output.
• Program statements are indented a few spaces more than start or the module name.
• Each program statement appears on a single line if possible. When this is not possible,
continuation lines are indented.
• Program statements begin with lowercase letters.
• No punctuation is used to end statements.
Flowcharts

Symbols used in Flowchart


Pseudo code Vs Flowcharts

Write a Pseudo code and draw flowchart to find Factorial of a number


Start
factorial(n)
begin
Fact=1
initialize fact=1
for i=1 to n do
begin i=1
calculate fact=fact*i
increment i by 1
end Fact=fact*i
display result
end i=i+1

Yes i<=n No Display


Stop
? fact
Pseudo code Vs Flowcharts
Write an algorithm / Pseudo code to generate Fibonacci Series
fibbo(int n) // n is number of terms to be printed
{
set f1=0 and f2 =1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2
n=n-2
f1 f2 f3 n o/p
repeat while (n>0) 0 1 5
{
calculate f3
print f3
f2=f3
f1=f2
// done with 1 iteration decrease n by 1
n=n-1
}
}
Pseudo code Vs Flowcharts
Write an algorithm / Pseudo code to generate Fibonacci Series
fibbo(int n) // n is number of terms to be printed
{
set f1=0 and f2 =1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2
n=n-2
f1 f2 f3 n o/p
repeat while (n>0) 0 1 5 0
{ 1
calculate f3
print f3
f2=f3
f1=f2
// done with 1 iteration decrease n by 1
n=n-1
}
}
Pseudo code Vs Flowcharts
Write an algorithm / Pseudo code to generate Fibonacci Series
fibbo(int n) // n is number of terms to be printed
{
set f1=0 and f2 =1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2
n=n-2
f1 f2 f3 n o/p
repeat while (n>0) 0 1 5 0
{ 1
calculate f3 3
print f3
f2=f3
f1=f2
// done with 1 iteration decrease n by 1
n=n-1
}
}
Pseudo code Vs Flowcharts
Write an algorithm / Pseudo code to generate Fibonacci Series
fibbo(int n) // n is number of terms to be printed
{
set f1=0 and f2 =1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2
n=n-2
f1 f2 f3 n is n >0? o/p
repeat while (n>0) 0 1 5 0
{ 1
calculate f3 3 3>0 Y
print f3
f2=f3
f1=f2
// done with 1 iteration decrease n by 1
n=n-1
}
}
Pseudo code Vs Flowcharts
Write an algorithm / Pseudo code to generate Fibonacci Series
fibbo(int n) // n is number of terms to be printed
{
set f1=0 and f2 =1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2
n=n-2 f1 f2 f3 n is n >0? o/p
repeat while (n>0) 0 1 5 0
{
1
calculate f3= f1+f2
3 3>0 Y
print f3
0+1=1
f2=f3
f1=f2
// done with 1 iteration decrease n by 1
n=n-1
}
}
Pseudo code Vs Flowcharts
Write an algorithm / Pseudo code to generate Fibonacci Series
fibbo(int n) // n is number of terms to be printed
{
set f1=0 and f2 =1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2
n=n-2 f1 f2 f3 n is n >0? o/p
repeat while (n>0) 0 1 5 0
{
1
calculate f3= f1+f2
3 3>0 Y
print f3
0+1=1 1
f2=f3
f1=f2
// done with 1 iteration decrease n by 1
n=n-1
}
}
Pseudo code Vs Flowcharts
Write an algorithm / Pseudo code to generate Fibonacci Series
fibbo(int n) // n is number of terms to be printed
{
set f1=0 and f2 =1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2
n=n-2 f1 f2 f3 n is n >0? o/p
repeat while (n>0) 0 1 5 0
{
1
calculate f3= f1+f2
3 3>0 Y
print f3
0+1=1 1
f2=f3
1
f1=f2
// done with 1 iteration decrease n by 1
n=n-1
}
}
Pseudo code Vs Flowcharts
Write an algorithm / Pseudo code to generate Fibonacci Series
fibbo(int n) // n is number of terms to be printed
{
set f1=0 and f2 =1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2
n=n-2 f1 f2 f3 n is n >0? o/p
repeat while (n>0) 0 1 5 0
{
1
calculate f3= f1+f2
3 3>0 Y
print f3
0+1=1 1
f2=f3
1
f1=f2
// done with 1 iteration decrease n by 1 1
n=n-1
}
}
Pseudo code Vs Flowcharts
Write an algorithm / Pseudo code to generate Fibonacci Series
fibbo(int n) // n is number of terms to be printed
{
set f1=0 and f2 =1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2
n=n-2 f1 f2 f3 n is n >0? o/p
repeat while (n>0) 0 1 5 0
{
1
calculate f3= f1+f2
3 3>0 Y
print f3
0+1=1 1
f2=f3
1
f1=f2
// done with 1 iteration decrease n by 1 1
n=n-1 2
}
}
Pseudo code Vs Flowcharts
Write an algorithm / Pseudo code to generate Fibonacci Series
fibbo(int n) // n is number of terms to be printed
{
set f1=0 and f2 =1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2
n=n-2 f1 f2 f3 n is n >0? o/p
repeat while (n>0) 0 1 5 0
{
1
calculate f3= f1+f2
3 3>0 Y
print f3
0+1=1 1
f2=f3
1
f1=f2
// done with 1 iteration decrease n by 1 1
n=n-1 2 2>0? Y
}
}
Pseudo code Vs Flowcharts
Write an algorithm / Pseudo code to generate Fibonacci Series
fibbo(int n) // n is number of terms to be printed
{
set f1=0 and f2 =1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2
n=n-2 f1 f2 f3 n is n >0? o/p
repeat while (n>0) 0 1 5 0
{
1
calculate f3= f1+f2
3 3>0 Y
print f3
0+1=1 1
f2=f3
1
f1=f2
// done with 1 iteration decrease n by 1 1
n=n-1 2 2>0? Y
}
1+1=2
}
Pseudo code Vs Flowcharts
Write an algorithm / Pseudo code to generate Fibonacci Series
fibbo(int n) // n is number of terms to be printed
{
set f1=0 and f2 =1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2
n=n-2 f1 f2 f3 n is n >0? o/p
repeat while (n>0) 0 1 5 0
{
1
calculate f3= f1+f2
3 3>0 Y
print f3
0+1=1 1
f2=f3
1
f1=f2
// done with 1 iteration decrease n by 1 1
n=n-1 2 2>0? Y
}
1+1=2 2
}
f1 f2
Pseudo code Vs Flowcharts f3 n is n >0? o/p
Write an algorithm / Pseudo code to generate Fibonacci Series 0 1 5 0
fibbo(int n) // n is number of terms to be printed 1
{ 3 3>0 Y
set f1=0 and f2 =1 0+1=1 1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2 1
n=n-2
repeat while (n>0) 1
{ 2 2>0? Y
calculate f3= f1+f2 1+1=2 2
print f3 2
f2=f3
f1=f2
// done with 1 iteration decrease n by 1
n=n-1
}
}
f1 f2
Pseudo code Vs Flowcharts f3 n is n >0? o/p
Write an algorithm / Pseudo code to generate Fibonacci Series 0 1 5 0
fibbo(int n) // n is number of terms to be printed 1
{ 3 3>0 Y
set f1=0 and f2 =1 0+1=1 1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2 1
n=n-2
repeat while (n>0) 1
{ 2 2>0? Y
calculate f3= f1+f2 1+1=2 2
print f3 2
f2=f3 2
f1=f2
// done with 1 iteration decrease n by 1
n=n-1
}
}
f1 f2
Pseudo code Vs Flowcharts f3 n is n >0? o/p
Write an algorithm / Pseudo code to generate Fibonacci Series 0 1 5 0
fibbo(int n) // n is number of terms to be printed 1
{ 3 3>0 Y
set f1=0 and f2 =1 0+1=1 1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2 1
n=n-2
repeat while (n>0) 1
{ 2 2>0? Y
calculate f3= f1+f2 1+1=2 2
print f3 2
f2=f3 2
f1=f2 1
// done with 1 iteration decrease n by 1
n=n-1
}
}
f1 f2
Pseudo code Vs Flowcharts f3 n is n >0? o/p
Write an algorithm / Pseudo code to generate Fibonacci Series 0 1 5 0
fibbo(int n) // n is number of terms to be printed 1
{ 3 3>0 Y
set f1=0 and f2 =1 0+1=1 1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2 1
n=n-2
repeat while (n>0) 1
{ 2 2>0? Y
calculate f3= f1+f2 1+1=2 2
print f3 2
f2=f3 2
f1=f2 1 1>0 ? Y
// done with 1 iteration decrease n by 1
n=n-1
}
}
f1 f2
Pseudo code Vs Flowcharts f3 n is n >0? o/p
Write an algorithm / Pseudo code to generate Fibonacci Series 0 1 5 0
fibbo(int n) // n is number of terms to be printed 1
{ 3 3>0 Y
set f1=0 and f2 =1 0+1=1 1
output f1 and f2 // printed 2 terms out of total n so reduce n by 2 1
n=n-2
repeat while (n>0) 1
{ 2 2>0? Y
calculate f3= f1+f2 1+1=2 2
print f3 2
f2=f3 2
f1=f2 1 1>0 ? Y
// done with 1 iteration decrease n by 1 2+2=4
n=n-1
}
}
Flowchart : Use of Sentinel value to end the program
Flowchart for interactive program to Double the number entered by user

Use some UNUSED number to stop iteration


EOF in Files
Understanding Programming Environments
To enter the program into a computer so you can translate and execute it, you usually use a
keyboard to type program statements into an editor.
You can type a program into one of the following:
• A plain text editor : Notepad, Norton Editor, vi (linux), MS word
• A text editor that is part of an integrated development environment: (
IDE : integrated development environment
Turbo C, Code block, Spyder(Anaconda)
Plain Text editor Vs IDE: Memory requirement is very high in IDE
Understanding Programming Environments
Advantages of IDE :
• Using an IDE is helpful to programmers because usually it provides features similar to those we
find in many word processors.
• It uses different colors to display various language components, making elements like data types
easier to identify.
• It highlights syntax errors visually for you.
• It employs automatic statement completion; when you start to type a statement, the IDE suggests
a likely completion, which you can accept with a keystroke.
• It provides tools that allow you to step through a program’s execution one statement at a time so
you can more easily follow the program’s logic and determine the source of any errors.
Understanding User Environments
• Command line
• GUI

• Game problem: Mad Libs is a children’s game in which players provide a few words that are then
incorporated into a silly story. The game helps children understand different parts of speech
because they are asked to provide specific types of words. For example, you might ask a child for
a noun, another noun, an adjective, and a past-tense verb. The child might reply with such
answers as table, book, silly, and studied. The newly created Mad Lib might be:
Mary had a little table
Its book was silly as snow
And everywhere that Mary studied
The table was sure to go.
Create the logic for a Mad Lib program that accepts five words from input, then
creates and displays a short story or nursery rhyme that uses them.
Understanding User Environments

• Game problem: Mad Libs is a children’s game in which players provide a few words that are then
incorporated into a silly story. The game helps children understand different parts of speech
because they are asked to provide specific types of words.
Inputs are : a noun, another noun, an adjective, and a past-tense verb.
The child might reply with such answers as table, book, silly, and studied.
The newly created Mad Lib might be:

Mary had a little table


Its book was silly as snow
And everywhere that Mary studied
The table was sure to go.
Understanding User Environments
• Game problem: Mad Libs is a children’s game in which players provide a few words that are then
incorporated into a silly story.

noun, another noun, an adjective, and a past-tense verb.

table, book, silly, studied.

Output in terms of variables is :


Mary had a little NOUN
it’s a_NOUN was ADJ as snow
And everywhere that Mary VERB
The table was sure to go.
Understanding User Environments
The characters in black are static, can be printed using printf
The tokens having colored background are input from user

Mary had a little NOUN


it’s a_NOUN was ADJ as snow
And everywhere that Mary VERB
The table was sure to go.

You might also like