Full Transcript

IT210 – INFORMATION TECHNOLOGY FUNDAMENTALS Program Design Objectives Describe the steps in the program development process. Introduce algorithms and pseudocode. Describe program data. 2 Steps in program development...

IT210 – INFORMATION TECHNOLOGY FUNDAMENTALS Program Design Objectives Describe the steps in the program development process. Introduce algorithms and pseudocode. Describe program data. 2 Steps in program development 3 Steps in program development 1. Define the problem into three separate components: Inputs. Outputs. Processing steps to produce required outputs. 4 Steps in program development 2. Outline the solution.  Decompose the problem to smaller steps.  Establish a solution outline.  Initial outline may include:  major processing steps involved  major subtasks  user interface  major control structures  major variable and data structures  mainline logic 5 Steps in program development 3. Develop the outline into an algorithm.  The solution outline is now expanded into an algorithm.  What is an algorithm? – a set of precise steps that describe exactly the tasks to be performed and the order in which they are to be carried out.  Pseudocode or f lowchart will be used to represent the solution algorithm. 6 Example Print selected student records: Design a program to read a file of different types of student records (e.g. S, U) and print out the student's number, name, and address who have ‘S’ records. 7 Example ( 1 of 3) Defining diagram: Input Processing Output ‘S’ records Print handling Handling line Number Read student records Selected student records Name Select ‘S’ records Number Address Print selected records Name Age Address Gender Attendance_pattern ‘U’ records 8 Example (2 of 3) Control structures required: 1. We need a loop, a DOWHILE should work. 2. We need a selection to test for which type of records. Of course, that will be an IF statement. 9 Example ( 3 of 3 ) Solution algorithm 10 Steps in program development 4. Test the algorithm for correctness.  Very important in the development of a program, but often forgotten  Major logic errors can be detected and corrected at an early stage  Go through the algorithm step-by-step with test data to ensure the program will do what it is supposed to do. 11 Steps in program development 5. Code the algorithm into a specific programming language. – Start to code the program into a chosen programming language design after all considerations from Steps 1–4 are met. 12 Steps in program development 6. Run the program on the computer.  This step uses a program compiler and programmer- designed test data to machine-test the code for:  syntax errors  logic errors 13 Steps in program development 7. Document and maintain the program. – Is an ongoing task from the initial definition of the problem to the final test 14 Steps in program development 15 AN INTRODUCTION TO ALGORITHMS AND PSEUDOCODE 16 Program data  Variable, constants and literals  A variable is a value stored in memory cells that may change or vary as the program executes.  A constant is a data item with a name and a value that remains the same during the execution of the program.  A literal value is any part of a statement or expression that is to be used exactly as it is, rather than as a variable or a Lingo element 17 Program data Data types can be: Elementary data items Contains a single variable that is always treated as a unit (classified into data types) Data structures An aggregate of other data items. The data items that it contains are its components. Data is grouped together in a particular way, which ref lects the situation with which the program is concerned. Most common are record, file, array and string 18 Program data  When designing an algorithm, a programmer must introduce some unique names which represents variables or objects in the problem.  Names should be meaningful.  Names should be transparent to adequately describe variables (Number1, number2, etc.).  When using more than one word, most programming language does not tolerate a space in a variable as space would signal the end of a variable name. Instead:  Underscore c a n be used (sales_tax or word_count).  Another method is to use capital letters as a word separator (salesTax or wordCount). 19 Program data  Data should always undergo a validation check before it is processed by a program.  Examples:  Correct type  Correct range  Correct length… 20 An introduction to algorithms and pseudocode  What is an algorithm?  Lists the steps involved in accomplishing a task (like a recipe)  Defined in programming terms as ‘a set of detailed and ordered instructions developed to describe the processes necessary to produce the desired output from a given input’  An algorithm must :  Be coherent, precise and unambiguous  Be general, Give the correct solution in all cases and used for different inputs  Be correct, and it must solve the problem for which it is designed  Execute and terminate in a finite amount of time  Be efficient enough so that it can solve the intended problem using the resource currently available on the computer  An algorithm can be represented by a pseudo-code or a f lowchart 21 An introduction to algorithms and pseudocode  What is pseudocode?  Structured English (formalized and abbreviated to look like high- level computer language) 22 How to write pseudocode There are six basic computer operations: 1. A computer can receive information 2. A computer can put out information 3. A computer can perform arithmetic 4. A computer can assign a value to a variable or memory location 5. A computer can compare two variables and select one of two alternate actions 6. A computer can repeat a group of actions 23 How to write pseudocode 1. A computer can receive information  The verbs Read, Get, Prompt, Input are used in pseudocode when a computer is required to receive information. Examples: Read name Get name Read number1, number2 24 How to write pseudocode 2. A computer can put out information  The verbs Print, Write, Put, Output or Display are used in pseudocode when a computer is required to supply information or output to a device. Examples: Print name Write "The average is", avg 25 How to write pseudocode 3. A computer can perform arithmetic A mathematical calculation using either mathematical symbols or the words for those symbols. For example, Add number to total OR Total = Total + number The following symbols can be written in pseudocode + or Add - or Subtract * or Multiply / or Divide () for Parentheses 26 How to write pseudocode  Orders of operation – Applies to pseudocode and to most computer languages – First operation carried out will be any calculations contained with parentheses 27 How to write pseudocode 4. A computer can assign a value to a variable or memory location.  Two cases of writing pseudocode to assign a value to a variable: 1. The verbs Initialise or Set are used to give data an initial value in pseudocode. 2. Symbols ‘’ or = are used to assign a value as a result of some processing. Examples on assign or give variable an initial value: Initialize total to zero Set count to 0 Examples on assign a computed value to a variable: Total = Price + Tax 28 How to write pseudocode 5. A computer can compare two variables and select one of two alternate actions.  To represent this operation in pseudocode, special keywords are used: IF, THEN and ELSE  The comparison of data is established in the IF clause  The choice of alternatives is determined by the THEN or ELSE options 29 How to write pseudocode 6. A computer can repeat a group of actions  When there is a sequence of processing steps that need to be repeated, two special keywords are used, DOWHILE and ENDDO  The condition for the repetition of a group of actions is established in the DOWHILE clause  The keyword ENDDO acts as a delimiter. As soon as the condition for the repetition is found false, control passes to the next statement after the ENDDO 30 The Structure Theorem  There are three basic control structures 1. Sequence 2. Selection 3. Repetition 31 The Structure Theorem 1. Sequence  Straightforward execution of one processing step after another  Represents the first four basic computer operations 1. Receive information 2. Put out information 3. Perform arithmetic 4. Assign values 32 The Structure Theorem A typical sequence statement in an algorithm might read: Add 1 to pageCount Print heading line1 Print heading line2 Set lineCount to zero Read customer record These instructions illustrate the sequence control structure as a straightforward list of steps written one after the other, in a top-to-bottom fashion 33 The Structure Theorem 2. Selection  Presentation of a condition and the choice between two actions, the choice depending on whether the condition is true or false  Represents the decision-making abilities of the computer  Illustrates the fifth basic computer operation – compare two variables and select one of two alternate actions 34 The Structure Theorem In pseudocode, selection is represented by the keywords IF, THEN, ELSE and ENDIF IF condition p is true THEN statement(s) in true case ELSE statement(s) in false case ENDIF If condition p is true, then the statement in true case will be executed, and the statement in the false case will be skipped (vice versa) 35 The Structure Theorem 3. Repetition  Presentation of a set of instruction to be performed repeatedly, as long as the condition is true  Block statement is executed again and again until a terminating condition occurs  Illustrates the sixth basic computer operation – to repeat a group of actions. 36 The Structure Theorem Written in pseudocode as: DOWHILE condition p is true statement block ENDDO  DOWHILE is a leading decision loop – condition is tested before any statements are executed  ENDDO triggers a return of control to the retesting of the condition  Condition is true, statements are repeated until condition is found false 37 Pre-programming phase: Flowchart  Drawing the Program Flowcharts – Flowchart is the graphic representations of the individual steps or actions to implement a particular module. – The f lowchart can be likened to the blueprint of a building. An architect draws a blueprint before beginning construction on a building, so the programmer draws a f lowchart before writing program. – Flowchart is independent of any programming language. – Flowchart is the logical design of a program. – It is the basis from which the actual program code is developed. – Flowchart serves as documentation for computer program. – The f lowchart must be drawn according to definite rules and utilizes standard symbols adopted internationally. 38 Pre-programming phase Flowchart 39 Pre-programming phase Flowchart 40 Example of flowchart 41 Advantages & Disadvantages Flowchart Advantages: Pseudocode Advantages ✓ Standardized ✓ Easily modified ✓ Visual ✓ Implements structured concepts ✓ Done easily on Word Processor Flowchart Disadvantages: ✓ Hard to modify ✓ Structured design elements not implemented Pseudocode Disadvantages: ✓ Special software required ✓ Not visual ✓ No accepted standard, varies from company to company 42

Use Quizgecko on...
Browser
Browser