Professional Documents
Culture Documents
Programming
Fundamentals
CHAPTER OUTLINE
ALGORITHMS AND SYNTAX
VARIABLES AND DATA TYPE
OPERATORS
EXPRESSING PROGRAM ALGORITHMS
INTRODUCTION
Chapter Objectives
At the end of the chapter, the
student should be able to:
read program algorithms and
syntax;
declare variables with specific
data types and scopes;
use different operators in writing
program statements; and
create flowcharts in expressing
program algorithms.
2
ALGORITHMS AND SYNTAX
Algorithm
An algorithm is a specific step-by-step
solution to a particular problem.
An algorithm can be a single line of
code or combinations of lines.
Computer responds based on the
predetermined instructions that is
contained in the algorithm.
If an event falls outside the algorithm,
either there would be no response or an
error would occur in the computer
system.
ALGORITHMS AND SYNTAX
Program Statement
A line of code in a Visual Basic program and serves as
basic sensible unit of an algorithm.
A statement is any combination of Visual BASIC
keywords, properties, object names, variables,
numbers, special symbols and other values that
collectively create a valid instruction recognized by the
Visual Basic compiler.
Example:
End
Label1.Text = TimeOfDay
MessageBox.Show("Hello " & txtName.Text & "!")
ALGORITHMS AND SYNTAX
Syntax
The rules of construction that must be used to build
program statements are called statements syntax
Example (Declaring a variable):
Example: If Value = 8
Step-by-step solution:
1. Obtain the input temperature in degrees Celsius from the user;
2. If the input is a valid number then compute the Kelvin value by
adding 273.15 to the input temperature. If not, ask the user for
another input;
3. Display the computed value to the user.
EXPRESSING PROGRAM ALGORITHMS
Pseudocode
An informal code that combines both the natural
language and a programming language.
Example (Kelvin to degrees celsius converter):
[Accept Input]
If [input] >= - 273.15 Then
[Add 273.15 to input]
Else
[Ask for another value]
End If
EXPRESSING PROGRAM ALGORITHMS
Flowcharts
Flowchart is a
graphical
representation of an
algorithmto define its
logical flow.
It illustrates the steps
of an algorithm by
using different kinds
of boxes which are
ordered by
connecting them with
arrows (shown on the
right).
EXPRESSING PROGRAM ALGORITHMS
Flowcharts
The algorithm for a
Celsius-To-Kelvin program
can be expressed as:
EXPRESSING PROGRAM ALGORITHMS
Sample Program
btnConvert txtCelsius
txtKelvin
EXPRESSING PROGRAM ALGORITHMS
Sample Program
SUMMARY
Writing program algorithms
follow specific syntax.
One of the basic building blocks
of algorithms is a variable that
is declared with proper data
type and location.
Operators are symbols or
keywords used to process
variables, constants, and
literals into meaningful results.
Flowcharts, using graphics, are
ways of planning and expressing
an algorithm in developing and
presenting program algorithms.
Thank you very much!
Next Chapter:
STRUCTURED PROGRAMMING
Decision/Selection Structure
Repetition Structure