You are on page 1of 36

IS 121 COMPUTER PROGRAMMING

LECTURE 1
INTRODUCTION
•What is a computer ?
A computer is a programmable machine. This means it can execute a programmed list of instructions and
respond to new instructions that it is given.

•What is a computer program ?


A computer program is a set of instructions that tells the computer what to do.

•What is computer Programming ?


Computer Programming is the process of developing and implementing various sets of instructions to enable
a computer to do a certain task.

•Programs are written to solve problems or perform tasks on a computer.


INTRODUCTION
•Programmers translate the solutions or tasks into a language the computer can understand.
• As we write programs, we must keep in mind that the computer will only do what we instruct it
to do.
•Because of this, we must be very careful and thorough with our instructions.
What is a Programming Language?
•Programming Language is a set of rules that provides a way of telling a computer what
operations to perform.
•Programming language is a set of rules for communicating an algorithm. It provides a linguistic
framework for describing computations.
•Programming language is a notational system for describing computation in a machine-readable
and human-readable form
•Algorithm -“a finite set of precise instructions for performing a computation or for solving a
problem”
Programming Languages
Generations of Programming Languages
•First Generation Languages.
•Second Generation Languages.
•Third Generation Languages.
•Fourth Generation Languages.
•Fifth Generation Languages.
First Generation Languages
•First Generation Languages (Machine Language) programs were made up of instructions
written in binary code.
•Each instruction had two parts: Operation code, Operand
◦ Operation code (Opcode): The command part of a computer instruction ( such as
addition and subtraction)
◦ Operand: The address of a specific location in the computer’s memory (Identifies the data
to be processed)
•Hardware dependent: Could be performed by only one type of computer with a particular
Central Processing Unit (CPU)
Second Generation Languages
•Second Generation Languages (Assembly Languages) programs are made up of instructions
written in mnemonics.
•Mnemonics: Uses convenient alphabetic abbreviations to represent operation codes, and
abstract symbols to represent operands.
• Each instruction had two parts: Operation code, Operand
• Hardware dependent.

•Because programs are not written in 1s and 0s, the computer must first translate the program
before it can be executed.
READ num1
READ num2
LOAD num1
Example of Second Generation ADD num2
Language STORE sum
PRINT sum
STOP
Third Generation Languages
•Third Generation (People-Oriented Programs)
•Instructions in these languages are called statements.
•High-level languages: Use statements that resemble English phrases combined with
mathematical terms needed to express the problem or task being programmed.
•Transportable: NOT-Hardware dependent.
•Because programs are not written in 1s and 0s, the computer must first translate the program
before it can be executed.
•Instructions are closer to English and included simple mathematical notation.
Third Generation Languages
Program sum2(input,output);
var
num1,num2,sum : integer;

begin
Example of Third Generation
Language read(num1,num2);
sum:=num1+num2;
writeln(sum)
end.
Fourth Generation Languages
•Fourth Generation - Non-Procedural Languages
•Programming-like systems aimed at simplifying the programmers task of imparting instructions
to a computer.
•These require fewer instructions to accomplish a task than third generation languages.
•Many are associated with specific application packages.
◦ Query Languages
◦ Report Writers
◦ Application Generators
◦ Form Designers
Fifth Generation Languages
•Fifth Generation - Natural Languages
•Natural-Language: Languages that use ordinary conversation in one’s own language.
•Research and experimentation toward this goal is being done.
• Intelligent compilers are now being developed to translate natural language (spoken) programs into
structured machine-coded instructions that can be executed by computers.
• Effortless, error-free natural language programs are still some distance into the future.

•Examples include LISP, Scheme, SML, Prolog.


Assembled, Compiler or Interpreted Languages
•All programs must be translated before their instructions can be executed.
•Computer languages can be grouped according to which translation process is used to convert
the instructions into binary code:
◦ Assemblers
◦ Interpreters
◦ Compilers
Assembled, Compiler or Interpreted Languages
•Assembled languages:
◦ Assembler: a program used to translate Assembly language programs.
◦ Produces one line of binary code per original program statement.
◦ The entire program is assembled before the program is sent to the computer for execution.
Assembled, Compiled, or Interpreted Languages
•Interpreted Languages:
•Interpreter: A program used to translate high-level programs.
•Translates one line of the program into binary code at a time:
◦ An instruction is fetched from the original source code.
◦ The Interpreter checks the single instruction for errors. (If an error is found, translation and execution ceases.
Otherwise…)
◦ The instruction is translated into binary code.
◦ The binary coded instruction is executed.
◦ The fetch and execute process repeats for the entire program.
Assembled, Compiled, or Interpreted Languages
•Compiled languages:
•Compiler: a program that translates human readable source code into computer executable
machine code.
•Compiler: Translates the entire program into binary code before anything is sent to the Central
Processing Unit (CPU) for execution.
•The translation process for a compiled program is as follows:
• First, the Compiler checks the entire program for syntax errors in the original source code.
• Next, it translates all of the instructions into binary code.
• Two versions of the same program exist: the original source code version, and the binary code version
(object code).
• Last, the CPU attempts execution only after the programmer requests that the program be executed.
Assembled, Compiled, or Interpreted Languages
•Compile time- The time taken to compile a program.
•Run time- The time taken for executing a program.
•Source Code-The program in its user written form of the language. Source code is given as input
to the compiler.
•Object Code- the machine code obtained after processing the source code, object code is also
known as Binary code.
Task 1
•Discuss the difference between a Compiler and an Interpreter
•Which would execute faster between a program written in First Generation language and the
one written in Fourth Generation Language? (Provide Reasons for your Answer)
Building a Program
•Whatever type of problem needs to be solved, a careful thought out plan of attack, called an
algorithm, is needed before a computer solution can be determined.

I. Developing the algorithm.


II. Writing the program.
III. Documenting the program.
IV. Testing and debugging the program.
v. Deployment of the program

Testing and
Developing Writing the Documenting
debugging the
the algorithm program. the program
program
Building a Program
I. Developing the algorithm.
• Algorithm: A detailed description of the exact methods used for solving a particular problem.

• To develop the algorithm, the programmer needs to ask:


◦ What data has to be fed into the computer?
◦ What information do I want to get out of the computer?
◦ Logic: Planning the processing of the program. It contains the instructions that cause the input data to
be turned into the desired output data.
Building a Program
•A step-by-step program plan is created during the planning stage.
•The three major notations for planning detailed algorithms:
◦ Flowchart: Series of visual symbols representing the logical flow of a program.
◦ Nassi-Schneidermann charts: Uses specific shapes and symbols to represent different types of program
statements.
◦ Pseudocode: A verbal shorthand method that closely resembles a programming language, but does not
have to follow a rigid syntax structure.
Building a Program
Flow chart: Nassi-Schneidermann chart:
Start Y If money > $10.00 N
Go out Go home
Count Money
Repeat until
money < 10,000/=
Do you Yes Stop
have more than Go out
10,000/= Pseudocode:
No 1. If money < 10,000/= then go home
Else Go out
Go home
2. Count money
3. Go to number 1
End
Flowcharts
• Flowchart graphically depicts the logical steps to carry out a task and shows how the steps
relate to each other.

• Flowchart is an organized combination of shapes, lines, and text that graphically illustrates a
process or structure.

• It visually represents and organizes the steps used to write the program—it is a diagram of
the “flow” of the process.
Flowchart Symbols
Flowchart Symbols
Pseudocode
•Pseudocode uses English-like phrases to outline the task/process
•One of the popular representation of Algorithm
•Widely choosen because:
◦ easy to read and write
◦ allow the programmer to concentrate on the logic of the problem
◦ Structured in English language
Pseudocode Convention
•Statement are written in simple English
•Each instruction is written on a separate line
•Keywords and indentation are used to signify particular control
structures.
•Each set of instructions is written from top to bottom, with only one
entry and one exit.
•Groups of statements may be formed into modules, and that group
given a name.
Six Basic Computer Operations
1. A computer can receive information
Verb used:
•Read  used when the algorithm is to receive the input from a record on a file
•Get  used when the algorithm is to receive input from the keyboard.

Read student name


Get system date
Read number_1, number_2
Get tax_code
Six Basic Computer Operations
2. A computer can put out information
Verb used:
• Print  used when the output is to be sent to the printer
• Write  used when the output is to be written to a file
• Put, Output, Display  used when the output is to be written to the screen
• Prompt  required before an input instruction Get, causes the message to be sent to the screen
which requires the user responds, usually by providing input.

Print `Program Completed´


Write customer record to master file
Put out name, address and postcode
Output total_tax
Display ´End of data´

Prompt for student_mark


Get student_mark
Six Basic Computer Operations
3. A computer can perform arithmetic operations
Verb used:
• Compute
• Calculate
Add number to total
Symbols used: Total = total + number
+, -, *, /, ()

Divide total_marks by student_count


Sales_tax = cost_price * 0.10
Compute C = (F – 32) * 5/9
Six Basic Computer Operations
4. A computer can assign a value to a variable or memory location
Three cases :
1. To give data an initial value in pseudocode, the verbs Initialise or Set are used
2. To assign a value as a result of some processing, the symbols ´=´or ´´ are written
3. To keep a variable for later use, the verbs Save or Store are used.

Initialize total_price to zero


Set student_count to 0
Total_price = cost_price + sales_tax
Total_price  cost_price + sales_tax
Store customer_num in last_customer_num
Six Basic Computer Operations
5. A computer can compare two variables and select one of two alternate actions
Keyword used:
IF, THEN, ELSE

IF student_attendance_status is part_time
THEN
add 1 to part_time_count
ELSE
Add 1 to full_time_count
ENDIF
Six Basic Computer Operations
6. A computer can repeat a group of actions
Keyword used:
DOWHILE, ENDDO

DOWHILE student_total < 50


Read student record
Print student name, address to
report
Add 1 to student_total
ENDDO
Building a Program
II. Writing the Program
◦ If analysis and planning have been thoroughly done, translating the plan into a programming language
should be a quick and easy task.

III. Documenting the Program


◦ During both the algorithm development and program writing stages, explanations called documentation
are added to the code.
◦ Helps users as well as programmers understand the exact processes to be performed.
Building a Program
IV. Testing and Debugging the Program.
◦ The program must be free of syntax errors.
◦ The program must be free of logic errors.
◦ The program must be reliable. (produces correct results)
◦ The program must be robust. (able to detect execution errors)

V. Deployment of the program


END OF LETURE 1

You might also like