Yurttas/PL/OOL/Cplusplus/F/03/02/01/00/06/S.cpp
Jump to navigation
Jump to search
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 S.cpp
14*/
15
16
17#include <cstring>
18
19using namespace std;
20
21#include "S.h"
22
23S::
24S(const char *a) {
25 if(a) {
26 l = strlen(a);
27 s = new char[l+1];
28 strcpy(s,a);
29 }
30 else {
31 l = 0;
32 s = new char[l+1];
33 *s = '\0';
34 }
35}
36
37S::
38S(const S& a) {
39 if(a.s) {
40 l = strlen(a.s);
41 s = new char[l+1];
42 strcpy(s,a.s);
43 }
44 else {
45 l = 0;
46 s = new char[l+1];
47 *s = '\0';
48 }
49}
50
51S::
52~S() {
53 delete [] s;
54}
55
56S&
57S::
58operator=(const S& a) {
59 if(this==&a) return *this;
60
61 delete [] s;
62
63 l = strlen(a.s);
64 s = new char[l+1];
65
66 strcpy(s, a.s);
67}
68
69bool
70S::
71operator==(const S& a) {
72 return (strcmp(s, a.s)==0);
73}
74
75ostream&
76operator<<(ostream& os,
77 const S& a) {
78 os << a.s << endl;
79
80 return os;
81}