Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // node.h
- #pragma once
- #include <string>
- using namespace std;
- class Node
- {
- private:
- double _account;
- int _id;
- Node *next;
- string _name;
- static int idGenrator;
- public:
- friend void print(Node&n);
- Node();
- ~Node();
- Node(string name,double account=0.0);
- static int getidGenrator();
- string Getname()const ;
- double Getaccount()const;
- void Setaccount(double);
- void Setnext( Node &n); // const can be used because we wont change the vlaues
- Node *Getnext() const;
- };
- //Queue.h
- #pragma once
- #include "Node.h"
- class Queue
- {
- private:
- Node *start;
- Node *end;
- public:
- Queue();
- ~Queue();
- void Addnode(Node &n);
- Node & Getnode();
- };
- // node.cpp
- #include "Node.h"
- #include <iostream>
- #include <string>
- using namespace std;
- int Node::idGenrator = 0;
- Node::Node()
- {
- }
- Node::~Node()
- {
- }
- Node::Node(string name, double account)
- {
- this->_name = name;
- this->_account = account;
- this->_id = getidGenrator();
- this->next = NULL;
- }
- int Node::getidGenrator()
- {
- ++idGenrator;
- // can be called insted of ++idGenrator
- return idGenrator;
- }
- string Node::Getname() const
- {
- return this->_name;
- }
- double Node::Getaccount() const
- {
- return this->_id;
- }
- void Node::Setaccount(double account) //if there is a deposit
- {
- this->_account += account > 0 ? account : 0;
- }
- void Node::Setnext( Node &n)
- {
- this->next = &n; //get ptr of n
- }
- Node* Node::Getnext() const
- {
- return this->next;
- }
- void print(Node &n)
- {
- cout << "ID:" << n._id << endl;
- cout << "Name:" << n._name << endl;
- cout << "account balance:" << n._account << endl;
- }
- // q.h
- #include "Queue.h"
- Queue::Queue()
- {
- start = end = NULL;
- }
- Queue::~Queue()
- {
- }
- void Queue::Addnode(Node &n)
- {
- if (start==NULL)
- {
- start = end = &n;
- }
- else
- {
- end->Setnext(n);
- end = &n;
- }
- }
- Node & Queue::Getnode()
- {
- Node *pn = start;
- if (start==end)
- {
- start = end = NULL;
- }
- else
- {
- start = start->Getnext();
- }
- return *pn;
- }
- //main.cpp
- #include <iostream>
- #include "Node.h"
- #include "Queue.h"
- using namespace std;
- void main()
- {
- //sNode::getidGenrator();
- Node v1("eden",2000);
- Node v2("elon mask", 50000);
- Node v3("joe", 40000);
- // Deposit//
- v1.Setaccount(1000);
- cout << "-----------------------------------"<< endl;
- print(v1);
- cout << "-----------------------------------" << endl;
- print(v2);
- cout << "-----------------------------------" << endl;
- Queue q1;
- q1.Addnode(v1);
- q1.Addnode(v2);
- q1.Addnode(v3);
- Node n10 = q1.Getnode();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement