-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpersonclasshelpers.h
More file actions
118 lines (106 loc) · 1.99 KB
/
personclasshelpers.h
File metadata and controls
118 lines (106 loc) · 1.99 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
int strcmpi(char s1[],char s2[]);
using namespace std;
class Person
{
public:
char firstname[15];
char lastname[15];
int age;
Person()
{
strcpy(firstname, "ND");
strcpy(lastname, "ND");
age = 0;
}
Person(char fname[], char lname[], int a)
{
strcpy(firstname, fname);
strcpy(lastname, lname);
age = a;
}
void display();
string getName();
int getAge();
void setAge(int a);
void setName(char fname[], char lname[]);
bool operator<(Person p);
bool operator>(Person p);
bool operator==(Person p);
};
void Person::display()
{
cout<<endl<<"Name :"<<getName()<<" || Age : "<<getAge()<<endl;
}
string Person::getName()
{
char fullname[30];
strcpy(fullname, firstname);
strcat(fullname, " ");
strcat(fullname, lastname);
return fullname;
}
int Person::getAge()
{
return age;
}
void Person::setAge(int a)
{
age = a;
}
void Person::setName(char fname[], char lname[])
{
strcpy(firstname, fname);
strcpy(lastname, lname);
}
bool Person::operator<(Person p)
{
if (age == p.getAge())
{
if (strcmpi(firstname, p.firstname) < 0)
return true;
else
return false;
}
else
{
return age < p.getAge();
}
}
bool Person::operator>(Person p)
{
if (age == p.getAge())
{
if (strcmpi(firstname, p.firstname) > 0)
return true;
else
return false;
}
else
{
return age > p.getAge();
}
}
bool Person::operator==(Person p)
{
return age == p.getAge();
}
int strcmpi(char s1[],char s2[])
{
char s3[15];
char s4[15];
strcpy(s3,s1);
strcpy(s4,s2);
for(int i=0;s3[i]!=0;i++)
{
s3[i]=toupper(s3[i]);
}
for(int i=0;s2[i]!=0;i++)
{
s4[i]=toupper(s4[i]);
}
return strcmp(s3,s4);
}