Guest User

Untitled

a guest
Nov 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. //player.h
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Player
  8. {
  9.     int health, level;
  10.     string name;
  11. public:
  12.     Player(string n, int l, int h)
  13.     {
  14.         name = n;
  15.         level = l;
  16.         health = h;
  17.     }
  18.     void playerDisplay()
  19.     {
  20.         cout << "Name: " << name << "\nLevel: " << level << "\nHealth: " << health << "\n\n";
  21.     }
  22.  
  23. };
  24.  
  25. //intSLLst.h
  26. #include <iostream>
  27. #include "player.h"
  28.  
  29. using namespace std;
  30.  
  31. class SLL
  32. {
  33.     struct Node
  34.     {
  35.         Node *next;
  36.         Player* data;
  37.         Node(Player* data)
  38.         {
  39.             next = NULL;
  40.             this->data = data;
  41.         }
  42.     };
  43.  
  44.     Node *head;
  45.     Node *tail;
  46. public:
  47.     SLL()
  48.     {
  49.         head = NULL;
  50.         tail = NULL;
  51.     }
  52.  
  53.     void add(Player* data)
  54.     {
  55.         Node *newNode = new Node(data);
  56.         if (head == NULL)
  57.         {
  58.             tail = head = newNode;
  59.         }
  60.         else
  61.         {
  62.             tail->next = newNode;
  63.             tail = newNode;
  64.         }
  65.     }
  66.  
  67.     void display()
  68.     {
  69.         Node *temp = head;
  70.         while(temp)
  71.         {
  72.              temp->data->playerDisplay();
  73.             temp = temp->next;
  74.         }
  75.     }
  76. };
  77.  
  78. //intSLLst.cpp
  79. #include <iostream>
  80. #include <string>
  81. #include "intSLLst.h"
  82.  
  83. using namespace std;
  84.  
  85. int main(int argc, char* argv[])
  86. {
  87.     SLL list;
  88.     Player* miyako = new Player("Miyako", 1, 195);
  89.     Player* sakura = new Player("Sakura", 2, 220);
  90.     Player* kaori = new Player("Kaori", 4, 175);
  91.  
  92.     list.add(miyako);
  93.     list.add(sakura);
  94.     list.add(kaori);
  95.  
  96.     list.display();
  97.  
  98.     cin.get();
  99.     return 0;
  100. }
Add Comment
Please, Sign In to add comment