-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperson.cpp
More file actions
78 lines (68 loc) · 1.31 KB
/
person.cpp
File metadata and controls
78 lines (68 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//implementation for the person struct
//person.cpp
//Author: Jayant Gandhi
//Date Created: 10/3/2012
//Date Last Edited:
//#include "stdafx.h"
#include "person.h"
#include <iostream>
#include <string>
#include <cstring>
#include <string.h>
using namespace std;
ostream& operator<< (ostream& oStr, const person& myPerson)
{
oStr << myPerson.name <<" - "<< myPerson.age << "yrs old" << endl;
return oStr;
}
person::person()
{
name=NULL;
age=0;
}
person::person(char* personName, int personAge)
{
//int length = strlen(personName);
name= personName;
//for (int i=0; i <20; i++)
//name[i]=personName[i];
//name[length]=0;
age=personAge;
}
person::person(const person& otherPerson)
{
//int length = strlen(otherPerson.name);
name= otherPerson.name;
//for (int i=0; i <20; i++)
//name[i]=otherPerson.name[i];
//name[length]=0;
age=otherPerson.age;
}
person::~person()
{
initializePerson();
}
void person::initializePerson()
{
name=NULL;
age=0;
}
person& person::operator= (const person& rhs)
{
//int length = strlen(rhs.name);
//initializePerson();
name= rhs.name;
//for (int i=0; i <20; i++)
//name[i]=rhs.name[i];
//name[length]=0;
age=rhs.age;
return *this;
}
bool person::operator< (const person& rhs) const
{
int lessThan = strcmp(name, rhs.name);
if (lessThan<0)
return true;
else
return false;
}