Anda di halaman 1dari 4

LESSON 1: INTRODUCTION TO PROGRAMMING CONCEPTS

Levels (Generations) of Programming Languages


Programming languages may be divided into four general types:
1. Machine Languages (1st Generation Languages)
2. Assembly Languages (2nd Generation Languages)
3. High-level Languages (3rd Generation Languages)
4. Fourth-generation Languages

Machine language is the “natural language” of a particular computer. It consists of a series of


1s and 0s that instruct the computer to perform its functions. Machine language programming
proved error-proned and tedious. This led to the use of assembly languages (English-like
abbreviations) to program the computer. Translator programs called assemblers were developed
to convert assembly language programs to machine language. The following assembly language
program segment adds the interest to deposit and stores the result in totalinvestment:

LOAD DEPOSIT
ADD INTEREST
STORE TOTALINVESTMENT

The simplest of tasks in assembly language required too many instructions to be accomplished.
In seeking a solution, high-level languages (HLLs) were developed in which single English-like
statements could be written to accomplish multiple tasks. Translator programs called compilers
were developed to convert high-level language programs into machine language. The program
segment written above is coded below using high-level language format:

TOTALINVESTMENT = DEPOSIT + INTEREST

BASIC, Pascal, and C/C++ are examples of high-level languages.

Developing business applications using high-level languages proved to be very difficult and
tedious. To solve this problem, Fourth-generation languages (4GLs) were developed. They
provide a window-based programmer interface and wizards that allow for the rapid creation of
database tables, forms and reports. Visual FoxPro® and Access® are examples of 4GLs.

CaFSET (Antigua) Office Workbook. Written by Richard and Jessie Lewis © 2009 by CaFSET (Antigua) 267
Introduction to Programming Lesson 1: Introduction to Programming Concepts

Problem Partitioning
Problem partitioning is the process of dividing a problem into input, processing, and output. Let
us look at a programming problem that accepts two numbers, adds them, and prints the total.
This problem is partitioned as follows:

Input Processing Output


number1 Accept number1 total
number2 Accept number2
Add the two numbers
Print the total

The following example calculates and prints the average of three (3) scores for a student. The
problem is partitioned as follows:

Input Processing Output


score1 Accept score1 average
score2 Accept score2
score3 Accept score3
Add scores
Find average
Print average

Variables and Data Types


A variable represents a data storage location in the computer’s memory in which a value can be
stored. Variables in a program must be declared. At the time of declaration, a data type must be
specified. The data type (e.g., integer, character, floating point/real) indicates the type of data to
be stored in the variable. A constant is a variable that has been assigned a preset value.

Algorithms
An algorithm is a series of instructions that are executed in a specific order. Specifying the order
in which statements are to be executed in a computer program is called program control. An
algorithm can be represented using pseudocode or flowcharts.

The syntax of an algorithm or a program refers to the characters, signs or symbols which are
combined to produce a program statement. The semantics of an algorithm or a program refer to
the meaning derived from the combination of characters, signs or symbols.

Pseudocode
Pseudocode is an informal language (using everyday English) that programmers use to develop
algorithms. Pseudocode is not an actual programming language and as such cannot be executed
by the computer. The algorithm must be converted to a language such as C++ or Pascal.

Data Input and Output


Output Statement
The PRINT command is used to formulate output statements. For example, to prompt the user to
enter a number, you write the statement:

CaFSET (Antigua) Office Workbook. Written by Richard and Jessie Lewis © 2009 by CaFSET (Antigua) 268
Introduction to Programming Lesson 1: Introduction to Programming Concepts

Print (“Please enter a number: ”)

Input Statement
The READ command is one of the statements used to accept data from the user. For example, to
accept or store a number, you write the statement:

Read (number)

The following example shows the Print and Read statements in use:

Print (“Please enter a number: ”)


Read (number)
Print (number)

The last statement prints the value stored in the variable “number”.

Flowcharts
A flowchart is a graphical representation of an algorithm. Flowcharts are used to show data flow
through a series of symbols and lines showing directional flow. Flowcharts are used in program
design to illustrate the logic of the program. The main flowchart symbols are:

Represents a process or an activity

Input or Output of data

Decision, where a condition is evaluated and the course of action will


depend on the result of the evaluation

Data flow lines

Connector (used to break a data flow line that flows to another page)

Start or End of a program

Let us use a flowchart to outline the steps in solving a simple programming problem.

Problem: Accept two numbers from the user (A and B), and print “Numbers are equal” if A
is equal to B. Otherwise, print “Numbers are not equal”. Using a flowchart, give
a solution for this problem.

CaFSET (Antigua) Office Workbook. Written by Richard and Jessie Lewis © 2009 by CaFSET (Antigua) 269
Introduction to Programming Lesson 1: Introduction to Programming Concepts

The flowchart solution is shown below:

Start

Prompt and
Input A, B

True
If A = B

False

Output
“Numbers are
not equal”

Output
“Numbers are
equal”

End

Operators used in Programming


Relational Operators Arithmetic Operators
< Less than + Plus
> Greater than - Minus
<= Less than or equal to / Division
>= Greater than or equal to * Multiplication
<> or != Not equal to

Operators are used with operands. 9 * 7 has two operands (9 and 7) and one operator (*).

Logical Operators
&& AND
|| OR
! NOT

CaFSET (Antigua) Office Workbook. Written by Richard and Jessie Lewis © 2009 by CaFSET (Antigua) 270

Anda mungkin juga menyukai