Yurttas/PL/OOL/Cplusplus/F/03/01/02/00/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   A.cpp
14*/
15
16
17#include "A.h"
18
19A::
20A(const int a) {
21  d = new int[2];
22
23  for(int i=0; i<2; ++i)
24    d[i] = a;
25}
26
27A::
28A(const A& a) {
29  d = new int[2];
30
31  for(int i=0; i<2; ++i)
32    d[i] = a.d[i];
33}
34
35A&
36A::
37operator=(const A& a) {
38  if(this==&a) return *this;
39
40  for(int i=0; i<2; ++i)
41    d[i] = a.d[i];
42
43  return *this;
44}
45
46A::
47~A() {
48  delete [] d;
49}
50
51int*
52A::
53get_d() const {
54  return d;
55}
56
57void
58A::
59set_d(const int a) {
60  for(int i=0; i<2; ++i)
61    d[i] = a;
62}
63
64void
65A::
66set_d(const int a,
67      const int b) {
68  d[0] = a;
69  d[1] = b;
70}
71
72void
73A::
74set_d(const int* a) {
75  for(int i=0; i<2; ++i)
76    d[i] = a[i];
77}
78
79ostream& operator<<(ostream& os,
80                    const A& a) {
81  for(int i=0; i<2; ++i)
82    os << a.d[i] << endl;
83
84  os << endl;
85
86  return os;
87}