Problem Solving with Programming - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Problem Solving with Programming

Description:

A flowchart is a diagram that is used to describe how a program work. It is used mainly to indicate the ... Hence the radix or base is said to be 2. For example ... – PowerPoint PPT presentation

Number of Views:65
Avg rating:3.0/5.0
Slides: 32
Provided by: solo65
Category:

less

Transcript and Presenter's Notes

Title: Problem Solving with Programming


1
Problem Solving with Programming
  • Week 2
  • Department of Computer Science
  • Faculty of Science and Technology
  • Assumption University

2
Agenda
  • Program Modeling Tools
  • Flowchart
  • Pseudo code
  • Programming Style Conventions
  • Indentation and Code Formats
  • Naming Conventions
  • Commenting
  • Number Systems
  • Decimal
  • Binary
  • Hexadecimal
  • Octal

3
Program Modeling Tools
3
4
Flowchart
  • A flowchart is a diagram that is used to describe
    how a program work.
  • It is used mainly to indicate the sequence of
    program executions as well as program branches
    and iterations.

5
Flowchart Symbols
  • Start/Stop
  • Computation
  • Input/Output
  • Condition
  • Directions
  • Connection

6
Flowchart Start/Stop
. . .
7
Flowchart Sequential
8
Flowchart Condition
9
Flowchart Iterations
10
Pseudocode
  • Pseudocode is used to describe algorithm.
  • It is written in human languages (usually
    English).
  • There is no standard conventions on how to write
    pseudocode.
  • Pseudocode is usually written as steps on how to
    do something.
  • Programmers can write a pseudocode first and then
    translate it in to a program in a specific
    programming language.

11
Programming Style Conventions
11
12
Indentation and Code Formats
  • Indentation and code formats are not required for
    most programming languages but they are important
    for program readability.
  • It helps programmers convey the structure of a
    program or a block of code to human readers.

13
Indentation in C
  • In C, an indentation is used whenever the line
    of code is a part of the outer one.
  • For example
  • int Add(int a, int b)
  • return a b

14
Nested Indentation
  • Indentation can be nested if an inner code has
    something further in it.
  • For example
  • if (a lt b)
  • if (a lt c)
  • x a
  • else
  • x c

15
Curly Braces
  • In C, the curly braces and are used to
    define the scope and create a compound statement.
  • The opening brace must be on the same line as
    the control structures first line.
  • The closing brace must be on the last line of
    that control structure.
  • The location of the closing brace must be at the
    same indentation level as that of control
    structure.

16
Naming Conventions
  • Good naming leads to good program readability.
  • Naming conventions specify how to capitalize
    names (such as variables and functions), whether
    there is any prefix or suffix to specialize names
    (such as pointers),

17
C Naming Conventions
  • Names representing types must be in mixed case
    starting with an uppercase letter (e.g., Student,
    MobilePhone).
  • Variable names must be in mixed case starting
    with a lowercase letter (e.g., studentName,
    mobileNumber).
  • Named constants must be all uppercase using
    underscore to separate words (e.g., PI,
    MAX_VALUE).

18
C Naming Conventions
  • Names representing functions must be verbs and
    written in mixed case starting with a lowercase
    letter (e.g., getStudentName, setMobileNumber).
  • Abbreviations and acronyms must not be uppercase
    when used as name (e.g., DvdPlayer).

19
Commenting
  • Commenting is used to document your code.
  • It describes what does the code or a segment of
    the code does.
  • It also helps other programmers understand your
    code.

20
Commenting in C
  • There are two ways to comment in C
  • Start a comment line with //
  • Cover a comment with / and /

21
Number Systems
  • Number systems use positional notation to
    represent value
  • Four such systems used in practice are
  • Decimal number system
  • Binary number system
  • Hexadecimal number system
  • Octal number system

22
Decimal Number System
  • The decimal number system has ten unique symbols
    0, 1, 2, 3, 4, 5, 6, 7, 8, and 9
  • It is also called Base 10 number system
  • the system of counting has ten symbols
  • Its radix or base is said to be 10
  • For example
  • (3472)10 3 103 4 102 7 101 2 100
  • 3000 400 70 2
  • (536.15)10 5 102 3 101 6 100 1
    10-1 5 10-2

23
Binary Number System
  • The binary number system has only two symbols 0
    and 1
  • Hence the radix or base is said to be 2
  • For example
  • (10101)2 1 24 0 23 1 22 0 211
    20
  • 16 0 4 0 1
  • 21 (the decimal equivalent of 1011012)

MSB
LSB
MSB Most Significant Bit LSB Least Significant
Bit
24
Binary Number System Cont.
  • What is the decimal equivalent of 11001.0112 ?
  • 11001.0112
  • 124 123 022 021 120
    02-1 12-2 12-3
  • 16 8 0 0 1 0 0.25 0.125
  • 25.375

25
Decimal to Binary Conversion
  • Convert the following decimal numbers into their
    binary equivalent
  • 17
  • 251
  • 4372
  • 0.71
  • 23.567

26
Binary to Decimal Conversion
  • Convert the following binary numbers into their
    decimal equivalent
  • 101102
  • 11101112
  • 10.0112
  • 11.10112

27
Hexadecimal Number System
  • Base-16 number system is called hexadecimal
    system
  • The term hexadecimal comes from the combination
    of two words decimal (10) and hex (6)
  • 16 characters exists in the hexadecimal set 0,
    1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F
  • This number system is most important in digital
    systems because it is easily to convert to and
    from binary

28
Binary to Hexadecimal Conversion
  • Convert 110111101011102 into hexadecimal
  • 0011 0111 1010 1110
  • 3 7 A
    E
  • 37AE16 37AEH

29
Hexadecimal to Decimal Conversion
  • Convert A59CH into decimal
  • A59CH A 163 5 162 9 161 C 160
  • 40960 1280 144 12
  • 42396

30
Hexadecimal to Binary Conversion
  • Convert F37AH into Binary
  • F37AH 1111 0011 0111 1010
  • Convert 23E0.B2H into Binary
  • 23E0.B2H 0010 0011 1111 0000 . 1011 0010

31
Octal Number System
  • The octal number system has 8 symbols 0, 1, 2,
    3, 4, 5, 6, and 7
  • Hence it is called Base-8 number system
  • Convert (231)8 into decimal
  • (231)8 2 82 3 81 1 80
  • 128 24 1 153
  • Convert 11110111101012 into octal
  • 001 111 011 110 101
  • 1 7 3
    6 5 (17365)8
Write a Comment
User Comments (0)
About PowerShow.com