Guest User

Untitled

a guest
Apr 18th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.00 KB | Source Code | 0 0
  1. #include "PatronList.h"
  2. #include<iomanip>
  3. void PatronList::AddPatron(Patron newPatron){
  4.     patrons.push_back(newPatron);
  5. }
  6.     void PatronList::DeletePatron(){
  7.         string name;
  8.         cout << "Please provide the name of the patron you wish to delete: " << endl;
  9.         getline(cin, name);
  10.         bool found;
  11.        
  12.         for(i = 0; i < patrons.size(); ++i)
  13.         {
  14.             if(name == patrons.at(i).GetName())
  15.             {
  16.                 found = true;
  17.                 patrons.erase(patrons.begin() + i);
  18.             }
  19.         }
  20.         if(found == false)
  21.         {
  22.             cout << "Patron not found" << endl;
  23.         }
  24.        
  25.     }
  26.     void PatronList::EditPatron(){
  27.         char choice;
  28.         int location, userNum;
  29.         string input;
  30.        
  31.         location = FindPatron();
  32.         cout << "Edit profile. Please select which field to edit: " << endl;
  33.         cout << "n - Name" << endl;
  34.         cout << "i - ID" << endl;
  35.         cout << "b - balance" << endl;
  36.         cout << "l - number of books" << endl;
  37.        
  38.    
  39.        
  40.            switch(choice){
  41.                case 'n':
  42.                cout << "Change name to: ";
  43.                getline(cin, input);
  44.                patrons.at(location).SetName(input);
  45.                break;
  46.                
  47.                case 'i':
  48.                cout << "Change ID to: ";
  49.                cin >> userNum;
  50.                patrons.at(location).SetID(userNum);
  51.                break;
  52.                
  53.                case 'b':
  54.                cout << "Change balance to: ";
  55.                cin >> userNum;
  56.                patrons.at(location).SetBalance(userNum);
  57.                break;
  58.                
  59.                case 'l':
  60.                cout << "Change the number of books to:";
  61.                cin >> userNum;
  62.                patrons.at(location).SetNumBooks(userNum);
  63.                break;
  64.                
  65.                
  66.                
  67.            }
  68.        
  69.        
  70.        
  71.        
  72.     }
  73.     unsigned int PatronList::FindPatron(){
  74.        string criterion;
  75.        char choice;
  76.         int location = -1, userNum;
  77.        
  78.         cout << "Searching for Patron, please select search criteria: " << endl;
  79.          cout << "--MENU--" << endl;
  80.        cout << "n - Name" << endl;
  81.        cout << "i - ID" << endl;
  82.        
  83.        
  84.        cin >> choice;
  85.        
  86.        
  87.      
  88.        switch(choice)
  89.        {
  90.            
  91.            case 'a':{
  92.            cout << "Please confirm the name of the patron:" << endl;
  93.            getline(cin, criterion);
  94.            
  95.            for(i = 0; i < patrons.size(); ++i)
  96.         {
  97.             if(criterion == patrons.at(i).GetName())
  98.             {
  99.                 location = i;
  100.             }
  101.         }
  102.            }
  103.            break;
  104.            case 't':{
  105.            cout << "Please confirm the ID number:" << endl;
  106.            cin >> userNum;
  107.            for(i = 0; i < patrons.size(); ++i)
  108.         {
  109.             if(userNum == patrons.at(i).GetID())
  110.             {
  111.                 location = i;
  112.             }
  113.         }
  114.            }
  115.           break;
  116.          
  117.          
  118.        }
  119.        if(location == -1)
  120.        {
  121.            cout << "Invalid Entry. No book found.";
  122.        }
  123.        return location;
  124.     }
  125.     void PatronList::PrintPatrons(){
  126.         unsigned int index = FindPatron();
  127.         cout << "Name: " << patrons.at(index).GetName() << endl;
  128.         cout << "ID: " << patrons.at(index).GetID() << endl;
  129.         cout << "Balance: " << patrons.at(index).GetBalance() << endl;
  130.         cout << "Number of books out: " << patrons.at(index).GetNumBooks() << endl;
  131.     }
  132.     void PatronList::PrintAll(){
  133.         for(i = 0; i < patrons.size(); ++i){
  134.             cout << "Name: " << patrons.at(i).GetName() << endl;
  135.         cout << "ID: " << patrons.at(i).GetID() << endl;
  136.         cout << "Balance: " << patrons.at(i).GetBalance() << endl;
  137.         cout << "Number of books out: " << patrons.at(i).GetNumBooks() << endl << endl;
  138.            
  139.         }
  140.     }
Advertisement
Add Comment
Please, Sign In to add comment