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 E.cpp
14*/
15
16
17#include "E.h"
18
19E::
20E(const int a,
21 const int b) : s(a),
22 d(new int[s]) {
23 for(int i=0; i<s; ++i)
24 d[i] = b;
25}
26
27E::
28E(const E& a) : s(a.s),
29 d(new int[a.s]) {
30 for(int i=0; i<s; ++i)
31 d[i] = a.d[i];
32}
33
34E&
35E::
36operator=(const E& a) {
37 if(this==&a) return *this;
38
39 delete [] d;
40
41 s = a.s;
42 d = new int[a.s];
43
44 for(int i=0; i<s; ++i)
45 d[i] = a.d[i];
46
47 return *this;
48}
49
50E::
51~E() {
52 delete [] d;
53}
54
55int
56E::
57get_s() const {
58 return s;
59}
60
61int*
62E::
63get_d() const {
64 return d;
65}
66
67void
68E::
69set_d(const int a) {
70 for(int i=0; i<s; ++i)
71 d[i] = a;
72}
73
74void
75E::
76set_d(const int a,
77 const int b) {
78 d[a] = b; // assuming a is in valid range!
79 // [ exception-handling is needed ]
80}
81
82void
83E::
84set_d(const int* a) {
85 for(int i=0; i<s; ++i) // assuming d and a has matching sizes
86 d[i] = a[i]; // [ exception-handling is needed ]
87}
88
89ostream& operator<<(ostream& os,
90 const E& a) {
91 for(int i=0; i<a.s; ++i)
92 os << a.d[i] << endl;
93
94 os << endl;
95
96 return os;
97}