by eturo
Programming a computer is
both a creative activity and a process structured by rules. Computers are programmed
or given instruction, through the use of programming languages, so to
program a computer, one must learn a programming language.
What is a computer program?
·
is a collection or set of directions that tell
the computer exactly what to do;
·
it is the medium used to communicate with the
computer;
·
can be written in many programming languages; and
·
they are designed and written by computer
programmers
What is a programming language?
Learning
a programming language has similarities to learning a natural language, such as
English or Spanish or Japanese. Natural languages have a lexicon, a syntax,
and a semantics. The lexicon is the vocabulary and
punctuation. The rules of syntax
dictate how the lexicon can be ordered to form correct sentences. The semantics conveys the meaning when the
chosen words are combined in the chosen syntax of each sentence. The semantics
changes, sometimes in subtle ways, depending on both the words chosen and the
sentence syntax.
So
too, a programming language has lexical
elements, a syntax, and a semantics.
- Lexical elements – are comprised of keywords in the programming language, symbols such as arithmetic operators or parenthesis or braces, and words denoting identifiers by which we can name what is being operated upon
- Syntax – specifies precise rules for how the lexical elements are ordered to form correct language statements and programs
- Semantics – is the meaning of the constructed language statements
Therefore, a programming
language are languages for specifying sequences of directions or
instructions for the computer
Two Types of Programming Languages
1. High - level languages
·
they
allow specification of program instructions in a manner closer to natural
languages, but without the ambiguity and lack of precision
·
rely
on Graphical User Interface (GUI)
featuring symbolic icons and drag-and-drop technique and uses English-like
statement
·
software
written on one computer could be used on another; programmers could work on
different computers without having to learn a new assembly
·
e.g. C, C++, Java, Visual
Basic, Visual Basic.Net. C#
2. Low - level languages
·
it
is only capable of executing exceedingly primitive instructions known as the machine language
·
uses
mnemonic code / symbols
·
e.g. Assembly Language
Classification of Programming Languages
1. Procedural - procedures are expressed
as specific algorithms. Each procedure to be executed by the computer is
written, one instruction at a time.
COBOL
(Common Business Oriented Language), C, Fortran (Formula Translation), Pascal
2. Functional - process steps are
expressed by composition of basic functions (list processing.
Lisp (
list - processing language)
3. Logic - relations are defined by basic logic formulas
(inferential processing).
ProLog (
Programming for Logic)
4. Object-Oriented - operation is conducted
by objects which integrate the data and their processing.
Java, C++, Smalltalk
Language Translators
·
translates
programs written in a variety of programming languages into machine language
codes.
Three
Types of Language Translator:
1.
Compiler – a computer program that translates
high level language into machine language at only one time. This is used mainly
by high-level languages.
2.
Interpreter – a computer program that translates
high level language into machine language one line at a time. This is used
mainly by high-level languages.
3.
Assembler – a computer program that translates
assembly language into machine language at only one time. This is used mainly by
low-level languages.
Problem
Solving through Programming
Programming
is about solving problems. Regardless of the language used, this
activity proceeds through a set of well-defined stages during the development
of the program.
- Some Tools in Problem Solving in Programming
·
Algorithm - sequence of steps in
solving a problem; list of instructions for carrying out some process step by
step
·
Pseudocode - English-like step-by-step description of the solution
·
Flowchart - a diagram representing the logical sequence which
a combination of steps or operations is to be performed; consists of labeled
geometrical symbols that are interconnected to provide a pictorial
representation of a data processing procedure; visual representation of an
algorithm
Symbols
|
Symbol
Name and Definition
|
parallelogram |
INPUT/OUTPUT represents an instruction to an
input or an output device
|
rectangle |
PROCESSING represents a group of program
instructions that perform a processing function of the program
|
diamond |
DECISION denotes point in the program where
more than one path can be taken
|
hexagon |
PREPARATION
represents
instructions that will alter, or modify a program’s course of execution
(initialization)
|
oval |
TERMINAL
used designate the
beginning and end of program, or a point of interruption
|
rectangle with 2 predefined vertical bars |
PREDEFINED
PROCESS represents
a named operation or programmed step not explicitly detailed in the program
flowchart; can be used when a procedure needs to be repeated several times
|
small circle |
ON-PAGE
CONNECTOR used to
connect one part of a flowchart to another without drawing flow lines within
same page
|
small pentagon |
OFF-PAGE
CONNECTOR used to
designate entry to or exit from a page when it require more than one page
|
lines with arrowhead |
FLOW
LINES & DIRECTION INDICATORS used
to show reading sequence in which flowchart symbols are to be read
|
- Steps in Problem Solving through Programming
Design.
In
the design stage, a careful problem statement is articulated, indicating the
desired outcomes of the program. The problem statement is then refined by
listing a set of steps designed to accomplish the goal. The set of steps is
called an algorithm, and may
be presented in English or in some other appropriate notation. The design stage
does not require the use of a computer.
Edit.
In
the edit stage, a program is created in a text editor and stored in one or more
files on disk. These files are known as the program source code.
Compile.
During
the compile stage, the compiler translates the program source code in the
source file(s) into the machine code appropriate for the machine on which the
program will execute.
Execute.
The
execute stage is the time when the compiled program is loaded from disk into
its execution environment and the machine carries out the instructions.