Yurttas/PL/OOL/Cplusplus/F/05/01/02/00/I A.cpp

 1/*
 2   Copyright(C) 1998
 3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4
 5   Permission to use, copy, modify, and distribute this
 6   software and its documentation for EDUCATIONAL purposes
 7   and without fee is hereby granted provided that this
 8   copyright notice appears in all copies.
 9
10   date   : January 1, 1998.
11   authorĀ : Salih Yurttas.
12
13   I_A.cpp
14*/
15
16
17#include "I_A.h"
18
19I_A::
20I_A() : s(0),
21        d(NULL) {
22}
23
24I_A::
25I_A(const I_A& o) : s(o.s),
26                    d(new int[s]) {
27  for(int i=0; i<s; ++i)
28    d[i] = o.d[i];
29}
30
31I_A&
32I_A::
33operator=(const I_A& o) {
34  if(this==&o) return *this;
35
36  delete [] d;
37
38  s = o.s;
39  d = new int[s];
40
41  for(int i=0; i<s; ++i)
42    d[i] = o.d[i];
43
44  return *this;
45}
46
47I_A::
48~I_A() {
49  delete [] d;
50  d = NULL;
51  s = 0;
52}
53
54int
55I_A::
56get_s() const {
57  return s;
58}
59
60int
61I_A::
62get_d(const int index) const { // assuming index in in valid range
63  return d[index];             // [ exception-handling is needed ]
64}
65
66int*
67I_A::
68get_d() const {
69  return d;
70}
71
72void
73I_A::
74set_d(const int size,
75      const int value) {
76  delete [] d;
77
78  s = size;
79  d = new int[s];
80
81  for(int i=0; i<s; ++i)
82    d[i] = value;
83}
84
85ostream&
86operator<<(ostream& os,
87           const I_A& o) {
88  for(int i=0; i<o.s; ++i)
89    os << o.d[i] << endl;
90
91  return os;
92}