Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * user.cpp
- * PROJECTO #1
- *
- * Created by Miguel Oliveira & Rui Couto on 22/03/2011.
- *
- */
- #include "user.h"
- #include <string>
- #include <iostream>
- #include <vector>
- using namespace std;
- IdentNum User::numUsers = 0; //number of users begins with 0
- /*
- ########################################
- ## CONSTRUCTORS ##
- ########################################
- */
- User::User () //used to with the temp objects
- {
- setID (0);
- name = "UNKNOWN NAME USER";
- }
- User::User (string name, string pass) //when adding a user, receives a name and password
- {
- numUsers++; //the number of users, increases with each new user
- setID (numUsers); //the ID of the new user will be the same as the number of users, since number of users is always different
- setName (name); //set the name as the name received
- setPass (pass); //set the password as the string received as password
- setActive(true); //automatically set the status to true
- requestedBooks.clear(); //SAFETY MEASURE - making sure the vector is cleared
- }
- /*
- ########################################
- ## GET FUNCTIONS ##
- ########################################
- */
- IdentNum User::getID () const //returns id of the user;
- {
- return ID;
- }
- string User::getName () const //return the name of the user;
- {
- return name;
- }
- string User::getPass () const //returns the password of the user;
- {
- return pass;
- }
- bool User::isActive () const //returns the status of the user;
- {
- return active;
- }
- vector<IdentNum> User::getRequestedBooks () const //returns the vector with the user's requested books
- {
- return requestedBooks;
- }
- bool User::hasBooksRequested () const //returns true or false if the user has books requested or not
- {
- if ( requestedBooks.empty() )
- return false;
- else
- return true;
- }
- /*
- ########################################
- ## SET FUNCTIONS ##
- ########################################
- */
- void User::setID (IdentNum userID) //define user ID
- {
- ID = userID;
- }
- void User::setName (string userName) //define user name
- {
- name = userName;
- }
- void User::setPass (string userPass) //define user password
- {
- pass = userPass;
- }
- void User::setActive (bool status) //define user status
- {
- active = status;
- }
- void User::setRequestedBooks (const vector<IdentNum> &booksRequestedByUser) //define requested books based on the vector that contains that information
- {
- requestedBooks = booksRequestedByUser;
- if ( requestedBooks != booksRequestedByUser) //SECURITY MEASURE - making sure the vectors were equalized
- cerr << "Error defining requestedBooks";
- }
- void User::setNumUsers (IdentNum num) //define number of users
- {
- numUsers = num;
- }
- void User::borrowBook (IdentNum bookID) //method to borrow the books, receives book ID and adds it to the vector of requestedBooks
- {
- requestedBooks.push_back(bookID);
- }
- void User::returnBook (IdentNum bookID) //method to return the books, receives book ID
- {
- for (int i = 0; i < (int)requestedBooks.size(); i++) //searches book ID on the requested books vector, and, if found, deletes it
- {
- if (requestedBooks[i] == bookID)
- requestedBooks.erase(requestedBooks.begin()+i);
- }
- }
Add Comment
Please, Sign In to add comment