You are on page 1of 52

DFC 10042

PROBLEM SOLVING AND PROGRAM DESIGN


Topics :
CHAPTER 1 :
INTRODUCTION TO PROGRAMMING LANGUAGE
CHAPTER 2 :
PROBLEM SOLVING METHODS
CHAPTER 3 :
FUNDAMENTALS OF PROGRAMMING
LANGUAGE
CHAPTER 4 :
BASIC PROGRAMMING CODE
Assessment :
COURSEWORK ASSESSMENT (CA) -70%
FINAL EXAMINATION (FE) -30% :

COURSEWORK ASSESSMENT
1. Quiz (4) – 10 %
2. Problem Based Exercise (3) -20%
3. Problem Based Task (2) - 40%
OUTCOMES
At the end of this chapter, you will be able to:
Describe the programming language
Describe fundamentals of programming languages.
1.1 DESCRIBE THE
PROGRAMMING LANGUAGE
LANGUAGE
According to

Language
1. The method of human communication
using spoken or written words

2. The particular form of words and speech that is used


by the people of a country, area, or social group

3. Signs, symbols, sounds, and other methods of communicating


information, feelings, or ideas
Definition :
A set of words, abbreviations, and symbols that enables a
programmer to communicate instructions to a computer.
In order to develop a program for a computer, you
must use a computer language.
Developing new software requires writing lists of
instructions for a computer to execute.
These instructions are written using a programming
language.
There are three levels of programming languages
 machine language
 assembly language
 high-level language
Figure 1.8: Advancement in Programming Language
This is the First Generation Language.
A collection of binary numbers understood by a
computer.
It represents data and program instructions as “1”s
and “0”s (binary digits corresponding to the “on” &
“off” electric states in the computer).
The only language which a computer understands
directly (built-in and does not require a translator).
Example: 00010101
This is the Second Generation Language.
It uses abbreviation for instructions developed to
replace “1”s & “0”s used in Machine Language.
Also known as symbolic language because it uses
mnemonic code (a symbol chosen to help the user to
remember the significance of the symbol)
Machine dependent (different language for different
type of CPU)
Example: ADD A, STOR B
Translation from assembly language into machine
language is done using an ASSEMBLER
Assembly
Language

Assembler

Machine Language
Instruction is written as a series of English-like
words.
Translation to machine language is performed
using compiler or interpreter.
Starting from 3rd Generation language and
above, written programs are no longer
dependent on the type of CPU and can be run in
any machine.
 FORTRAN – designed for scientific
application and used by engineers,
scientists and mathematicians.
 COBOL – more widely used for business
applications.
 BASIC – easy to learn and widely used in
education and business application.
 C/C++ - powerful and fast, used in many
areas.
Also uses English-like statements.
Variations on 4GLs are query languages, which can be used to retrieve
data from database.
The main domains and families of 4GLs are:
 database queries,
 report generators,
 data manipulation,
 analysis and reporting,
 screen painters and generators,
 GUI creators,
 mathematical optimization,
 web development
 general purpose languages.
Example: MAPLE, MATHEMATICA, POSTSCRIPT, SPSS, SQL
Many 4GLs are associated with databases and data processing,
allowing the efficient development of business-oriented systems
4GLs are mostly based on the Structured Query Language (SQL) for
managing structured data.
Most 4GLs contain the ability to add 3GL-level code to introduce
specific system logic into their program.
The codes resemble the human language.
Normally associated with artificial intelligence
built up through logic programming.
The use of natural languages to access
knowledge as a knowledge-base system or
expert system.
Example, Prolog.
Machine Languages
Using Vacuum Tubes

Assembly Languages
Using Transistors

3rd Generation Languages


Using Integrated Circuits

4th Generation Languages


Using Microprocessors

5th Generation Languages


Using Artificial Intelligence
1.2 FUNDAMENTALS OF
PROGRAMMING LANGUAGE
Program:
 A set of step-by-step instructions that directs a computer to perform a specific task
and to produce the required results.

Programming:
 Programming is a process of designing/ creating a program.

Programmer:
 Programmer is a person who designs, writes and test the program.
A computer can only understand programs defined using machine
code.
For example, a program written in Java cannot be run directly from a
computer.
To execute a computer program written in high or low level language,
it must be first be translated.
A translator is a program that:

 Checks syntax of a program to ensure the programming language is used correctly

 Translates a program into language that the computer can understand.

 Produces descriptive error messages known as syntax-error to programmer if there


are errors in the programs.
Syntax – set of rules to be followed Syntax Error – error in the use of a
when writing a program, these rules programming language.
are similar to the grammatical rules
in English. Example in C++ :
Statement: clrscr()
Example:
If semicolon (;) is not placed after
Message displayed on the screen is statement, an error message will be
“Please enter a number”. displayed :
C++ Language:
“Error DIT103.CPP: Declaration
cout << “Please enter a number”; syntax- error”
The correct syntax is:
clrscr();
3 types of system software used for translating the codes:

1. Assemblers
2. Compilers
3. Interpreters
A program used to convert assembly language into
machine language.
Translates the whole program at one time.
Also called assembler program.
sseg segment stack
db 256 dup (?)
sseg ends 11101 100000
100000
dseg segment 11110
data db “2 x 4 = ” 10111000
dseg ends
Assembler 11101000
cseg segment 11111100
assume cs:cseg:ds:sdeg:ss:sseg. 10111000
es:nothing 10001110 11011000
Start 10111000
10001110 11000000

Assembly Language Machine Language


A program that translates a high level language into machine code.
The Dev C++ compiler, for example, translates a program written in
C++ into machine code that can be run on a PC.
Translates the whole program at one time.

Compiler Process
# include <iostream> 11101 100000
using namespace std; 100000
11110
main( ) 10111000
{
11101000
int x, y, sum;
11111100
double avg; Compiler 10111000
cout<<" Enter 2 numbers : "; 10001110 11011000
cin >> x >> y; 10111000
sum = x + y; 10001110 11000000
avg = sum / 2;
cout<<" X : " << x <<“\nY : "<< y;
cout<<“The average is = "<< avg;
system("pause");
return 0;
}

Machine Language
C++ Language
Source File
Other Object Files

Object File
Executable File

Error messages

Input data Results

Figure 1 : Process of developing and testing high-level language


Also a program that translates high-level language into
machine language.
Also known as interpreter
Difference between a compiler and an translator?
 A translator translates one line at a time and then executes it
 No object code is produced
 So the program has to be interpreted each time it is to be run.

Eg. if the program performs a section code 1000 times,


then the section is translated into machine code 1000
times since each line is interpreted and then executed.
1.2.3 PROGRAMMING
APPLICATION IN REAL LIFE
Programming is important in our daily life to enhance and increase the
power of computers and the internet. Programming is important for
speeding up the input and output processes in a machine. Programming is
important to automate, collect, manage, calculate, analyze the processing
of data and information accurately.

You might also like