Ch01 Intro
Ch01 Intro
Programming Languages
Computer program: data and instructions used to operate a computer and produce a specific result
A program or set of programs is called software
Programming: writing instructions in a language that the computer can respond to and that other programmers can understand Programming language: set of instructions that can be used to construct a program
Machine Language
Executable program: program that can operate a computer Executable programs are written with binary numbers, which is a computers internal language (machine language)
An example of a simple machine language program containing two instructions is:
11000000000000000001000000000010 11110000000000000010000000000011
Opcode is short for operation code; tells the computer the operation to be performed
3
Assembly Language
Assembly language: uses the substitution of wordlike symbols for the opcodes, and decimal numbers and labels for memory addresses
LOAD first ADD second MUL factor STORE answer
Linker: combines additional machine language code with the object program to create a final executable program
7
10
11
The Development of C
Developed in the 1970s at AT&T Bell Laboratories by K. Thompson, D. Ritchie, and B. Kernighan High-level structured language
Can also access the internal hardware of a computer
C permits a programmer to see into a computers memory and directly alter data stored in it Standard maintained by the American National Standards Institute (ANSI) In the 1980s, Bjarne Stroustrup (working at AT&T) developed C++
C with object-oriented capabilities
12
Algorithms
Algorithm: specific steps required to produce a desired result
Set n equal to 100 Set a equal to 1 Set b equal to 100 Calculate sum = n(a+ b)/2 Display the sum
When English phrases are used to describe an algorithm, the description is called pseudocode
Input the three numbers into the computer Calculate the average by adding the numbers and dividing the sum by three Display the average
13
Algorithms (continued)
14
Algorithms (continued)
When mathematical equations are used to describe an algorithm, the description is called a formula Flowchart: provides a pictorial representation of an algorithm using specifically defined shapes
15
Algorithms (continued)
16
Algorithms (continued)
17
Algorithms (continued)
Converting an algorithm into a computer program, using a language such as C, is called coding the algorithm The program instructions resulting from coding an algorithm are called program code, or simply code
18
Algorithms (continued)
19
Step 3: Write the program (see next slide) Step 4: Test and correct the program
The circumference of the circle is 12.566400
Because only one calculation is performed by the program, testing Program 1.1 really means verifying that the single output is correct
21
22
23