}; // !
- :
- . , . ;
- " ". - - , ;
- , . - . ( ).
4_1.
vector. h // ,
//
#ifndef _VECTOR_H //
#define _VECTOR_H //
#include <iostream>
using std::endl;
using std::cout;
class VECTOR //
{
//
private:
int x, y; //
//
public:
// : -
//
void Assign(const int &x1, const int &y1)
{
x = x1; y = y1;
return;
}
// : .
// .
void print(void) const;
}; //
// print VECTOR
void VECTOR::print(void) const // const
//
{
cout<<"\n Coordinates of a vector: x= "
<<x<<" y= "<<y<<endl;
return;
}
#endif _VECTOR_H
class_vector.cpp //
#include "vector.h"
const int N = 5; //
Int main()
{
// v1 - VECTOR
// v_a - VECTOR
VECTOR v1, v_a[ N ];
// v1
v1.Assign(0, 0); cout<<"\n Vector v1: "; v1.print();
// v _ a
for (int i = 0; i < N; i++)
{
v_a[i].Assign(i, i+1);
cout<<"\n Vector v_a["<<i<<"]:";
|
|
v_a[i].print();
}
cout<<endl;
system (" pause ");
return 0;
}
:
, , , , . .
, ( ) , (public).
(), . .
: , .
, .
, .
, : ; ; return .
!
, VECTOR :
Class VECTOR
{
//
private:
int x, y; //
//
public:
// , .
//
VECTOR () { x = 0; y = 0;}
//
// .
//
// ;
//
VECTOR (const int &x1, const int &y1): x (x1), y (y1){ }
// (
// ):
// VECTOR (const int &x1, const int &y1) { x = x1; y = y1; }
// -
// .
//
VECTOR (const VECTOR & copy) // copy -
{
x = copy.x; y=copy.y;
}
...
};
, 4_1: VECTOR v 1, v _ a [ N ]; 6 ( v 1 v _ a). .
VECTOR v 1 (10, 10) x = 10, y = 10.
VECTOR v 2 (v 1) v 2 v 1. x, v 1. y.
. , VECTOR:
VECTOR (const int & x 1=0, const int & y 1=0): x (x 1), y (y 1) { }
|
|
, . , , . 4_1 .
(), ~ ( ). . , .
: ( ).
, !
, , ++ . (-) operator. :