View difference between Paste ID: GnY7nJhE and m6ZE3GW7
SHOW: | | - or go back to the newest paste.
1
#include <cstdlib>
2
#include <iostream>
3
#include <string>
4
#include <vector>
5
#include <algorithm>
6
7
using namespace std;
8
9-
typedef struct {
9+
struct date
10
{
11
	unsigned int day;
12
	unsigned int month;
13-
} date;
13+
14
	
15-
typedef struct {
15+
	bool operator == (const date& d1)const 			/* We overload the == operator for later use */
16
	{
17
		return ((d1.month == month) && (d1.day == day));
18-
} friend_pair;
18+
19
};
20-
void print_friend_pair (friend_pair current) {
20+
21-
	cout << current.name << ": " << current.birthdate.day << "/" << current.birthdate.month << "/" << current.birthdate.year << endl;
21+
struct friend_pair
22-
}
22+
{
23
	date birthdate;
24-
bool date_order (friend_pair first, friend_pair second) {		/* Orders two dates without paying attention to the year */
24+
25
	
26
	void print_friend_pair () 
27
	{
28
		cout << name << ": " << birthdate.day << "/" << birthdate.month << "/" << birthdate.year << endl;
29
	};
30-
		fst = first.birthdate;
30+
	bool operator < (const friend_pair & second)const	/* We overload the < operator for later use */
31
	{							/* Orders two dates without paying attention to the year */
32
		date fst;
33-
		if (fst.month < snd.month) {
33+
34
35
		bool result;
36
37
		fst = birthdate;
38
		snd = second.birthdate;
39
40
		if (fst.month < snd.month) 
41
		{
42
			result = true;
43-
}
43+
44
			result = false;
45-
class FriendsGroup {
45+
46
			result = true;
47
		} else {
48
			result = false;
49-
	bool equal_date (friend_pair first, friend_pair second) {	/* Checks if the day and month of two dates coincide */
49+
50
		return result;
51
	};
52
};
53-
		fst = first.birthdate;
53+
54
class FriendsGroup 
55
{
56-
		return (fst.month == snd.month && fst.day == snd.day);
56+
57
	vector<friend_pair> friend_list;
58
	int friend_amount;
59-
	void add_friend (date birthdate, string friend_name) {
59+
60
	public:
61
	void add_friend (date birthdate, string friend_name) 
62
	{
63
		++ friend_amount;
64
		friend_list.resize (friend_amount);
65
		
66
		friend_pair new_friend;
67
		new_friend.birthdate = birthdate;
68
		new_friend.name = friend_name;
69-
	void get_new_friend () {
69+
70
		friend_list[friend_amount-1] = new_friend;
71
	};
72
	void get_new_friend () 
73
	{
74
		string friend_name;
75
		date birthdate;
76
		
77
		cout << "Enter the Name \n";
78
		cin >> friend_name;
79-
		while (birthdate.day > 31 || birthdate.month > 12) {
79+
80
		cout << "Enter the Date, separated by spaces (dd mm yyyy) \n";
81
		cin >> birthdate.day >> birthdate.month >> birthdate.year;
82
		
83
		while (birthdate.day > 31 || birthdate.month > 12) 
84
		{
85
			cout << "Please input the date again, separated by spaces (dd mm yyyy) \n";
86
			cin >> birthdate.day >> birthdate.month >> birthdate.year;
87-
	void initialize () {
87+
88
		add_friend (birthdate, friend_name);
89
	};
90-
	void show () {
90+
	void show () 
91
	{
92
		int i;
93
		int printing;
94
		friend_pair current;
95
		friend_pair next;
96
97-
		std::sort (friend_list.begin(), friend_list.end(), date_order);
97+
		if (friend_amount == 0)			/* If there are no friends to show, do nothing */
98
		{
99
			return;
100
		}
101-
		for (i=1; i<friend_amount; i++) {
101+
102
		std::sort (friend_list.begin(), friend_list.end() );
103-
			if (equal_date(current, next) ){
103+
104-
				print_friend_pair (current);
104+
105
		current = friend_list[0];
106
		for (i=1; i<friend_amount; i++) 
107
		{
108-
				if (printing == 1) {
108+
109-
					print_friend_pair (current);
109+
			if (current.birthdate == next.birthdate)
110
			{
111
				current.print_friend_pair ();
112
				printing = 1;
113
				current = next;
114
			} else {
115
				if (printing == 1) 
116
				{
117-
		if (printing == 1) {
117+
					current.print_friend_pair ();
118-
			print_friend_pair (current);
118+
119
					printing = 0;
120
				} else {
121
					current = next;
122
				}
123-
int main (void) {
123+
124-
	FriendsGroup * people;
124+
125-
	people = new (FriendsGroup);
125+
		if (printing == 1) 
126
		{
127
			current.print_friend_pair ();
128
		}
129-
	status = "Recieving";
129+
130
	FriendsGroup()
131-
	while (status == "Recieving") {
131+
	{
132
		friend_amount = 0;
133
		friend_list.resize (friend_amount);
134
	};
135-
		if (input == "Exit") {
135+
136
137
int main (void) 
138-
			people -> show();
138+
{
139
	FriendsGroup people;
140-
			people -> get_new_friend ();
140+
141
	string input;
142
	
143
	status = "Receiving";
144
	
145
	while (status == "Receiving") 
146-
	delete (people);
146+
	{
147
		cout << "Choose your action: Add, Show, Exit \n";
148
		cin >> input;
149
		
150
		if (input == "Exit") 
151
		{
152
			status = "Exit";
153
		} else if (input == "Show") {
154
			people.show();
155
		} else if (input == "Add") {
156
			people.get_new_friend ();
157
		} else {
158
			cout << "That is not a valid input \n";
159
		}
160
	}
161
162
	return 0;
163
}