Steps in Program Development
Steps in Program Development
Steps in Program Development
Introduction to VBA
Data and Information
Data are raw facts
Examples of data include transactions, dates,
amounts, etc.
Information are data that have been processed into
a usable form
Information includes tables, documents, charts, etc.
Goal of computer applications is to process data
into information
2
Six Basic Computer Operations
1. A computer can receive (input) data
2. A computer can store data in memory
3. A computer can perform arithmetic and manipulate
text strings
4. A computer can compare the contents of two
memory locations and select one of two alternatives
5. A computer can repeat a group of operations
6. A computer can output information (processed data)
3
Computer Operations
4
Programs and Programming
A program is a very specific set of rules that
tell the computer which switches should be
"ON" or "OFF".
The process of creating a program is called
programming.
The computer only knows what it is told
through programs, so they must be accurate
and very specific.
5
What is Programming?
Deciding if there is a task to be accomplished or problem to be
solved using a computer, e.g., is there a need for a program?
Determining the nature of the task or problem, e.g., what must the
program do?
Developing a plan that will accomplish the task or solve the
problem, e.g., generating the step-by-step process that the
program will follow (algorithm).
Converting the plan into a computer language program
Testing the program to ensure it accomplishes task or solves
problem defined earlier.
Implementing the program to accomplish the task or solve the
problem.
6
Types of Computer Languages
Procedural: Monolithic programs that run from start to finish
with no intervention from user other than input
Basic, QBasic, QuickBasic
COBOL
FORTRAN
C
Object Oriented/Event Driven (OOED): Programs that use
objects which respond to events; use small segments to
code for each object
JAVA
Visual Basic
Visual Basic for Applications (VBA)
Visual C++
7
Levels of Computer
Languages
Low Level: at the level of the computer, i.e., in binary (0-1)
format Computer can only execute a binary form of a program
Intermediate Level: close to the computer but uses English
words or mnemonics, e.g., Assembler, that is converted
directly into binary
High Level: at the level of the programmer using English words
and clearly defined syntax; must be converted or translated
into binary for computer to implement it, e.g., VBA
8
Translating from High-level
Language to Binary
9
Total = 0 10111000
Current = 100 101110001 00000000
do while current <> 0 Translation 01100100
Total = Total + Current 00000001 11001000
Current = Current - 1 Program 01001001
Loop 01110101 11111011
10
Steps in Program Development
Outputs
Defining Diagram
Compile
Correct syntax errors
Run program with test data
Correct logic errors
Document and Maintain
Program
On-going task
Comments within program – very important in Java
Structure charts
Solution Algorithm
Test data results
Maintenance often done by other programmers. If program
well designed, code will be easier to maintain
Introduction to Algorithms and
Pseudocode
Algorithm –lists steps in accomplishing a
task
Lucid, precise, unambiguous
Give correct solution in all cases
Eventually end
Example of Algorithm
Turn on calculator
Clear calculator
Repeat the following instructions
Key in dollar amount
19
What is Pseudocode?
Variables
Name given to collection of memory cells
designed to store a particular data item
Variable because value stored in that variable
may change as program executes
Program Data (continued)
Constant
Data item with a name and a value that remain
the same during program execution.
The name Fifty may be given to a data item that
will always contain the value 50
Program Data (continued)
Literal
A constant whose name is the written
representation of it’s value
For example the program may contain the literal
’50’
Program Data (continued)
Data Structures
An aggregate of other data items
Data is grouped together in a particular way
Record- a collection of data items or fields hat
bear some relationship to each other. For
example a student record may contain student
number, name address, etc
Program Data (continued)
37
OOED Programming Process
A six step process for writing an OOED computer program:
1. Define problem.
2. Create interface
3. Develop logic for action objects
4. Write and test code for action objects
5. Test overall project
6. Document project in writing
38
Step One: Define Problem
Before you can create a computer application to solve a
problem, you must first clearly define it.
This may involve a study of the problem to understand the
inputs and outputs.
Must identify the data to be input to the program and the results
to be output from it.
Sketching an interface is a good way to understand the
problem and to communicate your understanding to other
people.
Denote input and output objects as well as action objects--
those for which code (instructions) are needed.
39
Sketch of Calculate Revenue Interface
40
Step Two: Create Interface
41
Calculate Revenue Interface - Input
42
Calculate Revenue Interface -
Output
43
Step Three: Develop Logic for Action
Objects
Need to think about what each action object should
do in response to an event
This is the logic for each object
Use Input/Processing/Output (IPO) Tables and
Pseudocode to develop the logic
IPO Tables show the inputs, outputs, and the
processing to convert inputs into outputs
44
IPO Table for Calculate Revnue Button
Quantity Sold
45
Pseudocode for Count High Values Button
Begin procedure
Input Selling Price
Input Quantity Sold
Revenue = Selling Price x Quantity Sold
Output Revenue
End procedure
46
Step Four: Write and Test Code of
Action Objects
Once you learn the vocabulary and syntax of a language,
you should be able to convert the logic embodied in the
pseudocode into a computer language. In our case, we use
VBA.
You need to test each code for each action object as they
are created.
Once the object code is written, the programmer must test
and correct it. This stage is referred to as debugging, since
it involves removing "bugs".
Use test data for which you know the correct answer to test
the object code.
47
VBA Code for Calculate Revenue Button
Sub CalculateRevenue()
Dim unitPrice As Currency
Dim quantitySold As Integer
Dim revenue As Currency
48
Step Five: Test Overall Project
49
Step Six: Document Project in Writing
Documentation includes the pictorial and written
descriptions of the software. It contains internal
descriptions of programming commands and
external descriptions and instructions.
Documentation is necessary since, sooner or later,
the program will need to be maintained (correct
bugs, add new features, handle problems not
thought of previously, etc. This is NOT possible
without documentation.
Written documentation includes books, manuals,
and pamphlets that give instructions on software
use and discuss the objectives and logic of the
software.
50
Risks in Numerical Computing
Almost all computer calculations involve
round off error (limited precision error)
If not monitored and planned for carefully,
such errors can lead to unexpected and
catastrophic results
Ariane 5 Rocket Failure
Patriot Missile Failure during Gulf War
The Explosion of the Ariane 5
Back
Patriot Missile Failure during Gulf War
During the Gulf War, an American Patriot Missile battery in Saudi Arabia, failed to track
and intercept an incoming Iraqi Scud missile. The Scud struck an American Army barracks,
killing 28 soldiers and injuring around 100 other people.
The General Accounting office reported on the cause of the failure. It turns out that the cause
was an inaccurate calculation due to computer arithmetic errors.
The time in tenths of second as measured by the system's internal clock was multiplied by
1/10 to produce the time in seconds.
The value 1/10, which has a non-terminating binary expansion, was chopped at 24 bits. The
small chopping error, when multiplied by the large number giving the time in tenths of a
second, led to a significant error. Indeed, the Patriot battery had been up around 100 hours,
and an easy calculation shows that the resulting time error due to the magnified chopping
error was about 0.34 seconds. (The number 1/10 equals 1/2 4+1/25+1/28+1/29+1/212+1/213+....
A Scud travels at about 1,676 meters per second, and so travels more than half a kilometer in
this time. This was far enough that the incoming Scud was outside the "range gate" that the
Patriot tracked.
Back