Professional Documents
Culture Documents
B351F (2021) L02 Business Programming
B351F (2021) L02 Business Programming
Learning Objectives
Discuss the contents in program specifications.
Explain the concepts of structured programming and program constructs.
Describe popular truth tables for NOT, OR, AND, XOR.
Develop the skills in converting system process (or program) flow into Pseudocodes and Flowcharts.
Explain the concepts of modular program designs.
Compare and contrast different program testing methods.
Describe the procedures to write a program.
Self-Test 2-1
Search for a sample of program specification from the Internet. Analyze the common contents found
from the program specification document.
1
BIA B351F L02 Business Programming
2. Structured Programming and Program Constructs
In structured programming, the program is divided into small parts (procedures or functions) and each part
performs a specific job. The main importance is on functions rather than data. The same data can be used
and manipulated by several procedures/functions and such type of data is made global.
All programming language utilize program constructs. In imperative languages they are used to control the
order (flow) in which statements are executed (or not executed). There are a number of recognized basic
programming constructs that can be classified as follows:
Sequence controls (sequence logic or sequential structures)
Selection controls (selection logic or conditional flow)
Repetition controls (iteration logic or looping)
1. Sequence controls – If nothing is specified then the program statements (or codes) would be executed
one by one (from top to bottom / from left to right) in a sequential order.
Algorithm:
Statement 1
Statement 2
:
Statement n
2. Selection controls – These structures implement the logic called conditional structures. The conditional
structures can be divided into following categories:
Single IF Algorithm
IF-THEN-ELSE Algorithm:
2
BIA B351F L02 Business Programming
Nested IF Algorithm:
IF Condition 1 applies, THEN
Statement 1
ELSE IF Condition 2 applies, THEN
Statement 2
:
ELSE IF Condition n applies, THEN
Statement n
ELSE
Default Statement
END IF
DO REPEAT
Statement 1
Statement 2
:
UNTIL Condition not applies
Self-Test 2-2
What are program constructs? Use a drawing tool to show their characteristics.
3. Truth Tables
A truth table is a mathematical table used to determine if a compound statement is true or false.
Operator Precedence Action Example
NOT 1 Not NOT X
AND 2 All conditions must be TRUE X AND Y
OR 3 At least one condition is TRUE X OR Y
XOR, (Exclusive OR) 4 Inputs differ outputs TRUE X XOR Y
EQV (logical equivalence) 5 Same Inputs TRUE outputs X EQV Y
IMP 6 FALSE iff the first TRUE, the second FALSE X IMP Y
3
BIA B351F L02 Business Programming
IMP(lies) operator works as both a logical and bitwise arithmetic operator. It returns FALSE (0) iff its
first operand is TRUE (non-zero) and the second operand is FALSE.
The IMP operator is used when you want to limit access to a certain "privilege".
For example, if you have a swimming pool but you don't want anyone entering it when the guard is not
present. So you let Q=Guard is Present and P=Pool is accessible. If Q is false (guard is not there), the
formula (P IMP Q) will always be false, ensuring safety of pool users.
Conditions
Condition of X F F T T
Condition of Y F T F T
NOT X T T F F
X AND Y F F F T
X OR Y F T T T
X XOR Y F T T F
X EQV Y T F F T
X IMP Y T T F T
Some Equivalence Laws of Propositional Logic
Let ∧ be logical AND, ∨ be logical OR. ¬ be logical NOT
(P ∧ Q) ∨ R ≡ (P ∨ R) ∧ (Q ∨ R) (P ∨ Q) ∧ R ≡ (P ∧ R) ∨ (Q ∧ R) Distributivity
P∨P≡P P∧P≡P Idempotency
P∨Q≡Q∨P P∧Q≡Q∧P Commutativity
P ∨ (Q ∨ R) ≡ (P ∨ Q) ∨ R P ∧ (Q ∧ R) ≡ (P ∧ Q) ∧ R Associativity
P ∨ Q ≡ ¬ (¬P ∧ ¬ Q) P ∧ Q ≡ ¬ (¬P ∨ ¬Q) De Morgan
P ∨ true ≡ true P ∧ true ≡ P
true ∨ P ≡ true true ∧ P ≡ P
P ∨ false ≡ P P ∧ false ≡ false
false ∨ P ≡ P false ∧ P ≡ false
¬ ¬P ≡ P Q ≡ ¬ ¬Q Double negative
Self-Test 2-3
Develop truth tables in Excel worksheet to prove:
(a) P AND Q ≡ NOT (NOT P OR NOT Q) // De Morgan’s law
(b) P OR Q ≡ NOT (NOT P AND NOT Q) // De Morgan’s law
(c) X EQV Y ≡ (X IMP Y) and (Y IMP X), if and only if conditions
(d) X IMP Y ≡ (NOT X) OR Y, if X then Y or X implies Y
A B C D E F G H A B C D E F G H
1 P Q P and Q ~P ~Q (~P or ~Q) ~(~P or ~Q) 7 P Q P or Q ~P ~Q (~P and ~Q) ~(~P and ~Q)
2 TRUE TRUE TRUE FALSE FALSE FALSE TRUE 8 TRUE TRUE TRUE FALSE FALSE FALSE TRUE
3 TRUE FALSE FALSE FALSE TRUE TRUE FALSE 9 TRUE FALSE TRUE FALSE TRUE FALSE TRUE
4 FALSE TRUE FALSE TRUE FALSE TRUE FALSE 10 FALSE TRUE TRUE TRUE FALSE FALSE TRUE
5 FALSE FALSE FALSE TRUE TRUE TRUE FALSE 11 FALSE FALSE FALSE TRUE TRUE TRUE FALSE
J K L M N O P J K L M N O P
1 X Y X EQV Y X IMP Y Y IMP X (X IMP Y) and (Y IMP X) 7 X Y X IMP Y ~X Y ~X or Y
2 TRUE TRUE TRUE TRUE TRUE TRUE 8 TRUE TRUE TRUE FALSE TRUE TRUE
3 TRUE FALSE FALSE FALSE TRUE FALSE 9 TRUE FALSE FALSE FALSE FALSE FALSE
4 FALSE TRUE FALSE TRUE FALSE FALSE 10 FALSE TRUE TRUE TRUE TRUE TRUE
5 FALSE FALSE TRUE TRUE TRUE TRUE 11 FALSE FALSE TRUE TRUE FALSE TRUE
4
BIA B351F L02 Business Programming
This is NO standard syntax for pseudocode, as a program in pseudocode is not an executable
program
Flowcharts could be thought of as a graphical alternative to pseudocodes or an algorithm.
Advantages of Pseudocode: reduced complexity, increased flexibility, ease of understanding
Structured English is very similar to Pseudo code, but it tends not to use so many mathematical symbols.
Often people start with Structured English, convert it to Pseudo Code and then write Executable Code.
Structured English Pseudocode Executable Code (VBA)
BEGIN
BEGIN Dim name As String
READ name
INPUT name name = InputBox ("Your name is?")
IF name EQUAL "Harry" THEN
IF name == "Harry" THEN IF name = "Harry" THEN
WRITE "Why don't you marry
OUTPUT "Why don't you marry Pippa?" Debug.Print("Why don't _
Pippa?"
ELSE & you marry Pippa?")
ELSE
OUTPUT "Are you Royal enough?" ELSE
WRITE "Are you Royal enough?"
END IF Debgug.Print("Are you _
END IF & Royal enough?")
END
END End if
All statements showing "dependency" are to be indented. These include: WHILE, DO, FOR, IF,
SWITCH, SUB, FUNCUION, PROCEDURE, …
Do not include data declarations in pseudocode.
Pseudocode (general) Pseudocode (VBA-like Code)
READ name, hourlyRate, hoursWorked, Rate SET total TO 0
grossPay = hourlyRate * hoursWorked SET grade counter TO 1
deduction = grossPay * Rate WHILE grade counter <= 10
netPay = grossPay – deduction INPUT the next grade
WRITE name, grossPay, deduction, netPay ADD the grade INTO the total
END WHILE
SET class average TO total divided by 10
PRINT class average.
IF HoursWorked > NormalMaximum THEN WHILE Total < Limit
DISPLAY overtime message COMPUTE Total AS Total + Births - Deaths
ELSE END WHILE
DISPLAY regular time message
ENDIF
IF student's grade >= 40 FOR counter = 0 to 100 step 2
PRINT "Passed" SET sum as sum + counter
ELSE NEXT
PRINT "Failed" PRINT sum
END IF
Flowcharts are written with program flow from the top of a page to the bottom. Each command is placed in
a box of the appropriate shape, and arrows are used to direct program flow. A flowchart can therefore be
used to:
o Define and analyze processes
o Build a step-by-step picture of the process for analysis, discussion, or communication
o Define, standardize or find areas for improvement in a process
The following shapes are often used in flowcharts:
5
BIA B351F L02 Business Programming
Self-Test 2-4
State the major differences between Pseudocode and Flowchart.
5. Modular Program Design
Modular programming is the process of sub-dividing a computer program into independent, interchangeable
modules (or sub-programs / procedures / subroutines / functions).
Modular programming has a main module and many auxiliary modules. The main module is compiled as an
executable (EXE), which calls the auxiliary module functions. Auxiliary modules exist as separate
executable files, which load when the main EXE runs. Each module has a unique name assigned in the
PROGRAM statement. Function names across modules should be unique for easy access if functions used
by the main module must be exported.
6
BIA B351F L02 Business Programming
Modules in modular programming enforce
logical boundaries between components and
improve maintainability.
They are incorporated through interfaces.
They are designed in such a way as to minimize
dependencies between different modules.
Teams can develop modules separately and do
not require knowledge of all modules in the
system.
Object-oriented programming (OOP) is
compatible with the modular programming
concept to a large extent.
Modular programming enables multiple
programmers to divide up the work and
debug pieces of the program independently.
Modular components could be classes, methods,
blocks of codes, or even calls to classes that are
external of the program.
6. Program testing
Functional Testing – is the type of testing done against the business requirements of application. It is a black
box type of testing.
Unit testing – Testing of individual software components or modules. Typically done by the
programmer and not by testers, as it requires detailed knowledge of the internal program design and
code. It may require developing test driver modules or test harnesses.
Integration testing – Testing of integrated modules to verify combined functionality after integration.
Modules are typically code modules, individual applications, client and server applications on a
network, etc. This type of testing is especially relevant to client/server and distributed systems.
System testing – Entire system is tested as per the requirements. Black-box type testing that is based
on overall requirements specifications, covers all combined parts of a system.
Acceptance testing -Normally this type of testing is done to verify if system meets the customer
specified requirements. User or customer do this testing to determine whether to accept application.
7
BIA B351F L02 Business Programming
Non-functional testing is the testing of a program application or system for its non-functional requirements:
the way a system operates, rather than specific behaviours of that system.
Performance testing – although this term often used interchangeably with ‘stress’ and ‘load’ testing,
they have different scopes of testing. Performance Testing is measuring how a system behaves under
an increasing load (both numbers of users and data volumes), Load Testing is verifying that the
system can operate at the required response times when subjected to its expected load, and Stress
Testing is finding the failure point(s) in the system when the tested load exceeds that which it can
support. All these tests are designed to check whether system meets performance requirements.
Security testing – Can system be penetrated by any hacking way. Testing how well the system
protects against unauthorized internal or external access. Checked if system, database is safe from
external attacks.
Usability testing – User-friendliness check. Application flow is tested, Can new user understand the
application easily, Proper help documented whenever user stuck at any point. Basically system
navigation is checked in this testing.
Compatibility testing – Testing how well software performs in a particular
hardware/software/operating system/network environment and different combination s of above.
Self-Test 2-6
What are the major differences between functional and non-functional testing in programming? Give
some examples for each testing approach.
8
BIA B351F L02 Business Programming
Note:
Algorithm – a clear and unambiguous specification of steps needed to solve a problem. Algorithm
should be correct and efficient.
Pseudocode – expresses computer actions using keywords and depicts logic structures using
indentation.
Control structures (Sequence, Selection and Repetition) – a standard progression of logical steps to
control the sequence of statement execution.
Self-Test 2-7
What are the major differences between Algoritm and Pseudocode? What are the three major errors in
programming?
8. Revision Question
1. Write a set of pseudocodes to sum the first 50 odd integers.
2. Write pseudo code that will perform the following. (a) Read in 5 separate numbers. (b) Calculate the
average of the five numbers. (c) Find the smallest (minimum) and largest (maximum) of the five
entered numbers. (d) Write out the results found from steps (b) and (c) with a message describing
what they are.
3. Draw a flowchart to show the maximum value of three input numbers.
4. Discuss the advantages and disadvantages of modular program design.
5. Distinguish between unit test and integration test. What is a stress test in programming? Why does it
so important for software development?
6. What are the outputs of these VBA code fragments?
Sub logic()
Dim a As Integer
Dim b As Integer
a = 10
b = -10
Debug.Print "a = " & a, "b = " & b
If a <> 0 Or b <> 0 Then
Debug.Print ("OR Operator Result is : True")
Else
Debug.Print ("OR Operator Result is : False")
End If