8.2.1 defining and understanding the problem and planning and designing software solutions

Upload: johnny-marsh

Post on 13-Apr-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    1/72

    8.2.1

    DEFINING AND UNDERSTANDING THE

    PROBLEM,

    PLANNING AND DESIGNINGSOFTWARE SOLUTIONS

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    2/72

    DEFINING AND UNDERSTANDING THE PROBLEM,PLANNING AND DESIGNING SOFTWARE SOLUTIONS

    In planning a solution,

    You need to understand;

    The problem to be solved and

    How the solution will be used.

    In this topic, You will consider all aspects of the solution before starting

    its implementation.

    The selection of data types and structures used in the solution of aproblem can have a huge impact on the effectiveness of thatsolution.

    A variety of data types and structures are introduced in this topic andappropriate algorithms should be developed and implemented thatmake best use of these.

    As algorithms become more complex, there is a need for amethodical top-down approach with progressive refinement of detail.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    3/72

    DEFINING AND UNDERSTANDING THE PROBLEM,PLANNING AND DESIGNING SOFTWARE SOLUTIONS

    By the end of this topic, You will be able to;

    Describe and uses appropriate data types

    Describes the interactions between the elements of acomputer system

    Describes the effects of program language developmentson current practices

    Identifies the issues relating to the use of software solutions

    Investigates a structured approach in the design andimplementation of a software solution

    Use a variety of development approaches to generatesoftware solutions and distinguishes between these

    approaches Use and develop documentation to communicate software

    solutions to others.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    4/72

    DEFINING AND UNDERSTANDING THE PROBLEM,PLANNING AND DESIGNING SOFTWARE SOLUTIONS

    Three steps to produce a solution to a problem: Understand the problem

    Work out a way to solve the problem

    Check the solution to the problem

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    5/72

    UNDERSTANDING THE PROBLEM

    8.2.1Defining and understanding the problem,Planning and designing software solutions

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    6/72

    UNDERSTANDING THE PROBLEM

    Prior to designing or developing any solution, theneed for that solution must be fully understood.

    To understand the need for the solution we mustinvestigate the intended use of the software.

    What is the overall purpose?

    Who are the users?

    What environment will it be used in?

    What Information Technology will be required andwhat is already available in the current environment?

    What data/information is the software intended touse/produce/manipulate?

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    7/72

    UNDERSTANDING THE PROBLEM

    To understand a software solution to bedeveloped several tools can be used to get anidea of the softwares purpose and way in whichit can achieve its purpose.

    IPO ChartsInput, Process, Output.

    Decision trees

    System Flow Charts,

    Dataflow Diagrams, Context Diagrams,

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    8/72

    UNDERSTANDING THE PROBLEM

    IPOCharts

    It describes all data elements which enter thesystem, the process that they will undergo, and

    the data elements that will leave the system The creation of IPO charts require the problem in

    the following way:

    What outputs are required to solve the problem?

    What inputs are required to produce those

    outputs?

    What processes are required to transform theinputs into the outputs?

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    9/72

    UNDERSTANDING THE PROBLEM

    IPOCharts

    An IPO chart helps in understanding therelationship of a system by showing the relation ofthe subsystem.

    For example, a software is required to calculate

    the area of a square and rectangles, the IPO willlook as follows:

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    10/72

    UNDERSTANDING THE PROBLEM

    Example of IPO chart in tabular form

    Scenario : Engadine High School decides to prepare reports forstudent based upon grades and marks both.The grades and marks range is respectively as follows: A graderanges from 100 to 80 marks, B grade ranges from 79 to 60, Cgrade ranges from 59 to 50 and lastly F grade which is thefailure ranges form 49 to 0.

    The IPO chart looks as follows:

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    11/72

    UNDERSTANDING THE PROBLEM

    IPO exercise

    Construct an IPO chart and add the correctheadings to each of the three columns. Divide

    the chart into five rows. Use one row to analyseeach of the following problems into inputs,processes and outputs:

    The addition of two numbers

    Buttering a slice of bread

    Using a music CD Opening a browser at a specific web site

    Turning on a computer and opening a databaseprogram (assume a GUI interface)

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    12/72

    ABSTRACTION/REFINEMENT

    8.2.1Defining and understanding the problem,Planning and designing software solutions

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    13/72

    ABSTRACTION/REFINEMENT

    Top-down design In abstraction and refinement of the

    problem, top-down design is used togroup the program specification into more manageable smaller seriesof problem or modules.

    This approach; decomposition of

    problem, is also referred to as;

    Stepwise refinement or

    Hierarchy chart.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    14/72ABSTRACTION/REFINEMENT

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    15/72

    ABSTRACTION/REFINEMENT

    Top-down design

    A graphical or written description of step by step procedurefor the modules is called solution algorithm or program logic

    The program containing modules allows the structure to bemore clearly examined and tested at each stage ofdevelopment.

    The programmer will test the main program before themodules are created.

    Once the main program is tested then the other modules will

    be created and tested. This will be a step by step procedure, so that the error is

    eliminated when the testing is done for each modules.

    The main program or algorithm will be a driver module

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    16/72

    ABSTRACTION/REFINEMENT

    Modification of an Existing Solution:

    In some situations most needs are met by theexisting software, and the source code anddevelopment documentation are available yetnew features or requirements are still necessary.

    In this case the original softwares source code canbe modified to allow for the new requirements or

    hot fixes patches or updates can be developed toaccount for the new requirements leaving theprevious software still functional with new modules.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    17/72

    DATA TYPES

    8.2.1Defining and understanding the problem,Planning and designing software solutions

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    18/72

    DATA TYPESNUMBERINGSYSTEMS

    Data representation

    The binary, octal and the hexadecimal system arethe number systems used to represent data.

    A digital computer only understands the binarysystem.

    The binary system of numbers is used to representstates in a computer logic circuit or computerstorage,

    Requires only two digits to represent all numbers (0and 1)

    The number one represents on and 0 representsoff.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    19/72

    DATA TYPESNUMBERINGSYSTEMS

    The storage device that is commonly used to

    store data and how the digits are representedare as follows:

    Storage Device Where it is stored? How is Data represented?

    Electronic Media The RAM inside the a

    computer uses the

    electrical state

    In this device the on and

    off is represents the digits

    1 and 0

    Magnetic Media Such as Hard disk which

    uses magnetic spots

    The data representation in

    this device is in form of

    magnetic polarisation e.g.NS for 1, EW for 0

    Optical device Such as Compact disks

    which has pits

    Th data in a compact disk

    is represented in form of pits

    to identify on and off.

    The large pit represents 1

    and small pit represents off.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    20/72

    DATA TYPESNUMBERINGSYSTEMS

    Conversion to and from the binary system

    The binary system (binary code) is an arithmeticsystem uses only digits 0 and 1 to represent all

    numbers.

    In our normal counting one we have reached thelast single digit,

    We increase the second digit by one and reset thesingle digit to 0.

    The same happens to binary For example show below the Binary representation

    of the first ten counting numbers:

    Four volunteers please

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    21/72

    DATA TYPESNUMBERINGSYSTEMS

    Conversion to and from the binary system

    Base of two(2) binary system, Base two means each unit from right to left is two to the

    power of;

    Starting from a power of zero, one, two, three...

    Investigate this with your calculator;

    Draw up a table as follows and calculate the answerbelow;

    27 26 25 24 23 22 21 2027 26 25 24 23 22 21 20

    128 64 32 16 8 4 2 1

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    22/72

    DATA TYPESNUMBERINGSYSTEMS

    Conversion to and from the binary system

    Using the above table, workout how you would represent your birthdate in binary given;

    the day as one number (8 bit)

    The month as one number (8bit) and

    The year as one number (10 bit)

    What is the maximum number of bits required to store the day for anygiven birthday?

    What is the maximum number of bits required to store the month forany given birthday?

    What is the maximum number of bits required to store the year for anygiven birthday within one century from today?

    27 26 25 24 23 22 21 20

    128 64 32 16 8 4 2 1

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    23/72

    DATA TYPESNUMBERINGSYSTEMS

    Conversion to and from the binary system

    Decimal numbers to binary: Division Method

    The division method is the practically the best way to

    convert any numbers into binary system.

    The number that is to be converted is divided by twoand then the answer from the division will be againdivide by 2 and so on until you reach to 0.

    As you are dividing the number to be converted intobinary;\

    The reminder of each step of division is written in R column,

    that will be ether 0 or 1.

    When there is no reminder then it is 0

    When there is then thats 1

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    24/72

    DATA TYPESNUMBERINGSYSTEMS

    Conversion to and from the binary system

    Try the decimal number of 102

    Convert the followingdecimal values to binary;

    63, 75, 457, 985, 135, 642, 314

    Number(dec)

    Remainder(bin)

    102 R

    Number(dec)

    Remainder(bin)

    102 R

    51 0

    25 1

    12 1

    6 0

    3 0

    1 1

    0 1

    1 1 0 0 1 1 0

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    25/72

    DATA TYPESNUMBERINGSYSTEMS

    Conversion to and from the Octal numberSystem

    The octal number system is based on eight digitsto represent the number (base 8),

    which is used to convert into binary number of

    0,1,2,3,4,5,6,7.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    26/72

    DATA TYPESNUMBERINGSYSTEMS

    Conversion to and from the Octal numberSystem

    This system of conversion is easier when numbersare converted into binary and then using thesebinary number convert it to Octal

    This system of conversion requires binary to be

    grouped into three equal groups by placing zerosin front of the binary numbers, so that it can bedivided into three equal groups.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    27/72

    DATA TYPESNUMBERINGSYSTEMS

    Conversion to and from the Octal numberSystem

    Converting the number 102:

    Decimal Number 102

    Binary Number 1100110

    Tri-GroupedBinary Number

    001 100 110

    Pad the binary numberwith two zeros so all sets in

    groups of three.

    Binary (Dec/Oct)Number

    001 1. One

    010 2. Two

    011 3. Three

    100 4. Four

    101 5. Five

    110 6. Six

    111 7. Seven

    =146 (OCT)

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    28/72

    DATA TYPESNUMBERINGSYSTEMS

    Conversion to and from the Octal number System

    Convert the following decimal values (that you previouslyconverted to binary) into octal;

    63, 75, 457, 985, 135, 642, 314

    Remember

    Convert to tri-grouped binary (pad where necessary)

    Take each groups value and sequence together.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    29/72

    DATA TYPESNUMBERINGSYSTEMS

    Conversion to and from the hexadecimal number System

    Base- 16 number system (Hexadecimal)

    In a hexadecimal 16 numbers are used to represent each

    digit. This represents the values stored within a computer byte in

    two halves (four bits).

    The four groups that hexadecimal binary system is divide iscalled nibble.

    The hexadecimal has sixteen different combinations of 0s

    and 1s. It also uses the letters A to F to represent some ofthe digits.

    To calculate the hexadecimal number we have to addzeros or delete zeros in front of the binary number so thatthe binary number can be divided into equal groups of four

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    30/72

    DATA TYPES

    Conversion to and from the hexadecimalnumber System

    So lets take the decimal value of 102,

    Which is 1 1 0 0 1 1 0, in binary and 146 in Octal

    And convert it to a Hexadecimal value...

    S

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    31/72

    SG SYSTEMS

    Conversion to and from thehexadecimal number System

    Convert 102 (dec) toHexadecimal...

    Decimal Number 102

    Binary Number 1100110

    Quad-GroupedBinary Number

    0110 0110

    Pad the binary numberwith a zero so all sets in

    groups of four or as a

    Binary (Dec/Oct)Number

    0001 1. One

    0010 2. Two

    0011 3. Three

    0100 4. Four

    0101 5. Five

    0110 6. Six

    0111 7. Seven

    1000 8. Eight

    1001 9. Nine

    1010 A. Ten

    1011 B. Eleven1100 C. Twelve

    1101 D. Thirteen

    1110 E. Fourteen

    1111 F. Fifteen

    =66(HEX)

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    32/72

    DATA TYPESNUMBERINGSYSTEMS

    Conversion to and from the Octal number System

    Convert the following decimal values (that you previouslyconverted to binary and octal) into Hexadecimal;

    63, 75, 457, 985, 135, 642, 314

    Remember

    Convert to quad-grouped binary (pad where necessary)

    Take each groups value and sequence together.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    33/72

    DATA TYPESNUMBERINGSYSTEMS

    Data TypesNumbering SystemsData Representation Summary

    One digit in a binary number is called a bit.

    There are 8 bits when grouped together is called a byte.

    We have to reverse the process in order to convert the base16 numbers in a hexadecimal into base 10 numbers.

    The process of calculating base 10 numbers using the base16 numbers:

    HEX number is 66

    So, a base 10 number is equal to the sum of each digit value X 16to the power of the digit place value.

    66(HEX) = 6 x 161 + 6 x 160(DEC)

    = 102 (DEC)

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    34/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

    When programming its really important to declare allvariables that you want to use in a program.

    A variable declaration includes the following:

    Data typeIdentifying the type of data that the variable will store.

    Identifiervariables name.

    InitialisationAn assigned value (optional dependant on language).

    TerminationA character used to represent the end of thedeclaration (Language and case dependant),

    In C++, all lines end in ;

    In Python, functions and other structures require a : to indicate the endof the declaration.

    Variables are named memory locations that your programs canbe used to store values

    A constant in programming is a hard coded value it can be anumber, character, string etc, in order for it to change the codemust be changed.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    35/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

    Data and instructions are stored in a computer system as strings of binary digits.

    Different programming languages have different keywords for each of these basic types.

    For instance, in C++, it's string

    while in Java it's String

    Data types can be categorised into variable or constant. The constant data type is the one that cannot be changed once the program has been

    compiled unless you modify the program

    Many languages require that you declare variables before you use them.

    A declaration specifies the data type and the name of the variable.

    In C++;

    int number = 0 // In C++ the data type must be declared by stating it before thevariable, because of this it is not necessary to initialise, assign the value tothe variable.

    In Python

    number = 0 # In Python, the compiler interprets the data type by the initialassignment it has been given, that is why it is necessary to initialise,assign the value to the variable.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    36/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

    Abstract data types

    The structures defining properties that are

    independent of the computer system being storedand used.

    Abstract data structures can be categorised intotwo forms:

    Simple data type

    Structured data type

    DATA TYPES REPRESENTATION OF

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    37/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

    Simple data types;

    Data Type Description Storage Requirements Python Example

    Boolean Can store and hold one

    of only two conditionssuch astrue or false

    Can be as small as a

    processor storing a bit ina single register

    Character Represents a singleAlphanumeric value, e.g.A or 8. Numbers storedare as characters sohave NO mathematical

    value other than theirencoded value(e.g. ASCII)

    One byte in primarystorage,gives max 256 differentcharacters within oneset.

    charVar = A

    charVar = 8

    String A sequence of characters, either as a literalconstant or as some kindof variable.

    A byte is stored for eachcharacter in the string,most languages allowstrings to use a variableamount of memory for

    string storage throughthe use of dynamicmemory allocation.

    StrVar = My String

    strVar = 1 2 3 4 5 6 7 8

    Integer This is a numerical datatype. It rangers from + to-, that is known as twocompliments

    Stored as two bytes(sixteen bits)Unsigned:

    From 0 to 65,535 [2161]

    Signed(Two compliment):

    From 32,768 to 32,767,

    [(215) to 2151]

    intVar = 65352

    intVar = -32124

    Floating point/real This is designed to Stored in two parts as an floVar = 0.124

    http://en.wikipedia.org/wiki/30000_(number)http://en.wikipedia.org/wiki/30000_(number)
  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    38/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

    Structured Data Types;

    Structured data type configuration in acollective way offers a convenient way ofrepresenting data that is to be stored ,

    The structured data types called:

    Arrays

    Records

    The arrays and records overcomes the problem ofidentifying each item that needs to be processed,

    The structured representation of data allows a

    logical relationship by using the same identifier.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    39/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

    Structured Data Types;

    Arrays & Lists

    An array is a list of similar variables and each of the likevariables is called an array element.

    The declaration of the array variables is done by assigningthe list of elements within square brackets;

    Python

    myList = [item0, item1, item2, item3]

    This example is a list of four elements that are string datatypes.

    An arrays & lists can be thought of a number of separatestorage locations arranged pattern.

    Arrays & lists are used to store multiple data items of thesame type.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    40/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

    Structured Data Types;

    Array Vs List

    Arrays & lists have many similar features however;

    Array will be set to a maximum size from firstinitialisation,

    Lists are dynamic and their size is mutable(changeable)

    In most languages arrays are easier to setup and useprior to learning the use of dynamic memory,

    However Python does all of this for you,

    so we jump into the use of lists over arrays as they are quitesimilar but have that distinct advantage over arrays.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    41/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

    Structured Data Types;

    Records (Struct/class type)

    A record consists of a number of data items, called

    fields which maybe logically linked.

    An array of records gives a programmer the

    opportunity to create large databases with a

    structure that is easily represented on paper.

    A record is a custom made data type by theprogrammer, and consists of a variety of simple or

    even structured data types.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    42/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    43/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

    Structured Data Types;

    Files

    A file is normally categorised as the source whichhas collection of data held in different forms.

    These files they have records and moreover they

    have fields.

    The logical relationship between files in a database

    management system allow users to create program

    linking files using one or fields.

    These are the report generators that are linked

    through different fields and records.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    44/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

    Characters Represented as Numbers

    ASCII

    American Standard Code for Information Interchange

    Character-encoding scheme originally based on the English

    alphabet that encodes 128 specified characters; Numbers 0-9,

    Letters a-z and A-Z,

    Basic punctuation symbols,

    Some control codes that originated with Teletypemachines,

    Blank space

    into the 7-bit binary integers.

    ASCII codes represent text in computers, communicationsequipment, and other devices that use text.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    45/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

    Characters Represented as Numbers

    ASCII

    Most modern character-encoding schemes are based onASCII, though they support many additional characters.

    ASCII its self is an outdated model,

    Character encoding methods used in modern dayinclude;

    MS Windows-1252

    Other types of Extended ASCII.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    46/72

    DATA TYPESREPRESENTATION OFDATA & INSTRUCTION

    Characters Represented as Numbers

    ASCII

    Encode your full name in;

    Binary, Octal, Decimal, and Hexadecimal.

    Using manual methods discussed previously!

    Given that the

    Binary Value for A is 0100 0001 (65 Dec)

    Binary Value for B is 0100 0010 (66Dec)

    Binary value for a is 0110 0001 (97 Dec)

    Binary value for is 0010 0000 (32 Dec)

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    47/72

    STRUCTURED ALGORITHMS

    8.2.1

    Defining and understanding the problem,Planning and designing software solutions

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    48/72

    STRUCTURED ALGORITHMS

    Algorithm

    An algorithm is the common way of performingcertain task.

    It involves step by step procedures of solving problemthat requires certain number of steps and couldrequire some repetition of those procedures.

    It helps in determining the design of the solution bybreaking down the problem into manageable steps.

    Algorithm is widely used in activities of our daily life's

    such as when driving, cooking with recipes, building,paying fees etc

    All the activities stated above has the definite solutionand the procedure in performing those task

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    49/72

    STRUCTURED ALGORITHMS

    Algorithm

    For algorithm to work in all situations, the steps must bewritten and programmed in a particular sequence or order.

    It is really important that the problem is fully understood.

    When Algorithm has developed it should be tested andchecked against the desired output and if it requires itshould modified or discarded and a new algorithm written.

    It is believed that there is more then one algorithm for aproblem.

    All algorithm should have a start and a single ending.

    It should have input and output structure for data which isdesired to be achieved through the process of finite steps.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    50/72

    STRUCTURED ALGORITHMS

    Algorithm

    There are various ways of representing algorithmdescription.

    Flowcharts

    Pseudocode

    STRUCTURED ALGORITHMS Flow Charts

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    51/72

    STRUCTURED ALGORITHMS Flow Charts Flowcharts are favoured as a

    method of algorithm description,it is easier to follow the structure

    in a pictorial or graphicalmethod.

    In a flow chart you can writesteps you need in diagram form,as a seise of steps connected by

    arrows, which makes it easier tounderstand.

    When reading flowcharts weread the flow of structure fromtop to bottom or left to rightmoving step by step across along

    the flow lines.

    Symbol Purpose

    Terminal;BEGIN/END

    Process,assignment oroperation.

    Subroutine orsubprogram (userdefined orpredefined)

    Decision (IF

    statement)Input/Output

    Data andprogram flow

    structure

    STRUCTURED ALGORITHMS

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    52/72

    STRUCTURED ALGORITHMS

    Flow Charts

    Crash Bandicoot was a game firstreleased in 1996 on the SonyPlayStation. In this game theplayer would collect wampa fruitas they played once 100 wampa

    fruits where collected the numberof players lives would increase byone and the wampa total wouldbe resent to zero.

    Use a flow chart to represent theprocess of determining when a

    new life is earned added andwampa fruits are managed.

    Symbol Purpose

    Terminal;BEGIN/END

    Process,assignment oroperation.

    Subroutine orsubprogram (userdefined orpredefined)

    Decision (IF

    statement)

    Input/Output

    Data andprogram flow

    structure

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    53/72

    STRUCTURED ALGORITHMS

    Pseudocode

    Pseudocode is a very popular method of writing algorithm description.

    It is easily written and modified using word process.

    The keywords are highlighted in Capital letters or bold type to emphasis them andto indicate the type of action being performed

    Pseudocode allows us to focus on the logical detail of the problem solution withoutgetting hung-up on the syntax rules of a particular programming language.

    This system of writing algorithm do not have uniform method of writing.

    It is written differently by different writers.

    If the Pseudocode is used, it should be written in such a way that any languageprogrammer should able to use it to write programs.

    NOTE::This is how you will write all programming components in an examincluding your HSC!

    You will only start to shy away from this method in examination once you reachUniversity, However you will still be expected to use it in your reporting for assignmentsand major project documentation.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    54/72

    STRUCTURED ALGORITHMS

    Pseudocode

    The flow control in Pseudocode is always from topto down.

    The keywords are grouped in pairs for example;

    For every BEGIN there is an END

    For every IF there is an ENDIF

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    55/72

    STRUCTURED ALGORITHMS

    Pseudocode

    Convert the flowchart you have created for CrashBandicoot into pseudocode.

    Remember we start with one

    BEGIN and finish with one END

    All key words are capitalised

    and paired (have a termination).

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    56/72

    STRUCTURED ALGORITHMS

    Control Structures

    Structured programming is a method of breakinga program into logical sections.

    Algorithms are composed of standard constructsor control structures, which are the building blocksof an algorithm

    In developing a structured program, aprogrammer uses a method of algorithmdescription using three basic structures.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    57/72

    STRUCTURED ALGORITHMS

    Control Structures

    Sequence

    Selection

    Repetition

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    58/72

    STRUCTURED ALGORITHMS

    Control Structures

    Sequence

    Is the order in which the steps are executed.

    in Pseudocode and flowchart the steps are placedbetween BEGIN and END.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    59/72

    STRUCTURED ALGORITHMS

    Control Structures

    Selection

    Is the feature of computer to make logical decisions, thatdetermines which particular step to be executed out of

    many steps Using selection, a condition such as a question is given.

    Then depending on the answer, different paths are followed.

    The key words are IFTHEN..ELSE are used for binary selection,whereas the condition after the IF keyword.

    There are two possible solution for the IF either true or false

    When the IF condition applies then program should execute the

    THEN keyword.

    When the IF is false the program will skip to the next step ignoringthe THEN condition and finishes the binary selection with theENDIF

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    60/72

    STRUCTURED ALGORITHMS

    Control Structures

    Repetition

    This loop structure that allows the steps to berepeated until the some condition is satisfied.

    Also known as Iteration.

    In a repetition control structure its very important

    that each loop contains a condition to stop and

    going forever. Its important to test the condition at the beginning

    and/or end.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    61/72

    STRUCTURED ALGORITHMS

    Control Structures

    Repetition

    Pre-test repetition

    This is also referred to as guarded loop, which is tested at a verybeginning.

    Keywords used in pseudocode are WHILEENDWHILE.

    The condition is stated after WHILE key and the loop is inbetween WHILE AND ENDWHILE key.

    Post-test repetition

    This is also referred to as unguarded loop, which is tested at a

    end of the loop after the steps to be repeated are executed.

    Keywords used in pseudocode are REPEAT..UNTIL.

    The body of the loop to be executed is placed underneathREPEAT and the post-test repetition the condition is after UNTIL.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    62/72

    STRUCTURED ALGORITHMS

    Control Structures

    Repetition

    Pre-test repetition Consider the example below

    Pseudocode;

    BEGIN

    WHILE travelling on the train

    buy ticket

    END WHILE

    END

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    63/72

    STRUCTURED ALGORITHMS

    Control Structures

    Repetition

    Post-test repetition Consider the example below

    Pseudocode ;

    BEGIN

    REPEAT

    wear black shoes to school

    UNTIL its a sports day

    END

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    64/72

    STRUCTURED ALGORITHMS

    Control Structures

    Repetition

    Countered loop Programs often needs to execute a set of steps a

    predetermined number of times.

    In this case, a counted loop using the construction:

    For identifier goes from value_1 to value_2 Nextidentifier

    This is also known as definite loop.

    When programming its important to initialise theloop control variable.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    65/72

    STRUCTURED ALGORITHMS

    Control Structures

    Repetition

    Countered loop

    Consider an algorithm to display numbers 1 through 20;

    Pseudocode;

    BEGIN

    set end to 20

    Set counter to 1

    WHILE counter is less than or equal to

    print counter

    increment counter by one

    ENDWHILE

    END

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    66/72

    STRUCTURED ALGORITHMS

    Checking Algorithms

    Its crucial to check the algorithm description stepsability to solve the problem.

    This process of checking is known as deskchecking

    This involves the process of checking the following:

    Values of the variables

    Outputs of the algorithm

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    67/72

    STRUCTURED ALGORITHMS

    Checking Algorithms; Desk Checking

    The process of checking is done using the sampledata and this data items are classified as testdata.

    While checking its important to keep recordingprogress.

    STRUCTURED ALGORITHMS

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    68/72

    Desk Checking Algorithms

    Pseudo-code: Pythagoras Theorem.

    BEGIN

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    69/72

    STRUCTURED ALGORITHMS

    DESK CHECKING ALGORITHMS;

    BEGIN

    PRINT Length of side A

    SET sideA TO USER_INPUT

    PRINT Length of side B

    SET sideB TO USER_INPUT

    SET sqSideC TO sideA*sideA + sideB*sideB

    SET sideC to square root of sqSideC

    PRINT Length of Side C is AND sideC

    ENDLine SideA SideB sqSideC sideC Input Output

    1 Length of side A

    2 3 3

    3 3 Length of side B

    4 3 4 4

    5 3 4 25

    6 3 4 25 5

    7 3 4 25 5 Length of Side C is 5

    STRUCTURED ALGORITHMS

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    70/72

    Desk Checking Algorithms;

    Desk check the algorithm you created for Crash Bandicoot.

    Design a algorithm, using flowcharts and pseudocode that takes each of the

    student, one at a time and determines their final grade. Given that

    Exam one was out of 50 marks

    Assignment One was out of 60 marks

    Assignment two was out of 60 marks and

    Final Exam was out of 100 marks

    Once you have designed your algorithm, desk check it to ensure it isfunctional.

    Once your algorithm has been checked and is perfect, you may code it.

    For this program; Write the purpose,

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    71/72

    STRUCTURED

    ALGORITHMS

    e e pu pose,

    Write the expectations of the final program,

    i.e that it calculates each mark correctly and weights them appropriately with no error infinal grades.

    Draw an IPO Chart and table for the proposed program.

    Create a data dictionary for the proposed program.

    Use a hierarchical diagram to illustrate the structure and proposeddevelopment approach to developing the program.

    Define each function (subroutine of the program).

    Draw a flowchart of the main program and each subroutine of the program.

    Translate the flowchart into pseudo-code

    Desk check the algorithm written in pseudo-code.

    Implement you algorithm using Python.

    Test your code

    Evaluate your program against the initial purpose and expectations.

  • 7/27/2019 8.2.1 Defining and Understanding the Problem and Planning and Designing Software Solutions

    72/72

    END!

    8.2.1DEFINING AND UNDERSTANDING THE

    PROBLEM,

    PLANNING AND DESIGNINGSOFTWARE SOLUTIONS