Yurttas/PL/OOL/Cplusplus/F/04/02/03/00/Animal.cpp

From ZCubes Wiki
Revision as of 22:29, 6 November 2013 by MassBot1 (talk | contribs) (Created page with "<syntaxhighlight lang="cpp" line start="1" enclose="div">/* Copyright(C) 2001 All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc.. Perm...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
 1/*
 2   Copyright(C) 2001
 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   : June 1, 2001.
11   author : Salih Yurttas.
12
13   Animal.cpp
14*/
15
16#include <cstring>
17
18#include <iostream>
19
20using namespace std;
21
22#include "Animal.h"
23
24Animal::  
25Animal() {
26  name = new char[1];
27  *name = '\0';
28  
29  age = 0;
30}
31
32Animal::
33Animal(const Animal& a) {
34  name = new char[strlen(a.name)+1];
35  strcpy(name,a.name);
36  age = a.age;
37}
38
39Animal::
40~Animal() {
41  delete [] name;
42}
43
44Animal&
45Animal::
46operator=(const Animal& a) {
47  if(this==&a) return *this;
48
49  delete [] name;
50
51  name = new char[strlen(a.name)+1];
52  strcpy(name, a.name);
53
54  age = a.age;
55
56  return *this;
57}
58
59char* 
60Animal::
61get_name() const {
62  return name;
63}
64
65int
66Animal::
67get_age() const {
68  return age;
69}
70
71void 
72Animal::
73set_name(const char* s) {
74  delete [] name;
75  name = new char[strlen(s)+1];
76  strcpy(name,s);
77}
78
79void 
80Animal::
81set_age(const int i) {
82  age = i;
83}
84
85void
86Animal::
87print() const {
88  cout << "Name: " << name << endl;
89  cout << "Age: " << age << endl;
90  cout << endl;
91}