Chapter 1 Programming Problem Solving
Chapter 1 Programming Problem Solving
Muhammad Taufiq
Department of Information and Communications Technology, , IIUM
Learning Outcome
• Identify basic components of a computer system
• Describe the Software Development Life Cycle (SDLC)
• Create a simple algorithm from a given problem
• Write a basic C Programming
• Execute programming code
2
Binary Digits
0, 1
3
Source: bbc.co.uk (Bitesize)
4
5
Machine language
6
Assembly languages
…
Assembler …
ADDF3 R1, R2, R3
1101101010011010
…
…
7
High level languages
• The high-level languages are English-like and easy to learn and program.
• For example, the following is a high-level language statement that
computes the area of a circle with radius 5:
area = 5 * 5 * 3.1415;
8
Popular High-level languages
9
History of C Programming
10
Programming Environment
• To run a C program, you must first create
the source code (also called source
program/ source module/ source file)
• The compiler compiles source code into a
machine readable form called an object
code (also called object program/ object
module/ object file)
• The compiler will also generate other
information needed for the linker to link
the object code with other referenced
module.
11
Inputs Algorithms Outputs
12
#include <stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
13
Algorithm representation
• Pseudocode
• A semiformal, English–like language with a limited vocabulary can be
used to design & describe algorithm.
• Flowchart
– A graph consisting of geometrical shapes that are connected
by flow lines.
14
Pseudocode
English-like syntax that represents a programming language
15
Guidelines to develop the pseudocode
• Each steps is execute in-order #include <stdio.h>
• The word “End” is used to show the end int main()
of process {
• Selection / conditional structure printf("Hello World!");
(optional) }
• Repetition / loop structure (optional) Pseudocode Example
• Use arithmetic symbol
1. Begin
2. Print “Hello World!”
3. End
16
• Each steps is execute in-order
17
Exercise
• Write a pseudocode to calculate area of rectangle.
18
Flowchart
Graphical representations of algorithms.
19
Flowchart
Graphical representations of algorithms.
20
Symbols use in flowchart
Begin / C
End o
n
Process n
e
c
t
Input / Output
o
r
21
Guidelines to develop the flowchart
• Identify the correct symbol
• according to their function
• Get a correct formula
• Use the appropriate data
• Test your flowchart
• Trace each symbol & compare with the expected output
22
Example
Problem:
Compare 2 values. If number 1 is greater than number 2, print message “Number
1” Flowchart
Pseudocode
Begin
End
24
Exercise
• Write a flowchart to calculate area of rectangle.
25
Software Development Life Cycle (SDLC)
• Requirement specification : eliminated ambiguities in the problem
statement.
• Analysis : identified problem inputs, outputs & collected information
about the inputs.
• Design : developed a series of steps with a logical order which, when
applied, would produce the output of the problem
• Implementation : Using tools.
• Testing & verification : check the output to verify the correctness of the
method.
26
Requirement Specification
• Understanding what the problem is?
• What is needed to solve it?
• What is solution should provide?
• Constraints & special conditions.
27
Analysis
• Inputs to the problem, their form & input media to
be used
• Outputs expected from the solution, their form &
output media to be used
• Any special constraints or conditions
• Formulas or equations to be used
28
Design
• Method of solution : what is define by design?
• Also called as algorithm : a sequence of a finite
number of steps arranged in a specific logical order,
which, when executed, produce the solution for a
problem.
29
Software Development Life Cycle (SDLC)
Agile Model
Modularity
• Programming problems should be divided into sub-problems and assembled in a
logical order.
• break up of a program as modules or functions to make it more manageable, rather
than putting all source codes in main() program only.
31
THE MAKING OF QUALITY PROGRAMS
Efficiency
• the smaller size of program is better because it runs faster during compilation.
• make source codes simple, concise, clear, and correct.
• write the most optimal code to gain high efficiency of the program.
Robustness
• able to handle all situations in a graceful manner.
• will not behave incorrectly or crash in unexpected situations or go to infinite loops.
Usability
• program is correct and meets the end-user requirements.
• easy to use and has good system learnability to end users.
32
YouTube:
CS50 2019 - Lecture 0 - Computational Thinking, Scrat
ch 33
Thank You