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

C++,

Dev-C++,
,

. .



. .
http://ani.cmc.msu.ru/geol

2010/2011

. . ( ) . . . 2010 1 / 36

1
2
3
4
5
6 C++
7 -
8
9
10
11
12
13
14
15
. . ( ) . . . 2010 2 / 36

, ,

I ,


. .
I
I
,
, ,

I :
I .-. (. )
I . ()
I ( )
pozdneev@cmc.msu.ru

. . ( ) . . . 2010 3 / 36

,
I :
I
I ( ) 16
I ( )
I :
I
I ,

I :
I
I .
I
I :
I

I
I
. . ( ) . . . 2010 4 / 36

I
I
I C++
I Maple

. . ( ) . . . 2010 5 / 36

. .
++
.: ,
2000, 2004, 2008

http://www.finstat.ru/podbelsky-cpp.htm

. . ( ) . . . 2010 6 / 36

I C++
Dev-C++
Windows
I Maple 10
I :
I Microsoft Visual C++ (Windows, )
I Eclipse (Windows/Linux, )
I GCC (Windows/Linux, )
I Intel C (Windows/Linux, Linux
)
I :
I Maxima
I Axiom
I - Windows:
I Mozilla Firefox

I Opera

. . ( ) . . . 2010 7 / 36

. . ( ) . . . 2010 8 / 36
C++
Dev-C++

. . ( ) . . . 2010 9 / 36
C++

I
I C++ main
Main MAIN

1 # include < iostream >


2 using namespace std ;
3

4 int main ()
5 {
6 cout << " Hello , World !" << endl ;
7 system (" pause ");
8 return 0;
9 }

. . ( ) . . . 2010 10 / 36
C++
hello.cpp

. . ( ) . . . 2010 11 / 36
C++

. . ( ) . . . 2010 12 / 36
C++

I , Hello, World!
I Enter,

. . ( ) . . . 2010 13 / 36
C++

I , Dev-C++

. . ( ) . . . 2010 14 / 36
C++

1 # include < iostream >
2 using namespace std ;
3
4 int main ()
5 {
6 cout << " Hello , World !" << endl ;
7 system (" pause "); // wait for user to press any key
8 return 0;
9 }

I 1: (streams) / (Input/Output)
I 2: C++
I 3: // ;

I 4: main() C++
; int ,

. . ( ) . . . 2010 15 / 36
C++
()

1 # include < iostream >


2 using namespace std ;
3
4 int main ()
5 {
6 cout << " Hello , World !" << endl ;
7 system (" pause "); // wait for user to press any key
8 return 0;
9 }

I 5, 9:
I 6: cout ,

I 6: , , <<
I 6: endl

. . ( ) . . . 2010 16 / 36
C++
()

1 # include < iostream >


2 using namespace std ;
3
4 int main ()
5 {
6 cout << " Hello , World !" << endl ;
7 system (" pause "); // wait for user to press any key
8 return 0;
9 }

I 7: system("pause")

I 8: ;
0

. . ( ) . . . 2010 17 / 36
C++

I
I , ,

I
:

1 # include < iostream >


2 using namespace std ; int main (){ cout < <
3 " Hello , World !" < < endl ; system (" pause "); return 0;}

. . ( ) . . . 2010 18 / 36
C++
()

I , //,

I
, !
I C++ ;
,

I #include <iostream> :
iostream
I , , .h
(#include <iostream.h>)

. . ( ) . . . 2010 19 / 36
C++

I ,
: I love C++
I cout?
I cout?

. . ( ) . . . 2010 20 / 36
-

I ,

I -,

I -
,
I :

. . ( ) . . . 2010 21 / 36
- Hello, World!

. . ( ) . . . 2010 22 / 36
- Hello, World! ()

. . ( ) . . . 2010 23 / 36

I :
I
I
I

. . ( ) . . . 2010 24 / 36

a + x = b

: a + x = b,
a b
:
1 #i n c l u d e <i o s t r e a m >
2 u s i n g namespace s t d ;
3
4 i n t main ( )
5 {
6 double a , b ;
7
8 c o u t << " I n p u t a : ";
9 c i n >> a ;
10
11 c o u t << " I n p u t b : ";
12 c i n >> b ;
13
14 double x = b a ;
15 c o u t << " Root o f e q u a t i o n a+x=b i s " << x << e n d l ;
16
17 system (" pause " ) ;
18 return 0;
19 }

. . ( ) . . . 2010 25 / 36

a + x = b ()

I
-
I
I C++

I C++
,
I

I
( ,
)

. . ( ) . . . 2010 26 / 36


1 int main ()
2 {
3 double a , b ;
4
5 cout << " Input a : ";
6 cin >> a ;

1 double x = b - a ;
2 cout << " Root of equation a + x = b is " << x << endl ;

I 4: a b,

I 9: , , a
I 14: x

I 15: ,
. . ( ) . . . 2010 27 / 36

I a + b a b; a b

I ,
?

. . ( ) . . . 2010 28 / 36
C++

I int
I , 4
I 2 147 483 648 2 147 483 647
I double
I , 8
I 1,797693 10308
I 2,225074 10308
I char
I , 1
I ,
,
I ,
,

. . ( ) . . . 2010 29 / 36


I az, AZ
I _
I 09

I
I _
I (int, return, . . . )
:
I : a, b, x1, y_42, day_of_week,
num_of_students, route_66
I : 3rd_law, double
I : _temp_var, new_var_

. . ( ) . . . 2010 30 / 36

I ,
,
,

I = ,
=
, :
I +
I
I *
I / (6/4 1, 6.0/4 1.25, 6/4.0 1.25)
I %
(6 % 4 2)

. . ( ) . . . 2010 31 / 36

C++

I ,

, ,
I , //,

1 int main () { // the beginning of the main function


2 double pi , e ; // the pi and the e numbers
3 return 0; // exit point of the function
4 // you may comment empty lines as well
5 }

. . ( ) . . . 2010 32 / 36

C
I :
/*<characters>*/

1 /* Some long comment ,


2 that could explain ,
3 what this function is doing
4 */
5 int main () {
6 /* such comments are useful */
7 /* to disable some parts of the code */
8 /*
9 double a , b , c ;
10 cout << a << << b <<
11 << c << endl ;
12 */
13 return 0;
14 }

. . ( ) . . . 2010 33 / 36

,
.
. , :
1 int a = 13/5;
2 int b = 13%5;
3 int c = 13.0/5;
4 double d = 13/5;
5 double e = 13%5;
6 double f = 13.0/5;
7 double g = 13/5 + 2/5;
8 double h = 13.0/5 + 2.0/5;
9 int i = 13.0/5 + 2.0/5;

. . ( ) . . . 2010 34 / 36

1. a b. ,

(.. a
b )
2. x. x 4 .
?
3. x. x 7
.
4. x. x 13
.
5. . .
6. .
(
).

. . ( ) . . . 2010 35 / 36

1. x. x 6
.
2. x. x 8
.
3. x. x 21
.
4. . .
5. . .
:
1. a b. ,
,
-
2. : h, m, s. ( )

h , m , s
.
. . ( ) . . . 2010 36 / 36