fourth-generation programming language

Download Report

Transcript fourth-generation programming language

FTMK, UTeM – Sem 1 2013/2014
1. Introduction to Computers and Programming Language
BITP 1113 PROGRAMMING TECHNIQUE
1
LEARNING OUTCOMES

At the end of this lecture, you should be able to
 explain
the use of computer programs
 describe what is computer, computer system
components (hardware and software)
 describe what is programs and programming
language
 explain the programming process
2
WHY PROGRAM?
Computer – programmable machine designed to follow
instructions
Program – instructions in computer memory to make it do
something
Programmer – person who writes instructions (programs) to make
computer perform a task
SO, without programmers, no programs; without programs, a
computer cannot do anything
3
MAIN HARDWARE COMPONENT CATEGORIES:
1. Central Processing Unit (CPU)
2. Main Memory
3. Secondary Memory / Storage
4. Input Devices
5. Output Devices
4
MAIN HARDWARE COMPONENT CATEGORIES
5
CENTRAL PROCESSING UNIT (CPU)
Comprised of:
 Control
Unit
 Retrieves
and decodes program instructions
 Coordinates activities of all other parts of computer
 Arithmetic
& Logic Unit
 Hardware
optimized for high-speed numeric calculation
 Hardware designed for true/false, yes/no decisions
6
CPU ORGANIZATION
Figure 1-2
7
THE CPU'S ROLE IN RUNNING A PROGRAM
Cycle through:
 Fetch: get the next program instruction from
main memory

Decode: interpret the instruction and
generate a signal

Execute: route the signal to the appropriate
component to perform an operation
1-8
MAIN MEMORY
Holds both program instructions and data
 It is volatile. Main memory is erased when
program terminates or computer is turned off
 Also called Random Access Memory (RAM)
 Organized as follows:

 bit:
smallest piece of memory. Has values 0 (off,
false) or 1 (on, true)
 byte: 8 consecutive bits. Bytes have addresses.
9
MAIN MEMORY


Addresses – Each byte in memory is identified by a
unique number known as an address.
Bit
8 bits




Byte


Smallest piece of memory
Stands for binary digit
Has values 0 (off) or 1 (on)
0 1
1
0
0
1
1
1
Is 8 consecutive bits
Word


Usually 4 consecutive bytes
Has an address
1 byte
10
MAIN MEMORY
In Figure 1-3, the number 149 is stored in the byte with the address 16, and the
number 72 is stored at address 23.
11
SECONDARY STORAGE
Non-volatile: data retained when program is not
running or computer is turned off
 Comes in a variety of media:

 magnetic:
floppy disk, zip disk, hard drive
 optical: CD-ROM
 Flash drives, connected to the USB port
12
INPUT DEVICES
Devices that send information to the computer
from outside
 Many devices can provide input:

 Keyboard,
mouse, scanner, digital camera,
microphone
 Disk drives and CD-ROM
13
OUTPUT DEVICES
Output is information sent from a computer
program to the outside world.
 The output is sent to an output device
 Many devices can be used for output:

 Computer
monitor and printer
 Floppy, zip disk drives
 Writable CD drives
14
SOFTWARE PROGRAMS THAT RUN ON A
COMPUTER

Operating system software


programs that manage the computer hardware and the
programs that run on the computer
how many programs can run at once?
Single tasking - one program at a time (MS-DOS)
 Multitasking – multiple programs at a time (UNIX, Windows
XP/Vista/7)


how many people can use computer at the same time?
Single user – MS-DOS, early versions of Windows
 Multiuser - UNIX


Application software

programs that provide services to the user.
Ex: word processing, games, programs to solve specific problems
1-15
PROGRAMS AND PROGRAMMING LANGUAGES

A program is a set of instructions that the
computer follows to perform a task

Programming Language is a language used to write

Types of languages
programs

Low-level: used for communication with computer
hardware directly.

High-level: closer to human language
16
PROGRAMMING LANGUAGE
•
A programming language is a machine-readable
artificial language designed to express
computations that can be performed by a
machine, particularly a computer.
•
Programming languages can be used to create
programs that specify the behavior of a
machine, to express algorithms.
•
Many programming languages have their syntax
and semantics.
17
GENERATIONS OF PROGRAMMING LANGUAGE
•
1st Generation: (1950-60) machine language.
•
2nd Generation: (1961-75) assembly language.
•
3rd Generation: (1976-92) high-level programming
languages, such as C, C++, and Java.
4th Generation: (1993-2005) typical high-level
programming languages closer to human
languages.
•
•
5th Generation: (2005-..) used for artificial
intelligence and neural networks.
18
FIRST-GENERATION PROGRAMMING LANGUAGE
•
A first-generation programming language is a
machine-level programming language.
•
No translator was used to compile or assemble the
first-generation language.
•
The main benefit of first-generation programming
language is that the code a user writes can run
very fast and efficiently.
•
It is a lot more difficult to learn than higher
generational programming languages, and it is far
more difficult to edit if errors occur.
19
•
Machine language is an example of 1st G
Language.
•
Sometimes referred to as machine code or object
code.
•
It is a collection of binary digits or bits that the
computer reads and interprets.
20
SECOND-GENERATION PROGRAMMING
LANGUAGE
•
Second-generation programming language is a
generational way to categorize assembly languages.
•
Second-generation programming languages have the
following properties:
• The code can be read and written by a programmer.
To run on a computer it must be converted into a
machine readable form, a process called assembly.
• The language is specific to a particular processor
family and environment.
21
ASSEMBLY LANGUAGE
•
It is an example of 2nd G Language.
•
Assembly languages are a family of low-level languages
for programming computers.
•
It implements a symbolic representation of the
numeric machine codes.
•
Other constants needed to program a particular CPU
architecture.
22
ASSEMBLY LANGUAGE
Assembler
•
Assembler creates object code by translating assembly
instruction mnemonics into opcodes, and by resolving
symbolic names for memory locations and other
entities.
•
Assemblers are generally simpler to write than
compilers for high-level languages.
23
THIRD-GENERATION PROGRAMMING
LANGUAGE
•
The introduction of the compiler in 1952 spurred the
development of third-generation computer languages.
•
These languages enable a programmer to create
program files using commands that are similar to
spoken English.
•
Third-level computer languages have become the
major means of communication between the digital
computer and its user.
•
Such as BASIC, C, FORTAN and Pascal.
24
THIRD-GENERATION PROGRAMMING
LANGUAGE
High-level language
•
3rd G Languages are High-level Languages.
•
After a program is written in one of the high-level
languages, it must be either compiled or interpreted.
25
THIRD-GENERATION PROGRAMMING LANGUAGE
•
A Compiler program rewrites the program into
machine language that the CPU can understand. This
is done all at once and the program is saved in this
new form.
•
A compiled program is generally considerably larger
than the original.
•
An Interpreter program translates the program
statements into machine language one line at a time
as the program is running.
•
An interpreted program will be smaller than a
compiled one but will take longer to execute.
26
FOURTH-GENERATION PROGRAMMING
LANGUAGE
•
A fourth-generation programming language
(1970s-1990) (abbreviated 4GL) is a programming
language or programming environment designed
with a specific purpose in mind, such as the
development of commercial business software.
•
In the evolution of computing, the 4GL followed the
3GL in an upward trend toward higher abstraction
and statement power.
•
The 4GL was followed by efforts to define and use
a 5GL.
27
FOURTH-GENERATION PROGRAMMING
LANGUAGE
•
3GL development methods can be slow and errorprone.
•
Some applications could be developed more
rapidly by adding a higher-level programming
language and methodology which would generate
the equivalent of very complicated 3GL
instructions with fewer errors.
•
All 4GLs are designed to reduce :



programming effort,
the time it takes to develop software and
the cost of software development.
28
FOURTH-GENERATION PROGRAMMING
LANGUAGE
•
Fourth-generation languages have often been
compared to domain-specific programming
languages (DSLs).
•
For example, a typical 4GL command is
FIND ALL RECORDS WHERE NAME IS "SMITH"
29
TYPES OF 4 GL :• Table-driven (codeless) programming, usually running
with runtime framework and libraries. Instead of using code.
• Report generators take a description of the data format
and the report to generate and from that they either generate
the required report directly or they generate a program to
generate the report.
• Data management 4GLs such as SAS, SPSS and Stata
provide sophisticated coding commands for data
manipulation, file reshaping, case selection and data
documentation in the preparation of data for statistical
analysis and reporting.
30
SOME FOURTH-GENERATION LANGUAGES
•
•
•
•
•
•
•
•
FoxPro
PowerBuilder
SQL
Report Builder
Oracle Reports
Graph Talk
MATLAB
CSS
31
EXAMPLES OF 4G LANGUAGES
Database query languages
•
•
•
•
Query languages are computer languages used to
make queries into databases and information
systems.
Query languages can be classified according to
whether they are database query languages or
information retrieval query languages.
SQL is a well known query language for relational
databases.
XQuery is a query language for XML data
sources.
32
FIFTH-GENERATION PROGRAMMING
LANGUAGE
•
Fifth generation computing devices, based on artificial
intelligence, are still in development, though there are
some applications, such as voice recognition, that are
being used today.
•
The use of parallel processing and
superconductors is helping to make artificial
intelligence a reality.
•
The goal of fifth-generation computing is to
develop devices that respond to natural
language input and are capable of learning and
self-organization.
33
FIFTH-GENERATION PROGRAMMING
LANGUAGE
Examples :
Artificial intelligence :
•
The branch of computer science concerned
with making computers behave like humans.
•
There are several programming languages that
are known as AI languages because they are
used almost exclusively for AI applications. The
two most common are LISP and Prolog.
34
FIFTH-GENERATION PROGRAMMING
LANGUAGE
Examples :
Neural network
•
A type of artificial intelligence that attempts to
imitate the way a human brain works.
•
A neural network works by creating connections
between processing elements, the computer
equivalent of neurons.
•
Neural networks are currently used prominently in
voice recognition systems, image recognition
systems, industrial robotics, medical imaging, data
mining and aerospace applications.
35
HOW TO BEGIN TO WRITE A PROGRAM
Example Algorithm for Calculating Gross Pay.
We start with an algorithm, which is a set of well-defined steps.
36
FROM A HIGH-LEVEL PROGRAM TO AN
EXECUTABLE FILE
a)
b)
c)
d)


Create file containing the program with a text editor or Integrated
Development Environment (IDE)
Run preprocessor to convert source file directives to source code
program statements.
Run compiler to convert source program into machine instructions.
Run linker to connect hardware-specific code to machine
instructions, producing an executable file.
Steps b–d are often performed by a single command or button click.
Errors detected at any step will prevent execution of following steps.
37
FROM A HIGH-LEVEL PROGRAM TO AN
EXECUTABLE FILE
Source Code
Object Code
Preprocessor
Linker
Modified
Source Code
Executable Code
Compiler
38
INTEGRATED DEVELOPMENT ENVIRONMENTS
(IDES)
An integrated development environment, or
IDE, combine all the tools needed to write,
compile, and debug a program into a single
software application.
 Examples are Microsoft Visual C++, Borland
C++ Builder, CodeWarrior, etc.

39
INTEGRATED DEVELOPMENT ENVIRONMENTS
(IDES)
40
WHAT IS A PROGRAM MADE OF?

Common elements in programming languages:
 Key
Words
 Programmer-Defined Identifiers
 Operators
 Punctuation
 Syntax
41
EXAMPLE PROGRAM
#include <iostream>
using namespace std;
int main()
{
double num1 = 5,
num2, sum;
num2 = 12;
}
sum = num1 + num2;
cout << "The sum is " << sum;
return 0;
KEY WORDS

Also known as reserved words

Have a special meaning in C++

Can not be used for another purpose

Written using lowercase letters

Examples in program (shown in green):
using namespace std;
int main()
PROGRAMMER-DEFINED IDENTIFIERS

Names made up by the programmer

Not part of the C++ language

Used to represent various things, such as
variables (memory locations)

Example in program (shown in green):
double num1
OPERATORS

Used to perform operations on data

Many types of operators
 Arithmetic:
+, -, *, /
 Assignment: =

Examples in program (shown in green):
num2 = 12;
sum = num1 + num2;
PUNCTUATION

Characters that mark the end of a
statement, or that separate items in a list

Example in program (shown in green):
double num1 = 5,
num2, sum;
num2 = 12;
LINES VS. STATEMENTS
In a source file,
A line is all of the characters entered before a
carriage return.
Blank lines improve the readability of a program.
Here are four sample lines. Line 3 is blank:
double num1 = 5, num2, sum;
num2 = 12;
sum = num1 + num2;
LINES VS. STATEMENTS
In a source file,
A statement is an instruction to the computer to
perform an action.
A statement may contain keywords, operators,
programmer-defined identifiers, and
punctuation.
A statement may fit on one line, or it may occupy
multiple lines.
Here is a single statement that uses two lines:
double num1 = 5,
num2, sum;
INPUT, PROCESSING, AND OUTPUT
Three steps that a program typically performs:
1) Gather input data:
 from keyboard
 from files on disk drives
2) Process the input data
3) Display the results as output:
 send it to the screen
 write to a file
49
INTRODUCTION TO C++
The Parts of a C++ Program
comment
// sample C++ program
preprocessor directive
#include <iostream>
which namespace to use
using namespace std;
beginning of function named main
int main()
beginning of block for main
{
cout << "Hello, there!"; output statement
send 0 back to operating system
return 0;
end of block for main
}
50
THE PARTS OF A C++ PROGRAM
Statement
Purpose
// sample C++ program
comment
#include <iostream>
preprocessor directive
using namespace std;
which namespace to use
int main()
beginning of function named main
{
beginning of block for main
}
cout << "Hello, there!";
output statement
return 0;
send 0 back to the operating system
end of block for main
2-51
SPECIAL CHARACTERS
Character
Name
Description
//
Double Slash
Begins a comment
#
Pound Sign
Begins preprocessor directive
< >
Open, Close Brackets
Encloses filename used in
#include directive
( )
Open, Close Parentheses Used when naming function
{ }
Open, Close Braces
" "
Open, Close Quote Marks Encloses string of characters
;
Semicolon
Encloses a group of statements
Ends a programming statement
2-52
IMPORTANT DETAILS

C++ is case-sensitive. Uppercase and
lowercase characters are different characters.
‘Main’ is not the same as ‘main’.

Every { must have a corresponding }, and viceversa.
2-53
THE COUT OBJECT
Displays information on computer screen
 Use << to send information to cout

cout << "Hello, there!";

Can use << to send multiple items to cout
cout << "Hello, " << "there!";
Or
cout << "Hello, ";
cout << "there!";
2-54
STARTING A NEW LINE

To get multiple lines of output on screen
- Use endl
cout << "Hello, there!" << endl;
-
Use \n in an output string
cout << "Hello, there!\n";
2-55
THE #INCLUDE DIRECTIVE

Inserts the contents of another file into the
program

Is a preprocessor directive
 Not
part of the C++ language
 Not seen by compiler

Example:
#include <iostream>
No ; here
2-56
STANDARD AND PRESTANDARD C++
Older-style C++ programs
•
Use .h at end of header files
#include <iostream.h>
Do not use using namespace convention
•
May not compile with a standard C++ compiler
•
2-57
REFERENCE
Tony Gaddis, Starting out with C++
 www.wittyengineers.com

58