Yurttas/PL/OOL/Cplusplus/F/03/01/02/00/D.cpp

Revision as of 21:54, 6 November 2013 by MassBot1 (talk | contribs) (Created page with "<syntaxhighlight lang="cpp" line start="1" enclose="div">/* Copyright(C) 1998 All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc.. Perm...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  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   D.cpp
 14*/
 15
 16
 17#include "D.h"
 18
 19D::
 20D(const int a,
 21  const int b) {
 22  s = a;
 23  d = new int[s];
 24
 25  for(int i=0; i<s; i++)
 26    d[i] = b;
 27}
 28
 29D::
 30D(const D& a) {
 31  s = a.s;
 32  d = new int[a.s];
 33
 34  for(int i=0; i<s; i++)
 35    d[i] = a.d[i];
 36}
 37
 38D&
 39D::
 40operator=(const D& a) {
 41  if(this==&a) return *this;
 42
 43  delete [] d;
 44
 45  s = a.s;
 46  d = new int[a.s];
 47
 48  for(int i=0; i<s; i++)
 49    d[i] = a.d[i];
 50
 51  return *this;
 52}
 53
 54D::
 55~D() {
 56  delete [] d;
 57}
 58
 59int
 60D::
 61get_s() const {
 62  return s;
 63}
 64
 65int*
 66D::
 67get_d() const {
 68  return d;
 69}
 70
 71void
 72D::
 73set_d(const int a) {
 74  for(int i=0; i<s; i++)
 75    d[i] = a;
 76}
 77
 78void
 79D::
 80set_d(const int a,
 81      const int b) {
 82  d[a] = b; // assuming a is in valid range!
 83            // [ exception-handling is needed ]
 84}
 85
 86void
 87D::
 88set_d(const int* a) {
 89  for(int i=0; i<s; i++) // assuming d and a has matching sizes
 90    d[i] = a[i];         // [ exception-handling is needed ]
 91}
 92
 93ostream& operator<<(ostream& os,
 94                    const D& a) {
 95  for(int i=0; i<a.s; i++)
 96    os << a.d[i] << endl;
 97
 98  os << endl;
 99
100  return os;
101}