-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerson.cpp
97 lines (82 loc) · 1.78 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* File: Person.cpp
*
* This file contains the implementation of the methods of the Person class
*
* Designed by: Team 4
*
* List of methods:
* constructors and destructor
* getName: return a person's name
* getAge: return a person's age
* getDiscountRatio: return a person's discount rate according to one's age
* operator=: overloaded assignment operator
*/
#include "Person.h"
/***********************
* CONSTRUCTOR
***********************/
Person::Person(string n, int a)
{
name = n;
age = a;
}
/*************************
* COPY CONSTRUCTOR
**************************/
Person::Person(const Person &person1)
{
name = person1.name;
age = person1.age;
}
/****************************
* function: getName
* parameter:
* return: void
* return the person's name
*****************************/
string Person::getName()
{
return name;
}
/****************************
* function: getAge
* parameter:
* return: void
* return the person's age
*****************************/
int Person::getAge()
{
return age;
}
/*************************************
* function: getDiscountRatio
* parameter:
* return: void
* return the person's discount rate
*************************************/
double Person::getDiscountRatio()
{
/*
* children (12 and under) pay 75% of the ticket price
* adults (from 12 to 65 exclusively) pay full price
* seniors (65 and above) pay half price
*/
if (age <= 12)
return 0.75;
else if (age < 65)
return 1;
else
return 0.5;
}
/*******************************
* overload assignment operator
* parameter:
* return: void
* return the person's name
*******************************/
void Person::operator=(const Person &person)
{
name = person.name;
age = person.age;
}