enum Exceptions {EOutOfBounds, EOutOfMemory,
EDivByZero, EDiskAccess, ESelfAssign};
typedef int data_type;
class Vec
{
public:
// LIFECYCLE
Vec(int n); // default constructor
Vec(const Vec&); // copy constructor
virtual ~Vec() {delete [] data;} // destructor
// OPERATORS
const Vec& operator=( const Vec&); //
assignment operator
data_type operator[](int i) {return data[i];}
// OPERATIONS
void Init();
void Show();
// ACCESS
// INQUIRY
data_type *data;
protected:
private:
int sz, // size of array
lb, // lower bound
hb // higher bound
;
void at(int i);
};
// METHODS
//
Vec::Vec(int n) : sz(n), lb(0), hb(10)
{
at(n);
data = new data_type[n];
if(!data)
throw EOutOfMemory;
Init();
};
Vec::Vec(const Vec& v) // copy constructor
{
this->sz =v.sz;
this->lb =v.lb;
this->hb =v.hb;
data = new data_type[sz];
for(int i=0; i<sz; i++)
data[i] =v.data[i];
};
void
Vec::Init()
{
for(int i=0; i<sz; i++)
data[i] =i;
};
void
Vec::Show()
{
for(int i=0; i<sz; i++)
cout<<data[i];
};
void
Vec::at(int i)
{
if(i<lb || i>hb)
throw EOutOfBounds;
};
const Vec&
Vec::operator=(const Vec& v)
{
if(this == &v)
throw ESelfAssign;
for(int i=0; i<sz; i++)
data[i] =v.data[i];
return *this;
};