TR
:
: g và C++
: 17209
TRÌNH :
DÙNG CHO SV NGÀNH :
45
30
0
0
0
:
K thut lp trình Pascal, K thut lp trình C.
:
c phng pháp lp trình h tng lp trình .
- rng c lp trình h tng.
- tng và l.
- gói, th k, a hình.
- B mu
TS
LT
BT
KT
:
9
6
3 2.1 Cài t ngôn ng C++ 2.2 C trúc mt chng trình C++ 2.3 Ki d li c s 2.4 Quy t s dng t khóa, tên chu, tên t
3.2 Quy t ki d li, ki tr. 3.3 ngh ch hàm, tham s ng 3.5 . ++
9
5
3
1
4.1 tng vào ra cout, cin
5.1 ngh tng 5.2 Khai báo l
ii
5.3 Hàm thi lp, hu b 5.4 Thành ph t, hàm bn, l bn 5.5 ngh ch toán t
6
3
3 7.1 Hàm , ràng buc t, ng 7.2 a th :
12
5
6
1
8.1 Hàm b m
3
:
2. Ph Vn . K thut lp trình h tng. NXB KHKT. 1998
3n.
:
- thc hành.
-
. 1
.
.
.
1.1
(
:
.
,
.
,
.
1.2
.
.
2
.
,
.
.
,
,
:
.
,
3
.
.
.
:
.
.
,
.
.
i
(object) ,
(class) ,
(instance) ,
.
.
,
70% .
.
) (
.
.
2.
.
.
5
:
.
.
(
.
: .
: ADT Integer:
End
1.2 (Objects) (Classes)
.
.
data member .
function.
(instance) .
,
.
1.3
(Inheritance)
.
6
( class).
.
.
1.4 Dynamic Binding (
) (
().
. :
int main()
{
Shape shape_list[4];
int choose;
int i;
for(i=0;i<4;i++)
{
cin >> choose;
if(choose==0)
{
shape_list[i] = new Circle();
}else{
shape_list[i] = new Rectange();
_
,
.
(polymorphism).
.
.
3.
++ .
,
2: 1959 1961 (Fortran II, Cobol)
3: 1962 1970 (Pascal, Simula)
,
4:
1995 Java
1983 to 1989 Language books with OO concepts
1989 to 1992 Object-oriented design books
1992 to present Object-oriented methodology books
Java
Self
Python
Perl
Prograph
8
Modula 3
Oberon
Smalltalk Venders
ParcPlace, Digitalk, Quasar
Prolog++
Ada 9X
Object Pascal (Delphi)
Object X, X = fortran, cobal, etc.
C#.
++
.
1.2
++.
C++ (AT & T
Bell Lab) ( 1994)
C.
C++
++ ,
++
.
2:
1.
(
)
(
).
(interpreter) (compiler).
:
.
.
.
. ,
,
.
9
.
.
.
,
,
.
.
.
.
.
.
.
.
(in-memory compilation).
. ,
.
(
.
.
.
.
(global optimizer)
.
,
.
(
.
.obj).
.
,
.
, ;
.
(dynamic type checking).
t.
C++
.
:
,
,
. Trong ngôn n
++,
.
.
11
C++
.
,
,
h
.
,
++
.
1
;
.
< >
.
: #include <header.h>
<>,
12
.
++.
(
.o
.obj),
.
.
.
,
.
.
,
.
.
++, ,
,
u:
,
.
, .
.
.
13
++
,
.
++
.
.
(
).
1.2
.
// Chương trình HelloWorld
// File hello.cpp
// In ra màn hình xâu “Hello, World!”
#include <iostream.h> // Khai báo luồng cout để sử
,
: , World!.
++
.
,
:
// ,
++
.
#include.
a C++.
14
stream.
() .
++ ()
0
.
<<.
<<
ong C++
, C++
. ++
(
: )
.
,
.
:
Tcc eHello hello.cpp.
.exe.
2.
,
.
.
(
)
.
++ :
<
> ;
( )
().
(
15
).
.
:
// file: Declare.cpp
// V d khai bo v đnh ngha bin
extern int i; // khai báo và không định nghĩa
float b; // khai báo và định nghĩa
int i; // định nghĩa biến i
int main() {
b = 1.0;
i = 2;
}
,
}
{
++
(tên, ,
) .
C++
. :
}
. !=
(
).
().
.
(
, local)
,
.
register.
.
.
.
(static variable)
.
.
.
,
.
2.5
.
,
.
.
.
. (
)
.
, :
#define PI 3.14159
.
.
C++
,
.
++ .
-
)
.
18
.
,
\
.
.
.
.
3. ++
(
nay)
.
.
.
++
(function prototype).
.
.
,
.
:
<
++ (
).
.
++ .
(), C++ ,
.
(void)
(
: variable argument list).
(). Tuy nhiên nên
++,
.
.
,
.
++
.
,
,
.
4.
. : if-else, while, do,
do-while, for switch.
. Trong C++ hai t
ng 0 .
4.1
-else
if else :
else. :
if(expression)
statement
if(expression)
statement
else
statement
,
{ }.
.
.
4.3 while
.
,
. :
for(initialization; conditional; step)
statement
,
.
.
,
,
}
:
char * reverse(char *s){
int c, i, j;
for(i = 0, j = strlen(s) 1; i < j; i++, j )
{
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
4.5
break continue.
break
4.6
{
case integral_value1: statement; break;
case integral_value2: statement; break;
default: statement;
}
.
.
.
22
4.7
++ .
c .
2
16
32
4 byte.
limit.
.h.
.
2
, .
. C++ 4
: long, short,
unsigned.
. :
.
,
.
.
.