Professional Documents
Culture Documents
359子情 - 4 - 1 en
359子情 - 4 - 1 en
1 Classification of
❶ program
Programming Languages
❶
To be processed by computer
❷
The overall work of creating the
It is called programming. program. programming
Also. The means of expressing a
program is called a con
➌
The word "computer" means a It is called a ➌ programming lan-
guage
language understood by a computer. programming language.
Programming languages can be classified as shown in It can also be just a language.
10
machine
programming language
Interpreter language (e.g. BASIC)
language assembly
Compiler language (C, Java, etc.)
language
high-level
language
Figure 1 Programming Language
computer. In machine language, the computer reads ",1" or "0" proceed with processing.
82 Chapter 4
rafting
Programming
To make machine
A machine language program is a
2 assembly language easier to
1
language series of numbers read, numerical
sequences of "1" and
and is difficult for humans to
"0" are often
Programming Basics
understand. The represented
hexadecimal
using
It is called an
assemblage.
Since the instruction code of assembly language may differ
depending on hardware such as central processing units,
many types of assembly languages exist.
Located at. 25
1 Programming Basics 83
❶
FORT RUN
WRITE(*,10)
10 FORMAT('Hello')
Fortran A language developed for scientific and
STOP
technical computing. END
#include <stdio.h>
sea int main(void){
C Widely used language in general use. printf("Hello¥n");
return 0; return
}
#include <iostream>
C++
A language developed from C. Data and using namespace std;
C++ operations can be described together.
int main(){
cout<<"Hello"<<endl;
}
84 Chapter 4
Programming
➍ interpreter
compiler.
1 Programming Basics 85
2 Primitive and Objective Programs
Assembly and high-level languages have their
1 Resource
Each of them has its own writing ❶ coding
program conventions, and this
is called a grammar. Writing a program according to the file
grammar is called coding.
❶❶ ❷ Day according to certain rules
The coding program is compiled as a file and stored in the same A grouping of two or more 5
directory. The coded program is compiled as a file persons.
➌
It can be done. This is called a It is called a source ➌ source program
Ⓖ
the execution of the
is called an object program.
target program. Even if
Figure 2 shows how the language processor works.
the target program is
Execute one instruction
source program
at a time,
grammatically correct
program.
It's a primitive
interpreting it as
you go.
and can be executed to
program
source
86 Chapter 4
Programming
Ⓖ object program
15
❻ bug
Including
grammatical errors
and logical errors in
execution.
All errors. 20
(after a noun,
adjective stem, ❼ debug
It must be corrected. This work
onomatopoeic-
mimetic word, etc.)
should be
It is called
debugging.
1 Programming Basics 87
3 Flow Chart and Program Structure
To be processed using a computer
name
ents
docum manual input
display
88 Chapter 4
Programming
port (e.g. LAN
Loop start (beginning of loop)
loop end
Start, end of flow chart
port)
Loop termination (end of
loop)
process
defined
n
associatio ray (e.g. X-
Processes defined elsewhere Flow chart connections
Process Flow
ray)
without specifying the
medium
1 Programming Basics 89
first doing of first first
doing of doing
... (ever, in
... (ever, of ...
one's life, in
in one's (ever,
the new year, NO
xlife,
≥ in100 in
etc.) 1
the new
YES ←S+N
S one's
year, life, in
xRead
← (a +the
b) value
/2 Output
etc.) ←N+1
Nthe
S
of a of x
new output
Output of x Input x NO
year,
N > 10
Read the value
etc.) YES end
of bthe end the
end
S←
1 0
Flowchart for inputting Flow chart for
two numbers a and b outputting x when the Find the ← 1 S of positive integers 1 to 10.
Nsum
and outputting their input number x is Flow chart for outputting S.
average x. greater than or equal
to 100. (c)
(a)
(b)
Figure 3 Example of flow chart
value. variable.
When obtaining an answer from the number or order of
processes, as in Figure 3( c ), the values of the variables must be
determined in advance before processing. This kind of ❷ initialization 5
❷
The operation is called initialization, and the value assigned to a Initial value
variable in initialization is called the initial value.
➌
The term value is called the period value.
Figure 3( c ) shows a flowchart for finding the sum from 1
to 10, counting the number of iterations in N and finding first doing of ...
10
(ever, in one's
the sum in S. In this algorithm, S and N are initialized with
life, in the new
the initial value 0 and 1, respectively.
year, etc.)
When N exceeds 10, the loop is terminated. Figure 3( c )
S←0
can also be drawn with a loop end symbol as shown in
N←
S← S +1N
Figure 4. In this example, an exit condition to escape from
loop 15
repetition is written at the end of the loop. N←N+1
N > 10
loop
at end
conditio S
90 Chapter 4
n Output
Programming
the
Figure 4 Example of flow
chart with loop
ends
1 Programming Basics 91
How the value of a Table 3 Trace Table
2 trace
variable changes in a
certain process
❶�
The process of tra
scalled
g
cin Figure 3( c )Iteration process
freque sadist N N > 10
Table 3 shows the results of tracing the Such a table can be ncy
0 0 1 -
traced
1 1 2 NO
5 The algorithm in question is called an algorithm
2 3 3 NO
table, and it is used to check whether the algorithm in 3 6 4 NO
question is a correct procedure to be processed. 4 10 5 NO
Do. 5 15 6 NO
countermeasure
6 21 7 NO
esothold c( ), when
In Figure 3( c ) , the condition N > 10 do
n
7 28 8 NO
➌)
Branch to NO and repeat the process. Fulfills (YoES)
the when
condition (true 8 36 9 NO
u
The repeatability is escaped by branching out to 9 45 10 NO
nt
10
left to right.
<Data D > 6, 9, 2, 7, 4, 3, 9, 3, 1, 0
92 Chapter 4
Programming
first
doing of
... (ever,
in one's
life, in
the new
year,
etc.) YES
D=0
M ← 0 NO
K P←←K0+ 1
K←0
Enter D YES
D<0 Output M, P, K
NO M←M+D
P←P+D
Enter D the
end
Figure 5 Flow chart
1 Programming Basics 93
structured To write a large program
3 programming efficiently, the program structure
-ing
must be able to
❶
The information should be as easy Structured programming is ❶ structured program
to understand as possible. a simple
ming
The rules were designed to create a clean and understandable
program. 5
sequenti
al
structure repetitive
structure
sequenti
al
structure
choice
structure
a Sequential structure
94 Chapter 4
Programming
Processing A
Processing A
Processing B
Processing B
(a) (b)
Figure 7
Sequential
structure
1 Programming Basics 95
b Selective structure
≦ NO NO
X: Y X>Y X>Y
> YES YES
Processing Processing Processing Processing Processing
C D C D C
Loop
name loop name
NO Processing
conditio end
n of conditio E
n
continua Processing Processing
YES
nce E NO E
Process contin the
ing E loop name ued afo End
conditio
article res n loop
name
aid
96 Chapter 4 YES
Programming
Conditional decisions are made before Conditional decisions are made after processing.
processing. Even if the continuation condition is
If the continuation condition is false false from the beginning, process E is
executed only once, the first time.
from the beginning, the process
E is never executed. (b) Post-determination type
Figure 9 Repeat
(a) Pre-determined form
structure
1 Programming Basics 97
Example
1 Figures 10(a) to 10(c) show the flow chart for finding the
sum S of odd numbers from 3 to 9. Fill in the blanks (1)
through (8).
(8)
(5)
(1)
No N
(2) N: 9
(7) S
(3)
output
end
explanation
) is added to S by increasing N from 3 to 9 in increments of 2.
(
a blanks
After adding N to S, add 2 to N. If N exceeds 9, escape the loop. (1) through
) N is initially 1.
(
b
(3 ) .
) uses the loop end. In this book, N is represented by 2 from 3
(
c
to 9.
❶
Repeating the process while increasing is written as "n 3, 9, 2".
answer
(1) N > 9 (N = 11 is also acceptable) (2) S ← S + N (3) N ← N + 2
(4) S←0, N←1 (5) S←S+N (6) ≧ (7) < (8) S←S+N
first
Questi Figure 11 shows a flowchart for
doing of
on 2
reading three sets of data A, B, and C and ... (ever,
1
15
10 NO
(2)
Write the initial value, closing value, and increment in this YES
(3)
M
Output
1 Programming Basics 99