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

Chapter 1 Programming Problem Solving

The document provides an overview of programming and problem solving. It discusses basic components of a computer system, the software development life cycle, and creating algorithms from problems. It also covers binary digits, machine language, assembly language, high-level languages, popular programming languages like C, and the history and environment of C programming. Pseudocode and flowcharts are presented as ways to represent algorithms.

Uploaded by

Fairuz Munirah
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Chapter 1 Programming Problem Solving

The document provides an overview of programming and problem solving. It discusses basic components of a computer system, the software development life cycle, and creating algorithms from problems. It also covers binary digits, machine language, assembly language, high-level languages, popular programming languages like C, and the history and environment of C programming. Pseudocode and flowcharts are presented as ways to represent algorithms.

Uploaded by

Fairuz Munirah
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

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

• Machine language is a set of primitive instructions built into every


computer. The instructions are in the form of binary code, so you have
to enter binary codes for various instructions. Program with native
machine language is a tedious process. Moreover the programs are
highly difficult to read and modify.
• For example, to add two numbers, you might write an instruction in
binary like this:
1101101010011010

6
Assembly languages

• Assembly languages were developed to make programming easy. Since the


computer cannot understand assembly language, however, a program called
assembler is used to convert assembly language programs into machine code.
• For example, to add two numbers, you might write an instruction in assembly
code like this:
ADDF3 R1, R2, R3
Assembly Source File
Machine Code File


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

• COBOL (COmmon Business Oriented Language)


• FORTRAN (FORmula TRANslation)
• BASIC (Beginner All-purpose Symbolic Instructional Code)
• Pascal (named for Blaise Pascal)
• Ada (named for Ada Lovelace)
• C (whose developer designed B first)
• Visual Basic (Basic-like visual language developed by Microsoft)
• Delphi (Pascal-like visual language developed by Borland)
• C++ (an object-oriented language, based on C)
• Java (an object-oriented language)

9
History of C Programming

Early 1970s, Dennis Ritchie created C at Bell Telephone


Laboratories.
C exists from the difficulties of programming language
(assembly language) for Unix OS.
Successor to B.
C++ exists from the enhancement of C with data
abstraction and object-oriented.

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.

YouTube: Algorithm using Flowchart and Pseudo code Level 1 Flowchart

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.

Area = Width x Height

18
Flowchart
Graphical representations of algorithms.

19
Flowchart
Graphical representations of algorithms.

• Flowcharts were formerly used to describe each processing path in a


program (the main program and various subroutines that could be
branched to)
• Programmers were admonish to always flowchart their logic rather than
carry it in their heads
• Use of simple geometric symbols to represent the beginning or end of a
program (an oval), a process (a rectangle), a decision (a diamond), or an
I/O process (a parallelogram). These symbols are defined in ANSI x 3.5
and ISO 1028.

20
Symbols use in flowchart
Begin / C
End o
n
Process n
e
c
t
Input / Output
o
r

Decision Activity Flow

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

1. Begin Read no1


2. Read no1 Read no2
3. Read no2 True
4. If (no1 > no2 ) If no1 > no2
4.1 Print “Number 1” Print
False “Number1”
5. End
End
23
Example: Pseudocode Example: Flowchart
Begin
1. Begin
Read no1
2. Read no1
3. Read no2 Read no2
4. If (no1 > no2 )
True Print
4.1 Print “Number 1” If no1 > no2
“Number 1”
5. Else If (no2 > no1 ) False
5.1 Print “Number 2” If no2 > no1
True
Print
6. Else “Number 2”
False
6.1 Print “Equal” Print
7. End “Equal”

End
24
Exercise
• Write a flowchart to calculate area of rectangle.

Area = Width x Height

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.

*Defining problem depends on degree of familiarity with the problem domain.


What would you do if you don’t?

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

6 basic SDLC methodologies: Which one is best?


30
THE MAKING OF QUALITY PROGRAMS
Readability
• make sure programs are understandable and have proper documentation style
(comments and indentations).
• follow the rules of naming convention of variables.
• easier for other programmers to read, understand and modify the codes later.

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

You might also like