PF-Week 01
PF-Week 01
PF-Week 01
Fundamental
Week 01
Sobia Iftikhar
[email protected]
Objectives of course
Week 05
Discussion of the course outline, Introduction
Week 10
problem solving with decisions and iterative Constant, Variables, Keywords,
Week
to problem solving, What is algorithm, How to structures, Basic Computer Organization, Intro
Escape sequence, Format Specifiers,
write pseudo code, programming structures, to IDE (compiled program, text editors,
01
problem solving with the sequential structures debuggers, etc), Program structure and Data types, Data manipulation,
and, Basic Flowchart, IPO and PAC. Execution, First Program with Input and Output. Library, Linking, Compiling & Loading.
Week 12
Decision Control Structures: If Nested if statements & switch
Week 02
Week 07
Introduction to Loops Design,
statements and if-else statement, statements 2. Logical &
Basic switch statements, Some
For, while and do-while loops,
Conditional Operators 3. Working
working examples. examples. Some working examples.
Week 03
Week 13
Week 08
Nested Loops, Break and Introduction to 1D Arrays, Functions: Declaration, Definition and
Calling, Passing values to functions, Passing
Continue Statement, Multiple subscripted arrays to functions, Standard library string
Working examples. arrays, Working examples. functions, 2D array of characters.
Week 04
Week 14
Week 09
Recursion 2. Introduction Nested structures, Passing
Dynamic memory
to Structures and Structure structure function 2. Introduction
to pointers 3. Pointers and Arrays. allocation 2. Void pointers
array 3. Working examples.
Week 15- Revision
Week 16- FINAL EXAM
Grading Scheme
– Mid-1 & 2: 15 each
– Assignment: 20
– Final: 50
Class 01
06-Sep-2021
Content
– Introduction to problem solving
– What is algorithm, How to write pseudo code
– Programming structures
– Problem solving with the sequential structures
– Basic Flowchart, IPO and PAC
Problem solving Concepts
– People make decisions every day to solve problems that affect their lives. If a
bad decision is made, time and resources are wasted, so it’s important that
people know how to make decisions well.
– For this, There are six steps to follow to ensure the best decision.
These six steps in problem
solving include the following:
1. Identify the problem. How do the individuals wish to spend the evening?
2. Understand the problem. With this simple problem, also, the knowledge base of the participants must be
considered. The only solutions that should be selected are ones that everyone involved would know how to do. You
probably would not select as a possible solution playing a game of chess if the participants did not know how to play.
3. Identify alternatives.
– a. Watch television.
– b. Invite friends over.
– c. Play video games.
– d. Go to the movies.
– e. Play miniature golf.
– f. Go to the amusement park.
– g. Go to a friend’s party.
– The list is complete only when you can think of no more alternatives.
Solution (cont.)
– Solutions that cannot be reached through a direct set of steps are called heuristic
solutions.
– These solutions require reasoning built on knowledge and experience, and a
process of trial and error.
– Example: how to buy the best stock or whether to expand the company
Problems with heuristic solutions
First guess:
Arrange a number in v = 1+3+5 =
way that sum of vertical 9
is equal to sum of H = 2+3+4 =
horizontal? 9
First guess:
v = 1+2+4 =
7
H = 3+2+5 =
10
Class 02
07-Sep-2021
Problem solving with
computers
The problem-solving process is not easy. It takes
practice and time to perfect, but Program means the set of instructions that make
in the long run the process proves to be of great up the solution after they have been coded into a
benefit. particular computer language.
– The algorithm is procedure or step by step instruction that you tell computer to do.
– To make a computer to do some task, one need a computer program.
– To write computer program, computer needs step by step statement, what you
exactly want to do.
– Its better to write algorithm before writing the actual computer program
– Properties of algorithm:
– Given problem should be broken into meaning full step
– Should be numbered sequentially
– Should be descriptive in simple English.
Example
Pseudo code
– Pseudo code describes how you would implement an algorithm without getting
into syntactical details
– Pseudo code is an informal way of writing a program. It is not exactly a
computer program. It represents the algorithm of the program in natural
language and mathematical notations.
Example
When solving problems on the computer, one of the most difficult tasks Insufficient
Incorrect prob
st
Poor training
Afraid to mak
for the problem solver is writing the instructions. definition
algorithm
Take the task of deciding which number is the largest from a
group of three numbers. Almost anyone can immediately tell which
is the largest, but many cannot explain the steps they followed to arrive
at it.
What Problem Can Be Solved
By Computer
Phase 2:
Programming phase.
Pre-programming Phase
Write a Problem Analysis Chart (PAC) to convert the distance in miles to kilometers
where 1.609 kilometers per mile.
– The interaction will form a hierarchy, called Hierarchy Input Process Output
Chart (HIPO) or Interactivity Chart (IC). Programming which use this
approach (problem is divided into subtasks) is called Structured Programming.
Main Module
Write an Input Process Output (IPO) that asks a user to enter the distance of a trip in
miles, the miles per gallon estimate for the user’s car, and the average cost of a gallon
of gas. Calculate and display the number of gallons of gas needed and the estimated
cost of the trip.
Solution
Input Processing Module Output
Symbol Function
Show the direction of data flow or logical
solution.
READ PRINT
QUANTITY TOTALSALE
A STOP
PRE-PROGRAMMING
PHASE
Finding Average Problem
Read a sequence of number, find the average of the number and print the average.
Solution: Stepwise Analysis of Average Problem
Start the processing
Read a number
Add the number
Repeat reading until last data
Calculate the average
Print the average
Stop the processing
Start
Read
Number Pre-
programming
Accumulate
Total Repetition Until End Of Data Phase
Calculate
Average
Print
Average
Stop
Start
X
Counter
=Æ
Pre-
Average = Total programmin
Read Number Counter
g Phase
Print Average
Total = Total + Number
Counter = Counter + 1
Stop
End Of Data
X
PRE-PROGRAMMING
PHASE
TASK:
READ
PRICE
READ
QUANTITY
Algorithm:
SALE = PRICE ´
QUANTITY Start
STOP
Example: Flowchart & Algorithm
Order of Execution of Instructions : Payroll System
Structuring a Program
Develop efficient computer solution to problems:
1. Use Modules
2. Use four logic structures
a. Sequential structure