:

  1. - .
  2. .

1.      -

:

class nested() //

{ //

};

class outer //

{ nested object; // -

..

};

#include <iostream.h>

class point //

{ int x,y;

public:

point(int a=0,int b=0)

{ x=a; y=b; cout<< point <<x<< <<y<<\n; }

void out() { cout<<:<<x<< <<y<<\n; }

};

class circle //

{ point centre; // -

int rad;

public:

circle(int a,int b,int r):centre(a,b),rad(r)

{ cout<< circle <<rad<<\n; }

};

void main()

{ circle c(1,2,9); } // c

point 1 2

circle 9

c.centre.out(); //: :1 2

 

2.     

:

class outer //

{ private:

class nested1 // 1

{ // 1

};

public:

class nested2 // 2

{ // 2

};

.

};

(point) public circle

#include<iostream.h>

#include<math.h>

class circle //

{ public:

class point //

{ float x,y;

public:

point() {x=y=0;}

point(float abs,float ord) {x=abs;y=ord;}

void print() {cout<<x<<","<<y;}

};

private:

point p;

float rad;

public:

circle(const point &a,float r); //

void print();

void calcul(float &p,float &s);

};

circle::circle(const point&a,float r):p(a),rad(r) {}

void circle::print()

{cout<<": ";p.print();cout<<endl;

cout<<": "<<rad;cout<<endl;

}

void circle::calcul(float &p,float &s)

{p=2*3.14*rad;

s=3.14*rad*rad;

}

void main()

{ point a(1,1);

cout<<"ocka : ";a.print();cout<<endl;

cout<<"ocka : ";a.circle::point::print();cout<<endl;

circle c(a,6);

cout<<"circle"<<endl;

c.print();

float p,s;

c.calcul(p,s);

cout<<": "<<p<<endl;

cout<<": "<<s<<endl;

}

:1,1

:1,1

circle

:1,1

:6

:37.68

:113.04

:

class outer //

{ private:

class nested1 // 1

{ friend class outer;

// 1

};

public:

class nested2 // 2

{ friend class outer;

// 2

};

.

};

private - x y point.

circle,

(d).

#include<iostream.h>

#include<math.h>

class circle

{ public:

class point

{ friend class circle;

float x,y;

public:

point() {x=y=0;}

point(float abs,float ord) {x=abs;y=ord;}

void print() {cout<<x<<","<<y;}

};

private:

point p;

float rad;

public:

circle(const point &a,float r);

void print();

void calcul(float &pe,float &s,float &d);

};

circle::circle(const point&a,float r):p(a),rad(r) {}

void circle::print()

{cout<<": ";p.print();cout<<endl;

cout<<": "<<rad;cout<<endl;

}

void circle::calcul(float &pe,float &s,float &d)

{pe=2*3.14*rad;

s=3.14*rad*rad;

d=sqrt((p.x-0)*(p.x-0)+(p.y-0)*(p.y-0));

}

void main()

{ point a(1,1);

cout<<"ocka : ";a.print();cout<<endl;

cout<<"ocka : ";a.circle::point::print();cout<<endl;

circle c(a,6);

cout<<"circle"<<endl;

c.print();

float p,s,d;

c.calcul(p,s,d);

cout<<": "<<p<<endl;

cout<<": "<<s<<endl;

cout<<" :"<<d<<endl;

}

 

:1,1

:1,1

circle

:1,1

:6

:37.68

:113.04

:1.41421