Program Development Cycle and Logic Gates

  • Program Development Cycle Stages: Analysis, Design, Coding, Testing, and Maintenance. This chapter focuses on Analysis, Design, Coding, and Testing. These stages are crucial for creating efficient and reliable software.

Analysis
  • Defining the Problem: Clearly defining the problem and setting requirements for anyone working on the solution. This involves understanding the user's needs and the system's constraints.

  • Requirements Specification: Detailing what the program needs to provide. This specification should be comprehensive and unambiguous.

    • Abstraction: Keeping key elements required for problem-solving and discarding unnecessary details (e.g., maps for transportation). Abstraction helps in focusing on the essential aspects of the problem.

    • Decomposition: Breaking down complex problems into smaller, manageable parts (e.g., getting dressed broken down into selecting items, removing clothes, and putting items on). Decomposition simplifies the problem-solving process.

Design
  • Program Specification: Translating program specification to show how the program should be developed. This involves creating a detailed plan of the software.

  • Programmer Knowledge: Understanding tasks, performance, and task interaction. A programmer's expertise is vital for effective design.

  • Formal Documentation: Use of structure charts, flowcharts, and pseudocode. These tools help in visualizing and documenting the design process.

Coding and Iterative Testing
  • Program Development: Writing individual modules using a suitable programming language. The choice of language depends on the project's requirements.

  • Iterative Testing: Conducting modular tests, amending code, and repeating tests until the module works as required. This process ensures that each module functions correctly.

Testing
  • Comprehensive Testing: Running the completed program or set of programs multiple times with different sets of test data. This ensures the program's robustness and reliability.

  • Task Verification: Ensuring all completed tasks work together as specified in the program design. Integration testing is crucial for system-wide functionality.

Computer Systems, Sub-Systems, and Decomposition
  • Computer System Components: Software, data, hardware, communications, and people. These components must work together seamlessly.

  • Sub-systems: Division of a computer system into smaller sub-systems. This division allows for easier management and development.

  • Single Action: Further division into sub-systems until each performs a single action. This ensures that each sub-system is focused and efficient.

Top-Down Design
  • Modular Construction: Using top-down design to produce structure diagrams. This approach helps in organizing the system hierarchically.

  • Sub-routines: Developing each sub-system as a sub-routine. Sub-routines promote code reusability and maintainability.

  • Flowcharts/Pseudocode: Representing how each sub-routine works. These tools aid in understanding the logic of each sub-routine.

Stepwise Refinement
  • Breaking down a computer system into manageable sub-systems to solve a problem efficiently. This approach simplifies complex problems.

  • Stepwise Refinement: Breaking down system into set of sub-systems

Benefits of Structured Approach
  • Independent Development: Allows multiple programmers to work independently on sub-systems. This speeds up the development process.

  • Reduces Time: Shortens development and testing time.

Decomposing a Problem
  • Component parts of a computer system

    • Inputs: Data needed to be entered into the system while it is active.

    • Processes: Tasks performed using input data and stored data.

    • Outputs: Information displayed/printed for users.

    • Storage: Data stored in files for future use.

  • Examples: Alarm App

    • Inputs: Time, remove a time, switch off/snooze

    • Processes: Check if the current time matches an alarm time, alarms on/off, manages snooze

    • Outputs: Sound at alarm/snooze time

    • Storage: Time(s) for alarms set

Methods for Solution Design
  • Rigorous Design: Solutions need to be designed and developed rigorously.

  • Formal Methods: Clearly showing the process for understanding the proposed solution

Structure Diagrams
  • Diagrammatic Form: Shows top-down design in a diagram.

  • Hierarchical: Illustrates how a solution is divided into sub-systems.

  • Alarm app main functions: Setting the alarm, checking for the alarm time, sounding the alarm.

Flowcharts
  • Diagrammatical Steps: Showing steps required to complete a task in sequence.

  • Algorithms: Steps and their order.

  • Communication: Effectively demonstrating how a system/sub-system works.

Flowchart Symbols
  • Terminator Symbols: For the beginning and end of each flowchart. (START, STOP)

  • Process Symbols: Showing actions.

  • Input and Output: Input of data and output of information.

  • Decision Symbols: Deciding which action to take next (selection/repetition). Two outputs.

  • Flow Lines: Arrows showing direction of flow.

  • Concert ticket sales example calculating cost: Tickets at $20, discount for 10/20 tickets, no more than 25 tickets.

Pseudocode
  • Simple Method: Showing an algorithm with English keywords.

  • Data Item Names: Meaningful names similar to variables/constants.

  • No Strict Syntax: Not bound by programming language rules.

Consistent Writing
  • Readable Pseudocode: Matching IGCSE Computer Science syllabus.

  • Non-proportional font.

  • Keywords in capital letters.

  • Data item and subroutine names start with a capital letter.

  • Indentation for conditional and loop statements (two spaces).

Assignment Statements
  • Cost10Cost \leftarrow 10

  • PriceCost2Price \leftarrow Cost * 2

  • TaxPrice0.12Tax \leftarrow Price * 0.12

  • SellingPricePrice+TaxSellingPrice \leftarrow Price + Tax

  • Gender \leftarrow \"M\"

  • ChosenFalseChosen \leftarrow False

Mathematical Operators
  • Addition: +

  • Subtraction: −

  • Multiplication: *

  • Division: /

  • Raise to the power: ^

  • Group: ( )

Conditional Statements
  • Decision making based on variable values.

  • Two main types:

    • IF…THEN…ELSE…ENDIF: For true/false conditions.

    • CASE OF…OTHERWISE…ENDCASE: For multiple different values.

    • Example of IF condition: If age < 18, output \"Child\", else output \"Adult\".

Different ways to assign IF Conditions
  • Boolean variables (TRUE or FALSE).

  • Comparisons using comparison operators.

  • Nested IF Statements: An IF statement within another IF statement.

Comparison Operators
  • Greater than: >

  • Less than: <

  • Equal: =

  • Greater than or equal: >=

  • Less than or equal: <=

  • Not equal: <>

  • Both: AND

  • Either: OR

  • Not: NOT

CASE Statements
  • Variable value decides path.

  • OTHERWISE for all other values.

  • ENDCASE marks end of the statement.

Iteration
  • Repeating actions in an algorithm.

  • Three types of loop structures:

  • FOR…TO…NEXT: Set number of repetitions.

  • REPEAT…UNTIL: Completed at least once.

  • WHILE…DO…ENDWHILE: May never be completed.

  • FOR loop is better as it is managed automatically.

FOR…TO…NEXT Loops
  • A variable is set up, with a start value and an end value

  • Increment steps of one until the end value is reached

  • For reading values into lists of known lengths

REPEAT…UNTIL Loops
  • Not known repetitions

  • Actions are repeated until a condition becomes true

  • Completed at least once

WHILE…DO…ENDWHILE Loops
  • Actions are only repeated WHILE a condition is true

  • Condition is untrue = actions are never performed

  • Condition tested at the start of the loop.

Input and Output
  • Data entry and display of information.

  • INPUT and OUTPUT, READ and PRINT.

Algorithm Purpose
  • Sets out the steps to complete a task

  • Typically shown as flowchart or pseudocode

Standard Methods of Solution
  • Repeat existing methods.

  • Totalling: keeping subtotal

  • Counting: keep count on the number of times action is performed

  • Finding maximum, minimum, and average (mean) values

  • Searching using a linear search

  • Sorting using a bubble sort.

Validation and Verification
  • Data inputs should be reasonable and accurate before being accepted by the system

  • Two different methods used: validation, verification

Validation
  • Automated program checks to be reasonable

  • if data is rejected = message should state what that is

Types of Validation Checks
  • Range checks - upper and lower end values entered

  • Length checks - length of password

  • Type checks- is a entry a whole number

  • Presence checks- has a email address entered

  • Format checks- must follow a character form

  • Check digits- last digit calculated using all other digits in the code (detects errors and omissions)

Verification
  • Checking data copied correctly from the source

  • Double entry- both checked and must be the same

  • Screen/ visual check- completed by user

Test Data
  • To know if a solution is working as it should (tested before fully used)

  • Algorithms in pseudocode or flowcharts need testing

  • Computer programs can be tested by running data and looking for results

  • Different sets of test data may be used

  • A set = all items of data required to work in a solution

  • Set of test data should be used that the program would work normally with

  • Solution: program should not do wrong (should not be wrong)

  • Abnormal test data should be rejected

  • Extreme data: largest and smallest values normal data can take

  • Boundary data: establish largest and smallest values, two values are required - one value accepted and one rejected

Trace Tables
  • Used to record results and algorithms

  • Helps find out the purpose of algorithms

  • Each item values should be entered each time it changes

Identify Errors in Algorithms
  • This can be done by checking if the variable total identifies all the smallest number 110

The negative number can be tested if it works

Writing and Amending Algorithms
  • Problem is clearly identified

  • Break the problem into sub-problems

  • How is data stored and obtained (stored permanently?)

  • Design the structure = structure diagram

  • Construct an algorithm using

Abstract Data Types (ADTs)
  • An ADT is a collection of data and a set of operations on that data

  • Stack: list contains several items following the FILO principal

  • Queue: List contains serial items operating FIFO principal

Logic Gates
  • Logic gates take binary inputs and produce a binary output

  • Logic gates combined together form logic circuits

  • Output form a logic gate/circuit is done with a truth table

  • Six gates considered: (NOT, AND, OR, NAND, NOR, XOR)

Logic Gate Symbols
  • NOT gate = One input (output is only high if input is low)

  • AND gate = (Both inputs have to be positive for output to be positive)

  • OR gate =

  • NAND gate =

  • NOR gate =

  • XOR gate =

Truth Tables
  • NOT gate = only one input

  • The possible inputs in a truth table, can have three, four, inputs:

  • Number of possible binary combinations, is a multiple of the number 2 (every case)

NOT gates (1 input):

Output high (1) is the input/s are low only\

Q=AQ = \overline{A}