Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //player.h
- #include <iostream>
- #include <string>
- using namespace std;
- class Player
- {
- int health, level;
- string name;
- public:
- Player(string n, int l, int h)
- {
- name = n;
- level = l;
- health = h;
- }
- void playerDisplay()
- {
- cout << "Name: " << name << "\nLevel: " << level << "\nHealth: " << health << "\n\n";
- }
- };
- //intSLLst.h
- #include <iostream>
- #include "player.h"
- using namespace std;
- class SLL
- {
- struct Node
- {
- Node *next;
- Player* data;
- Node(Player* data)
- {
- next = NULL;
- this->data = data;
- }
- };
- Node *head;
- Node *tail;
- public:
- SLL()
- {
- head = NULL;
- tail = NULL;
- }
- void add(Player* data)
- {
- Node *newNode = new Node(data);
- if (head == NULL)
- {
- tail = head = newNode;
- }
- else
- {
- tail->next = newNode;
- tail = newNode;
- }
- }
- void display()
- {
- Node *temp = head;
- while(temp)
- {
- temp->data->playerDisplay();
- temp = temp->next;
- }
- }
- };
- //intSLLst.cpp
- #include <iostream>
- #include <string>
- #include "intSLLst.h"
- using namespace std;
- int main(int argc, char* argv[])
- {
- SLL list;
- Player* miyako = new Player("Miyako", 1, 195);
- Player* sakura = new Player("Sakura", 2, 220);
- Player* kaori = new Player("Kaori", 4, 175);
- list.add(miyako);
- list.add(sakura);
- list.add(kaori);
- list.display();
- cin.get();
- return 0;
- }
Add Comment
Please, Sign In to add comment