COMP1105 - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

COMP1105

Description:

Small programs (less than 5000 lines) can be reliably developed by one person ... documentation techniques may seem like overkill for small problems, THE PRACTICE ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 24
Provided by: cmpla
Category:

less

Transcript and Presenter's Notes

Title: COMP1105


1
COMP1105
  • The Structure Theorem
  • Modularization
  • Top-Down design and
  • Stepwise Refinement
  • Pseudocode and
  • Flowcharts
  • Algorithms
  • Control structures
  • 2. Problem Solving and programming

2
Problem solving and software development
  • Software Engineering
  • Small programs (less than 5000 lines) can be
    reliably developed by one person
  • Most software is developed in much larger
    environments - with teams of programmers or even
    collections of teams
  • Managing large projects involves many more
    organisational difficulties than the small
    single-person projects
  • Software engineering is the study of processes by
    which large projects can be developed

3
Problem solving process
  • We want to build good problem solving skills for
    software development
  • This means skills which can successfully be used
    to tackle larger and more complex problems
  • The design/documentation techniques may seem like
    overkill for small problems, THE PRACTICE IS
    IMPORTANT, AND VASTLY WORTHWHILE LATER ON
  • Planning, organisation, and documentation prevent
    a great deal of grief in program development and
    maintenance

4
A typical Software life cycle
  • Analysis - specifying exactly what the problem is
    and what are the requirements for an acceptable
    solution
  • Design - developing a detailed solution to the
    problem
  • Coding - turning the design into a working
    program
  • Testing/verification - ensuring the software is
    correct
  • Maintenance - fixing, enhancing, adapting the
    software
  • Obsolescence - abandoning a program which is no
    longer effectively maintainable

5
Program development
  • Analysing/defining the problem we're given
  • Developing a solution technique (algorithm)
  • Documenting the program/technique
  • Translating (implementing) the technique into
    code
  • Compiling and running the program
  • Testing the results with appropriate data

6
Design and analysis
  • Analysis includes
  • determining the input data for the program
  • determining the output that must be produced
  • identifying any information needed to get from
    the inputs to the output
  • Design consists primarily of working out an
    algorithm
  • that is, a step by step procedure for solving the
    problem (based on the analysis)

7
Structured Programming
  • Top-down development
  • Modular design
  • The Structure Theorem

8
Top-down design
  • Take a problem, divide it into smaller logical
    sub-problems, and remember how they fit together
  • For each sub-problem, divide it into still
    smaller sub-problems
  • Continue sub-dividing until each little problem
    is small enough to be easily solved
  • Solving a collection of small problems thus
    allows us to solve one much larger problem
    Modular Design

9
The Structure Theorem
  • 3 control structures (Bohm and Jacopini)
  • Sequence structure statements executed
    sequentially by default
  • Transfer of Control
  • Selection if-Then-Else
  • Repetition do/while, Repeat/Until

10
Algorithms
  • Computing problems
  • Solved by executing a series of actions in a
    specific order
  • Algorithm is a procedure determining
  • Actions to be executed
  • Order to be executed
  • Example recipe
  • Program control
  • Specifies the order in which statements are
    executed

11
Algorithms
  • Must be
  • Precise and unambiguous
  • Give the correct solution in all cases
  • Eventually end
  • Example an algorithm for making coffee
  • Stumble to kitchen
  • Get coffee beans
  • Get Coffee Grinder
  • Grind.
  • Drink your coffee!

12
Pseudocode
  • Artificial, informal language used to develop
    algorithms that is similar to everyday English
  • Not executed on computers but is used to think
    out program before coding and Easy to convert
    into programs
  • 6 basic computer operations
  • Receive information Read, Get, ..
  • Put out information display, Print, ..
  • Perform arithmetic
  • Assign value to a variable or memory location
  • Compare two variable and select one of two
    alternative actions If/Else
  • Repeat a group pf actions Do/While
  • 3 basic control structures
  • Sequence
  • Selection
  • Repetition
  • 3 steps
  • Define problem
  • Design solution algorithm
  • Check solution

13
Pseudocode
  • Suppose a program is required to read 2 numbers,
    add them and print their total.

Defining Diagram
Algorithm
Algorithm to add 2 numbers and print their
sum Begin Input the first number Input the
second number Add the two numbers Output the
sum End
14
Pseudocode
  • Suppose you want to determine which is the larger
    of the two numbers (if any).

Begin Input Num1 from the keyboard Input the
Num2 from the keyboard If the Num1 is greater
than the Num2 print Num1 Else if the Num2 is
greater than the Num1 print Num2 Else print
a message stating that the numbers are equal
End
15
Flowchart
  • Graphical representation of an algorithm using
    special-purpose symbols connected by arrows
    (flowlines)
  • Parallelogram symbol
  • Input/Output operations
  • Diamond symbol - Decision
  • Rectangle symbol Action/process
  • Oval symbol
  • Beginning or end of a program, or a section of
    code (circles)

Read Num2
Num1 gt Num2
no
yes
Print Num1
Stop
16
if Selection structure
  • Choose among alternative courses of action
  • Pseudocode statement to determine whether a
    student has passed the course
  • If students grade is greater than or equal to 40
  • Print Passed
  • If the condition is true
  • Passed is printed, control continues on to next
    statement
  • If the condition is false
  • Print statement ignored, control continues to
    statement after the if
  • Indenting makes algorithm easier to read

17
if Selection structure
  • Flowchart of pseudocode statement
  • If - Performs action if condition true
  • if/else Performs Different actions if
    conditions true or false
  • Example
  • if students grade is greater than or equal to
    40 print Passed
  • else
  • print Failed

18
while Repetition Structure
  • Action repeated while some condition remains true
  • Pseudocode
  • while there are more items on my shopping list
  • Purchase the next item and cross it off
    the list
  • while loop repeated until condition becomes false


19
Example
  • A fabric store wants a program to convert
    measurements in square metres to square yards
  • Define problem program data?
  • Inputs the incoming information is the number of
    square metres of fabric
  • Outputs the number of square yards which are
    equivalent to the input number of square metres
  • How to get from inputs to outputs the extra
    information we need (and can work out) is that 1
    square metre 1.196 square yards. Thus the
    output number is 1.196 times the input number

20
Write an algorithm to Find the tallest person in
the class!
  • Read number of people into the variable people
  • Input the first height directly into the variable
    tallest
  • Increment counter to 1
  • WHILE counter is less than people DO
  • Begin
  • input a new height into the variable height
  • IF height is greater than tallest
  • replace tallest with height
  • ENDIF
  • Increment counter
  • End
  • Print the value of the largest
  • (NB1 BEGIN and END of the algorithm is not
    shown!
  • 2 The while condition becomes false when
    counter is equal
  • to people)

21
flowchart
END
22
Solve this problem
BEGIN ALGORITHM //Let num1, num2 and num3 store
integer values   READ num1, num2   INITIALISE
num3 0   WHILE num2 gt 0 DO   BEGIN     
num3 num3 num1      num2 num2 - 1  
END   PRINT num3END ALGORITHM
  • The following algorithm reads in 2 numbers and
    performs an operation on them. What is the
    relationship between the 2 numbers read in and
    the result printed?
  • Draw a flowchart.

23
Skills needed in programming
  • Attention to detail
  • Stupidity
  • Good memory
  • Ability to abstract, think on different levels
  • Further Reading http//www.eskimo.com/scs/cclass
    /progintro/sx1.html
Write a Comment
User Comments (0)
About PowerShow.com