Yurttas/PL/OOL/Cplusplus/F/04/02/03/01/Person.cpp

From ZCubes Wiki
Jump to navigation Jump to search
 1/*
 2   Copyright(C) 2002
 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, 2002.
11   author : Salih Yurttas.
12
13   Person.cpp
14*/
15
16#include "Person.h"
17
18Person::
19Person() {
20  last_name="";
21  m_i='\0';
22  first_name="";
23}
24
25Person::
26Person(const Person& a) {
27  last_name = a.last_name;
28
29  m_i = a.m_i;
30
31  first_name = a.first_name;
32}
33
34void
35Person::
36set_name(string& s) {
37  int p = s.find(' ',0);
38  last_name=s.substr(0,p);
39  s.erase(0,p+1);
40
41  p = s.find(' ',0);
42  m_i=s.substr(0,p)[0];
43  s.erase(0,p+1);
44
45  p = s.find(' ',0);
46  first_name=s.substr(0,p);
47  s.erase(0,p+1);
48}
49
50void
51Person::
52set_name(const string& l,
53         const char m,
54         const string& f) {
55  last_name = l;
56
57  m_i = m;
58
59  first_name = f;
60}
61
62ostream&
63operator<<(ostream& os,
64           const Person& a) {
65  string s_out;
66
67  s_out += a.last_name;
68  s_out += " ";
69  s_out += a.m_i;
70  s_out += " ";
71  s_out += a.first_name;
72  s_out += " ";
73
74  if(s_out.length()<16)
75    s_out += "\t";
76
77  os << s_out;
78
79  if(s_out.length()<24)
80    os << "\t";
81
82  os << endl;
83
84  return os;
85}