Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "PatronList.h"
- #include<iomanip>
- void PatronList::AddPatron(Patron newPatron){
- patrons.push_back(newPatron);
- }
- void PatronList::DeletePatron(){
- string name;
- cout << "Please provide the name of the patron you wish to delete: " << endl;
- getline(cin, name);
- bool found;
- for(i = 0; i < patrons.size(); ++i)
- {
- if(name == patrons.at(i).GetName())
- {
- found = true;
- patrons.erase(patrons.begin() + i);
- }
- }
- if(found == false)
- {
- cout << "Patron not found" << endl;
- }
- }
- void PatronList::EditPatron(){
- char choice;
- int location, userNum;
- string input;
- location = FindPatron();
- cout << "Edit profile. Please select which field to edit: " << endl;
- cout << "n - Name" << endl;
- cout << "i - ID" << endl;
- cout << "b - balance" << endl;
- cout << "l - number of books" << endl;
- switch(choice){
- case 'n':
- cout << "Change name to: ";
- getline(cin, input);
- patrons.at(location).SetName(input);
- break;
- case 'i':
- cout << "Change ID to: ";
- cin >> userNum;
- patrons.at(location).SetID(userNum);
- break;
- case 'b':
- cout << "Change balance to: ";
- cin >> userNum;
- patrons.at(location).SetBalance(userNum);
- break;
- case 'l':
- cout << "Change the number of books to:";
- cin >> userNum;
- patrons.at(location).SetNumBooks(userNum);
- break;
- }
- }
- unsigned int PatronList::FindPatron(){
- string criterion;
- char choice;
- int location = -1, userNum;
- cout << "Searching for Patron, please select search criteria: " << endl;
- cout << "--MENU--" << endl;
- cout << "n - Name" << endl;
- cout << "i - ID" << endl;
- cin >> choice;
- switch(choice)
- {
- case 'a':{
- cout << "Please confirm the name of the patron:" << endl;
- getline(cin, criterion);
- for(i = 0; i < patrons.size(); ++i)
- {
- if(criterion == patrons.at(i).GetName())
- {
- location = i;
- }
- }
- }
- break;
- case 't':{
- cout << "Please confirm the ID number:" << endl;
- cin >> userNum;
- for(i = 0; i < patrons.size(); ++i)
- {
- if(userNum == patrons.at(i).GetID())
- {
- location = i;
- }
- }
- }
- break;
- }
- if(location == -1)
- {
- cout << "Invalid Entry. No book found.";
- }
- return location;
- }
- void PatronList::PrintPatrons(){
- unsigned int index = FindPatron();
- cout << "Name: " << patrons.at(index).GetName() << endl;
- cout << "ID: " << patrons.at(index).GetID() << endl;
- cout << "Balance: " << patrons.at(index).GetBalance() << endl;
- cout << "Number of books out: " << patrons.at(index).GetNumBooks() << endl;
- }
- void PatronList::PrintAll(){
- for(i = 0; i < patrons.size(); ++i){
- cout << "Name: " << patrons.at(i).GetName() << endl;
- cout << "ID: " << patrons.at(i).GetID() << endl;
- cout << "Balance: " << patrons.at(i).GetBalance() << endl;
- cout << "Number of books out: " << patrons.at(i).GetNumBooks() << endl << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment