.


:




:

































 

 

 

 





.

- ++, ++. . - : , , .

++ . (). , .

. . , .

, ++ - , .

:

 

_ : < >

{

;

};

 

_ class, struct union (.. , ).

. , . . , , , .

++ , . , : public, private ( ). , public; , .

:

 

1

 

 
: class struct union
private public public

 

 

.

struct date //

{int month,day,year; // : , ,

void set(int,int,int); //

void get(int*,int*,int*); //

void next(); //

void print(); //

};

class complex //

{double re,im;

double real(){return(re);}

double imag(){return(im);}

void set(double x,double y){re = x; im = y;}

void print(){cout<<re = <<re; cout<<im = <<im;}

};

( )

_ _;

date today,my_birthday;

date *point = &today; // date

date clim[30]; //

date &name = my_birthday; //

complex x1,x2, D; // complex

complex *paint = &D; // complex

complex dim[8]; // complex

complex &Name = x2; // complex

 

, - . - . :

1. :

 

_._::_;

_. _;

, :

 

x1.re = dim[3].re =1.24; //

x1.im = 2.3;

dim[3].im = 0.0; //

:

 

_.

 

, :

 

x2.set(5.1,7); // 5.1+i*7

x1.print();//

 

2. :

 

___ -> ;

 

, pint, D complex, D :

 

complex *point = &D; // point = new complex;

point -> re = 2.3;// D

point -> im = 6.1; //

point >print();

.

. , , . () . : public, private, protected.

:

 

# include<iostream.h>

 

class

{

private: // , ..

protected:

public:

} ;

 

(public) . , . :

_.__

__.__

__->__

 

(private) . , .

(protected) .

class. (private).

.

class complex

{

double re, im; // private

public:

double real(){return re;}

double imag(){return im;}

void set(double x,double y){re = x; im = y;}

};

this

 

- , , . this :

_ *const this = _

this . this , . .

this . , - this .

this .

 

. set ( complex) .

- ( - ). . , - , .

:

_(__)

{__}

 

++ . new .

.

omplex(double re1 = 0.0,double im1 = 0.0){re = re1; im = im1;}

 

- .

:

. void .

, .

.

, , , . . , . (public).

, (T&). () . . :

_ _ (_);

_ (_);

. :

complex ss (5.9,0.15);

:

complex (5.9,0.15);

. , , . . . :

_ ()

.

class CLASS_A

{

int i; float e; char c;

public:

CLASS_A(int ii,float ee,char cc): i(8),e(i * ee + ii),(){}

...

};

.

#include <string.h>

#include <iostream.h>

class string

{

char *ch; //

int len; //

public:

//

//

string(int N = 80): len(0){ch = new char[N+1]; ch[0] = \0;}

//

string(const char *arch){len = strlen(arch);

ch = new char[len+1];

strcpy(ch,arch);}

// -

//

int& len_str(void){return len;}

//

char *str(void){return ch;}

...};

 

string .

: (const _&) (_&). , .

, T::T(const T&), . , .

, , . :

) ;

) ;

) .

, . . . , string:

string(const string& st)

{len=strlen(st.len);

ch=new char[len+1];

strcpy(ch,st.ch); }

 

, ( ).

, .

class complex{

double re;

double im;

 

public:

complex(){re=0.0;im=0.0;}

complex (double real, double image){re=real; im=image;}

};

void main(){

class complex a[20]; // ( )

class complex[2]={complex(10.2,2.4),complex(1.5,3.4)};//

 

 

- , -: ( ), - . , .

. , , , , , . , . . :

~_(){__}

, ~ ().

. (), .

, delete .

string *p=new string ();

delete p;

, , , . , , , ch string, : ~string(){delete []ch;}

, , .





:


: 2016-11-02; !; : 591 |


:

:

- , - .
==> ...

1311 - | 1249 -


© 2015-2024 lektsii.org - -

: 0.06 .