.


:




:

































 

 

 

 


, , , 1




Ͳ Dz

˲

"-в "

 

 

2007


̲Ͳ ²

ʲ ֲ
Ͳ IJͲ

 

Ͳ Dz

 

˲

"-в "

_______________________

 

 

³ ..

 

 

.

 

2007


ᒺ- c ___________ /.: .. , .. , .. - i: , 2007. - ___ .

 

: ..

..

..

 

 

.. , . .

 


.. 5

1 ++. 7

2 , , , . 28

2 ++. 39

4 ++. 46

5 ++. 54

5 ++. 80

7 proxy-. 97


 

- .

- Simula 67, 60- . . , , ( 60- .) Simula 67, ( , Fortran).

Simula 67 , 70- . - . - : C++, Ada, Smalltalk .

- C++ [1, 6, 8]. Simula. ++ 80- , AT&T. , , , 1998 . ++.

- . , 1995 . - Java, , , Internet. Microsoft - C# (C Sharp), ++ Internet-.

- - , . - . [3, 4], . , . , - -. UML [2, 5, 7, 9], 1997 . Object Management Group .


1 ++

 

, , , . , , .

++ , , -, -, .

 

. . , , . , , .

ß

class date {

public:

int day, month, year;

void set (int, int, int);

void get (int&, int&, int&);

void next ();

};

 

- . inline. .

.

 

. - date::set, .

 

void date::set (int d, int m, int y) {

day = d;

month = m;

year = y;

}

 

. . . , , ,

date d;

 

, .

ß

cout << d.day;

d.set(19,10,2001);

- . ( , , , , ). , .

public private .

 

. date , .

ß

class date {

private:

int day, month, year;

public:

void set (int,int,int);

...

};

 

, , ,

 

int day, month, year;

 

 

int date::day, date::month, date::year;

 

.

. , . , . .

 

. .

ß

class date {

int day, month, year;

public:

date(int,int,int);

date(char*);

date();

};

 

, . , ++ .

 

:

 

void main(int argc, char* argv[])

{

date d1 = date(19, 10, 2001);

date d2(19, 10, 2001); // ,

date d3 = date("19-Oct-2001");

date d4 = "19-Oct-2001"; // 1

date d5; //

}

 

, , . .

, . , . ~ . ,

~date().

 

. , . , .

date* p date. p , (*p).set(),

 

p->set()

 

.

ß

date d1;

date* p = &d1;

 

, this. -. X this :

 

X* const this;

 

- ,

 

int readme() const {/* */};

 

this, , :

 

const X *const this.

new delete

new.

ß

date* p = new date(19, 10, 2001);

 

, , 0.

 

. new , , .

 

delete.

ß

delete p;

!

static . , .

, , , .

, .

.

- .

- , :

□ , , sizeof.

class A{

public:

static int cout;

 

};

int A::cout;

A b,*c;

void main()

{

cout<<A::cout<<endl;//10

cout<<b.cout<<endl;//10

cout<<c->cout<<endl;//10

A::cout=100;

cout<<A::cout<<endl;//10

cout<<b.cout<<endl;//10

cout<<c->cout<<endl;//10

/////////////////////////////

cin.get();

}

//---------------------------------------------------------------------------

. , this. , , , , .

#include <iostream.h>

class B{

static int cout;

int data;

 

public:

static void inc_cout(){cout++;}

static int get_cout(){return cout;}

};

int B::cout(13);

void main()

{

B d,*e;

cout<<d.get_cout()<<endl;

d.inc_cout();

cout<<e->get_cout()<<endl;

cin.get();

}

//---------------------------------------------------------------------------

(const) (virtual).

, . .

.

.

- , , friend.

- , this .

- .

- .

- .

- , friend.

 

#include <iostream.h>

class TA{

int a;

int b;

public:

int d;

TA (int x=3,int y=4){a=x;b=y;}

friend void print(TA&);

friend class TB;

 

};

class TB{

public:

void inc_TA(TA& inca){inca.a++;};

void inc_TB(TA& incb){incb.b++;};

};

void print(TA &obj)

{cout<<obj.a<<"\t"<<obj.b<<endl;}

 

void main()

{

TA b,*c,d(4,5),*z;

c=new TA();

z=new TA(7,8);

print(b);

print(d); //4 5

print(*c);

print(*z);

 

delete c;

delete z;

 

TB q;

q.inc_TA(d);

q.inc_TB(d);

print(d);//5 6

 

cin.get();

}

friend .

, , . , :

□ , ;

□ main:

□ , , delete.

(-), . :

□ ;

□ const static;

□ ;

.

, .

, , , -, .

.

:

, new . .

C++ , .

, C++, :

..*?::: # ## sizeof

(-) :

□ , ( ), ;

□ ;

□ - ;

□ - ( -);

□ - static.

- : , , .

, , 1.

- operator, :

operator ( ) { }

 

 

#include <iostream.h>

class TA{

int a;

int b;

public:

TA (int x=3,int y=4){a=x;b=y;}

friend void print(TA&);

//

/* -, , , , :

*/

TA& operator++(){a++;b++;return *this;}

// :

const TA& operator=(const TA& operand2)

{if(&operand2==this) return *this;

//

//

//

a=operand2.a;b=operand2.b;

}

TA operator+(TA& operand2){

TA sum;

sum.a=a+operand2.a;

sum.b=b+operand2.b;

return sum;

}

bool operator>(TA& operand2){

return (a>operand2.a&&b>operand2.b)? true: false;

}

//

//

//

friend ostream& operator<<(ostream& out,TA &obj)

{out<<"a= "<<obj.a<<"\tb="<<obj.b;

return out;}

friend istream& operator>>(istream& in,TA &obj)

{

cout<<"Vvedite a=";

in>>obj.a;

cout<<"Vvedite b=";

in>>obj.b;

 

return in;}

 

};

 

void main()

{

TA b(4,5),c(1,1);

print(b);

b++;

print(b);

TA s=b+c;

print(s);

if (s>b)cout<<">"<<endl;

cin>>s;

cout<<s<<endl;//a=6 b=7

cin.get();

cin.get();

}

//---------------------------------------------------------------------------

void print(TA &obj)

{cout<<obj.a<<"\t"<<obj.b<<endl;}

 

 


 

 

:

 

1.

2.

3.

4.

5.

6.

7. -

 

- , , .

 

, , . .

 

1

 

, . , , , . , (, ). .

 

:

1. (+)

2. ,

3.

4.

5.

6. ,

7.

 

2

 

, . , , . , . , .

 

:

1.

2.

3. ( )

4. ( )

5.

6. (/)

7. ,

 

 

3

 

, . , , . . , .

 

:

1.

2. ,

3.

4. ( )

5. ( )

6.

7.

 

 

4

 

, . , , , , . . , , .

 

:

1.

2. ,

3.

4. ( )

5. ( )

6.

7. ,

 

5

 

, . , , . . , .

 

:

1.

2. ,

3.

4.

5.

6.

7.

 

 

6

 

, . , . . , , .

 

:

1.

2. ,

3.

4.

5.

-

6.

7. ,

 

 

7

 

, . , . , . .

 

:

1.

2. ,

3. ,

4.

5.

6.

7.

 

 

8

 

, . , , , . , . , .

 

:

1.

2. ,

3.

4.

5.

6.

7.

 

 

9

 

, . , , , . , . .

 

:

1.

2. ,

3.

4.

5.

6. ,

7. , , , .

 

10

 

, . . . , (/ ).

 

:

1. ,

2. ,

3.

4. ( )

5. ( )

6. ,

7.

 

 


, , ,

 

2.

() . , , .

 

: date birthday.

ß

class date {

int day, month, year;

public:

date(int,int,int);

date(char*);

};

 

class birthday: public date {

public:

string name;

};

 





:


: 2017-02-25; !; : 400 |


:

:

, .
==> ...

1704 - | 1526 -


© 2015-2024 lektsii.org - -

: 0.223 .