-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerson.cpp
77 lines (65 loc) · 1.54 KB
/
Person.cpp
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
/*
* Title: Graphs
* Author: Isik Ozsoy
* ID: 21703160
* Section: 1
* Assignment: 3
* Description: cpp file of Person
*/
#include <string>
#include <iostream>
#include "Person.h"
using namespace std;
// Constructor
Person :: Person( int id, string name, int degree) {
this -> id = id;
this -> name = name;
this -> degree = degree;
friends = new int[degree];
}
// Default constructor
Person :: Person() {
}
Person :: Person( const Person& aPerson) {
id = aPerson.id;
name = aPerson.name;
degree = aPerson.degree;
friends = new int[degree];
for(int i = 0; i < degree; i++)
friends[i] = (aPerson.friends)[i];
}
// Destructor
Person :: ~Person() {
if(friends)
delete [] friends;
}
// Copies the given person
void Person :: createPerson(Person* personToCopy)
{
id = personToCopy->id;
name = personToCopy->name;
degree = personToCopy->degree;
friends = new int[degree];
for( int i = 0; i < degree; i++)
friends[i] = personToCopy->friends[i];
}
// Method that set the friends
void Person :: setFriends( int* friends) {
for( int i = 0; i < degree; i++)
this->friends[i] = friends[i];
}
// Returns the name of the person
string Person :: getName() {
return name;
}
// Returns the degree of the person
int Person:: getDegree() {
return degree;
}
int Person::getId() {
return id;
}
// Returns the id of the friend in the given index
int Person :: getFriendId(int i) {
return friends[i];
}