Академический Документы
Профессиональный Документы
Культура Документы
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.
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
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
Analysis
Algorithm Design
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
END
18
DISPLAY
PRINT PROCESS CALCULATE IF END IF ELSE REPEAT LOOP END LOOP/REPEAT
19
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