Time Card Example No-function condition—null ELSE The no-function condition is represented by enclosing the key-word ELSE in parentheses.
Sample Problem 3.1 Payroll Problem Compute the pay for an employee. Regular pay will be computed as hours (through 40) times rate. Overtime pay (1.5 times hours times rate) for all hours worked over 40.
Character-String Constant The following information would be output as a result of 3 being input and the WRITE statement: Designate character-string by enclosing it in single or double quotation marks, distinguishing it from a variable name. If we included the variable name CODE within the quotation marks:
Character-String Constant Assign the value of a character-string constant to a variable by means of a statement. Use a character-string constant in a decision statement. Compared to the letter D. Compared to the value of the variable D.
Sample Problem 3.4 Sales Problem The commission rate is based on two factors, the amount of sales and the class to which the sales person belongs.
Problem (Adding Six Numbers) Preparation symbol An operation performed on data in preparation for a major sequence of operations. Initialization step. Accumulator A variable holding the sum of a group of values. Counter is a special type of accumulator. Adds or accumulates by a constant amount. Partial sum—ACCUM is used to hold the sum of the numbers so far.
The DOWHILE Loop Connector symbol A collector at the beginning of the loop. DOWHILE Loop Leading-decision program loop The test to determine whether the loop should be executed or exited is encountered immediately upon entering the loop. If the tested condition is not true the first time it is tested, the remaining steps in the loop are not executed at all.
The DOWHILE Loop Properly formed DOWHILE loop: Place the loop test before any other step within the loop (leading decision). Place the loop steps in the YES path of the loop test. Indicated that the loop will exit in the NO path of the loop test.
Counter-Controlled Loops Counter-controlled loop The algorithm clearly shows the number of times the loop steps will be done. The loop is controlled by a counter. The number of times the loop will be executed is known or preset. COUNT is often referred to as the loop control variable.
Header Record Logic Header record logic A more flexible approach to loop control The number of loop iterations can vary with each program execution. Header record Specifies how many additional input records will follow.
Payroll with Header Record Problem: Sample Problem 4.1 (Payroll) including a header record. Input record contains the number of employees.
Payroll Problem with Header Record (Flowchart)
Payroll Problem with Header Record (Flowchart) cont.
Payroll Problem with Header Record (Pseudocode)
Averaging Problem with Header Record Problem: The number of individual scores that must be added will depend on the number of assignments completed.
Averaging Problem with Header Record (Flowchart)
Averaging Problem with Header Record (Flowchart) cont.
Averaging Problem with Header Record (Pseudocode)
The No-Data Condition What if N is less than or equal to 0? No path will be taken immediately. The step following involves a division by N. A division by 0 will be the result.
Averaging Problem with No-Data Test (Flowchart)
Averaging Problem with No-Data Test (Flowchart) cont.
Averaging Problem with No-Data Test (Pseudocode)
Proper Programs Any solution algorithm can be expressed using the three basic patterns of logic. SIMPLE SEQUENCE IFTHENELSE DOWHILE
Proper Programs Building-block concept Each basic pattern is characterized by a single point of entrance and a single point of exit. Contained patterns are nested. A solution algorithm should have only one entry point and only one exit point. A program that can be viewed as a single statement is called a proper program. The algorithms presented thus far are all examples of proper programs.
Enrichment Visual Basic Graphical user interface for the problem involving the addition of six numbers.
Enrichment If the user clicks the Cancel button instead of the OK button, no value will be assigned to decNumber. This could cause an error. If the user enters a non-numeric value in the input box, another type of error may occur.