-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatronsCollection.cpp
More file actions
132 lines (103 loc) · 3.36 KB
/
PatronsCollection.cpp
File metadata and controls
132 lines (103 loc) · 3.36 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
File:
PatronsCollection.cpp
*/
#include "PatronsCollection.h"
#include <iostream>
using namespace std;
//Add a new patron to the collection
void PatronsCollection::addPatronsCollection()
{
Patron newPatron;
newPatron.addPatron(); //Call the Patron's method to input details
patrons.push_back(newPatron); //Add the new patron to the vector
}
//Edit an existing patron based on ID
void PatronsCollection::editPatronsCollection()
{
int id;
//Prompt user for Patron ID Number to edit
cout << "\nEnter Patron ID Number to edit: ";
cin >> id; //Search by Patron ID Number
for (auto &patron : patrons)
{
if (patron.getId() == id) //Use getId to find the patron by ID
{
patron.editPatron(); //Call the Patron's edit method
return;
}
}
cout << "Patron ID Number does not exist." << endl; //If Patron ID Number does not match, it does not exist
}
//Delete a patron based on ID
void PatronsCollection::deletePatronsCollection()
{
int id;
//Prompt user for Patron ID Number to delete
cout << "\nEnter Patron ID Number to delete: ";
cin >> id;
for (auto it = patrons.begin(); it != patrons.end(); ++it)
{
if (it->getId() == id) //Search by Patron ID Number by using getId to find the patron by ID
{
it->deletePatron(); //Call the Patron's delete method
patrons.erase(it); //Remove the patron from the collection
return;
}
}
cout << "Patron ID Number does not exist." << endl; //If Patron ID Number does not match, it does not exist
}
//Find a patron by ID and print their details
void PatronsCollection::findPatronsCollection() const
{
int id;
//Prompt user for Patron ID Number to search
cout << "\nEnter Patron ID Number to find: ";
cin >> id;
for (const auto &patron : patrons)
{
if (patron.getId() == id) //Search by Patron ID and use getID to find the patron by ID Number
{
patron.printPatronDetails(); //Print the details if found
return;
}
}
cout << "Patron ID Number does not exist." << endl; //If Patron ID Number does not match, it does not exist
}
//Payfines for patrons
void PatronsCollection::payFinesCollection()
{
int id;
//Prompt user for Patron ID Number to pay fines
cout << "\nEnter Patron ID Number to pay fines: ";
cin >> id;
for (auto &patron : patrons) //Search by ID and use getID to find the patron by ID Number
{
if (patron.getId() == id)
{
patron.payFines(); //Call the Patron's payFines method
return;
}
}
cout << "Patron ID Number does not exist." << endl; //If Patron ID Number does not match, it does not exist
}
//Prompt user for Patron ID Number to print all Patrons collection
void PatronsCollection::printAllPatronsCollection() const
{
for (const auto &patron : patrons)
{
patron.printPatronDetails(); //Print details of each patron or Output the relevant details
}
}
//Prompt user for Patron ID Number to print single patron’s collection
void PatronsCollection::printSinglePatron(int id) const
{
for (const auto &patron : patrons)
{
patron.printPatronDetails(); //Print details of each patron
}
}
vector<Patron> PatronsCollection::getPatrons() const
{
return patrons; //Return the vector of patrons
}