.


:




:

































 

 

 

 


-




 

-. :

static _ _ ().

.

- . , . , this.

- . . :

_:: _ ( );

1 _ .

# include <stdio. h >

class A

{

public:

static void stat_func ()

{

puts ( !);

}

};

void main ()

{

A:: static_func (); // .

}

2 .

 

#include<stdio.h>

class coord

{

static float x;

float y;

public:

coord(float a):y(a)

{

}

static void f_stat()

{

puts( =);

scanf(%f,&x);

printf(x=%f\n,x);

}

void f_non _stat()

{

puts( =);

scanf(%f,&x);

printf(x=%f y=%f\n,x,y);

}

}

float coord::x=12.5;// .

void main()

{

coord w(45);// w.x=12.5;w.y=45.

w.f_stat();//, this // .

w.f_non_stat();

coord::f_stat();// // .

}

. y. - f_stat() x. y . - . - f_non_stat() x. , , static .

 

-

const -. . :

Class coord

{

Const int x, y;

public:

coord (int a, int b): x(a), y(b)

{

}

};

-, -.

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

onst. :

Class A

{

===========

};

Void main ()

{

const A w; // w -

}

- :

Class A

{

===========

public:

_ _ () const

{

===========

}

};

.

# include <stdio.h>

Class A

{

Int x, y;

public:

A ()

{

}

A (int a, int b)

{

x=a;

y=b;

}

//

//

Void p_const () const

{

x=12; // Cannot modify a const object

y=15; // Cannot modify a const object

}

//

Void p_non_const ()

{

x=12;

y=15;

}

};

Void main ()

{

const A w (1,2); // w -

A q; // q -

w.p_const (); //

q.p_const (); //

w.p_non_const (); // Warning: non-const

// function A::p_non_const () called for

// const object.

// p_non_const () .

}

! -. =12; =15, . , , - . , , p_const () :

Void p_const () const

{

puts ( , );

scanf (%i%i, &x, &y);

}

22

. , class student, class teacher, class officer -, , , . .. class man, , -. : class student, class teacher, class officer. , , -.

.. . , , . :

lass Base

{

.

.

.

};

lass Derived: _ Base

{

.

.

.

};

_ private, protected public. , private public .

_ . .

 

 

_
public ublic rotected private ublic rotected private
protected ublic rotected private rotected rotected private
private ublic rotected private rivate rivate rivate

- ( ublic).

. , . .

.

 

lass

{

.

.

. };

lass

{

..

.

};

lass : ublic , ublic

 

{

.

.

};

. . class man. lass student. , rotected , .

 

#include<stdio.h>

class man

{

rotected:

char* name;//

char*address;//

int age;//

ublic:

void get_man_info()

{

name=new char[15];

address=new char[20];

puts( );

fflush(stdin);

scanf(%s,name);

puts( );

fflush(stdin);

scanf(%s, address);

puts( );

scanf(%i, &age);

}

void put_man_info()

{

printf( %s. % s. %i\n,name,address,age);

}

}: // man

class student:public man

{

char* group; //

ublic:

void get_stud_info()

{

group =new char[10];

puts( );

fflush(stdin);

scanf(%i, group);

}

void put_stud_info()

{

printf( %s. % s. . % s \n,name,address,age, group);// - .

}

}

void main

{

man x;//

x.get_man_info();

x.put_man_info();

student y; //

y.get_man_info();

y.get_stud_info();

y.put_stud_info();

}

y get_man_info(), - man. y.put_stud_info() y.name, y.address, y.age y.group.

, class student , , class stud_sport (-). class student group rotected. stud_sport - - student, man, student.

 

 





:


: 2015-11-05; !; : 714 |


:

:

.
==> ...

1273 - | 1256 -


© 2015-2024 lektsii.org - -

: 0.033 .