Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Login
- -------------
- #include <iostream>
- #include "linkedlist.h"
- #include "Employee.h"
- using namespace std;
- class Login{
- LinkedList<Employee> list;
- Login(){
- //Employee e1 ("manager","manager",true),e2 ("staff","staff",false);
- Employee *e1 = new Employee("manager","manager",true);
- Employee *e2 = new Employee("staff","staff",false);
- list.add(*e1);
- list.add(*e2);
- }
- ~Login(){
- }
- };
- ---------
- #include <iostream>
- using namespace std;
- class Employee{
- int ID;
- static int nextID;
- string username;
- string password;
- bool manager;
- public:
- Employee(string username,string password,bool manager){
- this->ID = nextID;
- nextID++;
- this->username = username;
- this->password = password;
- this->manager = manager;
- }
- void Employee::grantManager(){
- this->manager = true;
- }
- void Employee::revokeManager(){
- this->manager = false;
- }
- };
- int Employee::nextID=0;
- -----------
- //LinkedList.h - defines a linked list
- #include <iostream>
- using namespace std;
- template<class T>
- struct node
- {
- T item;
- node<T> *next;
- node<T> *prev;
- };
- template <class T>
- class LinkedList
- {
- public:
- void add(const T& item);
- LinkedList();
- ~LinkedList();
- int getLength();
- void reset();
- T iterate();
- T search(int ID);
- void remove(int ID);
- protected:
- node<T> *first;
- node<T> *last;
- int length;
- T i;
- };
- template <class T>
- LinkedList<T>::LinkedList(){
- first = NULL;
- last = NULL;
- length = 0;
- }
- template <class T>
- LinkedList<T>::~LinkedList(){
- node<T> *remove;
- while(first!=NULL){
- remove = first;
- first = first->next;
- delete remove;
- }
- delete last;
- length = 0;
- }
- template <class T>
- void LinkedList<T>::add(const T& item){
- node<T> *nNode;
- nNode->item=item;
- if (*first == NULL) *first = *nNode;
- else {
- *last->next = *nNode;
- *nNode->prev = *last;
- *last = nNode;
- }
- }
- template <class T>
- int LinkedList<T>::getLength(){
- return length;
- }
- template <class T>
- T LinkedList<T>::iterate(){
- if(i ==NULL){
- i = first;
- return i->item;
- }else{
- return i->next->item;
- i = i->next;
- }
- }
- template <class T>
- void LinkedList<T>::reset(){
- i = NULL;
- }
- template <class T>
- T LinkedList<T>::search(int ID){
- node i = NULL;
- while(i->item->ID !=ID){
- i = list.iterate();
- }
- return i->item;
- }
- template <class T>
- void LinkedList<T>::remove(int ID){
- node i = first;
- node temp = NULL;
- if(first->item->ID == ID){
- temp = first;
- first = temp->next;
- delete temp;
- }else{
- while(i->next->item->ID !=ID){
- i = i->next;
- }
- temp = i->next;
- delete i->next;
- i->next = temp->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement