Вы находитесь на странице: 1из 23

INTRODUCTION TO PROGRAMMING

CHAPTER 1

Computer Program
A self-contained set of instruction used to operate a computer to produce specific result. A list of detailed, step by step instruction that tell a computer how to solve a problem or carry out a task Also called Software

Programming
Process of writing a program (software)

Programming Language
Set of instruction that can be used to construct a program The language that the computer can interpret or understand Ex: C++, Basic, Fortan, Cobol,Java.

Types of Programming Languages


The evolution: First Generation: Machine Language(1945) Second Generation: Assembly Language(mid 1950s) Third Generation: High Level Language(early 1960s)

Low Level Language

Machine Language
The actual language to operate computers Language that understandable Consist of binary numbers: 0 and 1 Instruction consist of: instruction and address Ex: 11000000 00000001 00000010 Add the data in memory location 1 to the data in memory location 2.
6

Cont
Example Equation: wages = rate * hours Binary codes: 100100 010001 100110 010010 100010 010011 Programmer had to remember the machine language codes for various operations. Also need to remember the locations of the data
7

Assembly Language
Machine language: Tedious, timeconsuming. Word-like symbols,abbreviations vs binary numbers Instruction such as ADD, SUB, MUL Ex: ADD 1,2 MUL 2, 3 Computers can only execute machine language.
8

cont

Assembly Language program

Translation program (assembler)

Machine language

High-Level Language
Machine and assembly are low level High-level language uses instructions that mimic English language Human-like words Ex: Result = num1 + num2; Example of high-level languages are: C++, Fortran, COBOL, Java etc
10

cont
Source code: programs written in a computer language. Must be translated into machine language Interpreter or compiler Interpreter: each statement is translated individually and executed immediately upon translation - BASIC Compiler: All statements are translated as a complete unit - C++
11

Problem Solving
Programming is a process of problem solving One common problem solving technique is algorithm. Algorithm is a step by step problem solving process

12

Steps of problem solving


analyze the problem, outline the problem and its solution requirements and design an algorithm to solve problem. implement the algorithm in a programming language, such as C++ and verify that the algorithm works. maintain the program by using and modifying it if the problem domain changes.
13

Processing a high-level program


Problem

Analysis

Algorithm Design

Coding Syntax error Compiler No error library Linker

Loader error Execution

Results

14

DESIGNING TOOLS
pseudocode and flow chart. Pseudocode is like common word or human words such as English like wording used to represent algorithm Flowchart is a graphical representation of algorithm

15

Example of problem
To find perimeter and area of a rectangle. Formulas are:
perimeter = 2 . (length + width) area = length . Width

Analysis Process
get the length of the rectangle get the width of the rectangle find the perimeter using the following equation perimeter = 2 . (length + width) find the area using the following equation area = length . Width Displays perimeter and area
16

Pseudocode
START INPUT length INPUT width CALCUALTE PERIMETER perimeter = 2 . (length + width) CALCULATE AREA area = length . width OUTPUT perimeter OUTPUT area END
17

Flowchart
START INPUT length INPUT width

perimeter = 2 * (length + width)

area = length . width

DISPLAY length DISPLAY width

END

18

LIST OF PSEUDOCODE WORDINGS.


Word START END INPUT GET ENTER OUTPUT Description To indicate start of the algorithm/certain structure To indicate end of the algorithm/certain structure To indicate of input data needed To indicate of input data needed To indicate of input data needed To indicate of displaying information on the screen

DISPLAY
PRINT PROCESS CALCULATE IF END IF ELSE REPEAT LOOP END LOOP/REPEAT

To indicate of displaying information on the screen


To indicate of displaying information on the screen To indicate of processing data by certain formulas/calculation To indicate of processing data by certain formulas/calculation To indicate of selection structure To indicate end of selection structure To indicate of selection structure-branching To indicate of repetition structure To indicate of repetition structure To indicate end of repetition structure

19

LIST OF FLOWCHART SYMBOLS


Symbol Description To indicate start or end of the algorithm/certain structure terminal To indicate of input data needed or To indicate of displaying information on the screen Input/output To indicate of processing data by certain formulas/calculation

process To indicate branching because of selection structure or repetition structure

decision To indicate the flow of the algorithm flowline To indicate an entry or exit from another part of the flowchart connector To indicate a predefined process as in calling a function

Predefined process

20

EXERCISE
Why computer is required to translate a program written in a high level language into machine language? To make a profit, the prices of the items sold in a furniture store are marked up by 60%. Design an algorithm to find the selling price of an item sold at the furniture store. What information do you need to find the selling price?
21

EXERCISE
1. The volume of oil stored in an underground 200-foot deep cylindrical tank determined by measuring the distance from the top of the tank to the surface of the oil. Knowing this distance and the radius of the tank, the volume of oil in the tank can be determined using the formula volume = radius2 (200 distance). Using this information design a program that accepts the radius and distance measurements, calculates the volume of oil in the tank, and display the two input values and the calculated volume. Design a program that asks user to input two numbers. If the first number entered is greater than the second number, the program should print the message THE FIRST NUMBER IS GREATER else it should print the message THE FIRST NUMBER IS SMALLER.

2.

22

Cont

23

Вам также может понравиться