Guest User

ex4 unfinished

a guest
Nov 19th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.64 KB | None | 0 0
  1. /* -------------------------- myNode.h  ---------------------------*/
  2. #ifndef myNode_h
  3. #define myNode_h
  4. #include <iostream>
  5.  
  6. class Node {
  7.  
  8. private:
  9.     char *clientName;
  10.     double clientState;
  11.    
  12. public:
  13.     Node *next;
  14.     Node();
  15.     Node(char *, int);
  16.     void setName(const char *);
  17.     void setState(const double);
  18.     char* getName() const;
  19.     double getState() const;
  20.     ~Node();
  21.  
  22. };
  23.  
  24. #endif
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. /* -------------------------- myQueue.h  ---------------------------*/
  32. #include <iostream>
  33. using namespace std;
  34.  
  35. #ifndef myQueue_h
  36. #define myQueue_h
  37.  
  38. class Queue {
  39.  
  40. friend void printQ();
  41.  
  42. private :
  43.  
  44.     Node* head;
  45.     Node* tail;
  46.  
  47. public:
  48.  
  49.     Queue();
  50.     void insertNode(Node);
  51.     Node *getLast();
  52.     Node *peek();
  53.     bool isEmpty();
  54.    
  55.  
  56. };
  57.  
  58. void printQ(Queue &Q)
  59. {
  60.     Node *location= Q.head;
  61.  
  62.     if (!location) { cout <<"There are no clients!"<<endl; }
  63.     while (location)
  64.     {
  65.     //  cout << "Client Name: "<< location->clientName ;
  66.     //  cout << " Client State: "<<location->clientState << endl ;
  67.     //  location=location->next;
  68.     }
  69. }
  70.  
  71.  
  72. #endif
  73.  
  74.  
  75.  
  76.  
  77. /* -------------------------- myNode.cpp  ---------------------------*/
  78. #include <iostream>
  79. #include "myNode.h"
  80. #include <cstring>
  81.  
  82. using namespace std;
  83.  
  84. Node :: Node()
  85. {
  86.     this->clientName = NULL;
  87.     this->clientState=0;
  88.     this->next=NULL;
  89. }
  90.  
  91. Node::Node(char *name, int state)
  92. {
  93.     this->clientName = new char[strlen(name)+1];
  94.     strcpy(clientName,name);
  95.     this->clientState = state;
  96. }
  97.  
  98.  
  99. void  Node::setName (const char *name)
  100. {
  101.     strcpy(clientName,name);
  102. }
  103.  
  104.  
  105. void  Node ::setState(const double state)
  106. {
  107.     this->clientState = state;
  108. }
  109.  
  110.  
  111.  
  112. char* Node :: getName() const
  113. {
  114.     return (this->clientName);
  115. }
  116.  
  117. double Node :: getState() const
  118. {
  119.     return (this->clientState);
  120. }
  121.  
  122. Node :: ~Node()
  123. {
  124.     delete []clientName;
  125. }
  126.  
  127.  
  128.  
  129.  
  130.  
  131. /* -------------------------- myQueue.cpp  ---------------------------*/
  132.  
  133. #include <iostream>
  134. using namespace std;
  135. #include "myNode.h"
  136. #include "myQueue.h"
  137.  
  138. Queue :: Queue()
  139. {
  140.     this->head=NULL;
  141.     this->tail=NULL;
  142. }
  143.  
  144.  
  145. void Queue :: insertNode(Node n1)
  146. {
  147.     if (this->head == NULL)
  148.         this->tail = this->head = &n1;
  149.     else
  150.         this->tail->next=&n1;
  151. }
  152.  
  153.  
  154. Node * Queue :: getLast()
  155. {
  156.     Node *myHead=this->head;
  157.     this->head = this->head->next;
  158.     return myHead;
  159. }
  160.  
  161.  
  162. Node * Queue :: peek()
  163. {
  164.     return this->head;
  165. }
  166.  
  167.  
  168. bool Queue ::  isEmpty()
  169. {
  170.     if (this->head == NULL)
  171.         return true;
  172.     return false;
  173. }
  174.  
  175.  
  176.  
  177.  
  178.  
  179. /* ------------------------------------------ main.cpp --------------------------------------------------*/
  180. #include <iostream>
  181. #include "myNode.h"
  182. #include "myQueue.h"
  183.  
  184. using namespace std;
  185.  
  186.  
  187.  
  188.  
  189. void main ()
  190. {
  191. }
Advertisement
Add Comment
Please, Sign In to add comment