Advertisement
edensheiko

C++ bank code using linked list version 0.2 alpha

Feb 18th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. // Node.h file , paste made by @edensheiko
  2. #pragma once
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9. class Node
  10. {
  11. private:
  12.     double _account;
  13.     int _id;
  14.     Node *next;
  15.     string _name;
  16.     static int idGenrator;
  17.  
  18. public:
  19.     friend void print(Node&n);
  20.     Node();
  21.     ~Node();
  22.     Node(string name,double account=0.0);
  23.     static int getidGenrator();
  24.     string Getname()const ;
  25.     double Getaccount()const;
  26.     void Setaccount(double);
  27. };
  28.  
  29. // node.cpp file
  30. #include "Node.h"
  31. #include <iostream>
  32. #include <string>
  33. using namespace std;
  34. int Node::idGenrator = 0;
  35.  
  36. Node::Node()
  37. {
  38. }
  39.  
  40.  
  41. Node::~Node()
  42. {
  43. }
  44.  
  45. Node::Node(string name, double account)
  46. {
  47.     this->_name = name;
  48.     this->_account = account;
  49.     this->_id = getidGenrator();
  50. }
  51.  
  52.  int Node::getidGenrator()
  53.  {
  54.      ++idGenrator;
  55.      // can be called insted of ++idGenrator
  56.      return idGenrator;
  57.  }
  58.  
  59.  string Node::Getname() const
  60.  {
  61.  
  62.      return this->_name;
  63.  
  64.  }
  65.  
  66.  double Node::Getaccount() const
  67.  {
  68.  
  69.      return this->_id;
  70.  
  71.  }
  72.  
  73.  void Node::Setaccount(double account) //if there is a deposit
  74.  {
  75.      this->_account += account > 0 ? account : 0;
  76.  
  77.  }
  78.  
  79.  void print(Node &n)
  80.  {
  81.      cout << "ID:" << n._id << endl;
  82.      cout << "Name:" << n._name << endl;
  83.      cout << "account balance:" << n._account << endl;
  84.  
  85.  }
  86.  
  87.  // main.cpp file
  88. #include <iostream>
  89. #include "Node.h"
  90.  
  91. using namespace std;
  92.  
  93. void main()
  94. {
  95.     //sNode::getidGenrator();
  96.  
  97.     Node v1("eden",2000);
  98.     Node v2("elon mask", 50000);
  99.    
  100.    
  101.     //cout << "first name:" << v1.Getname() << endl<< "secand name:" << v2.Getname() << endl;
  102.     //cout << "acc:" << v1.Getaccount() << endl << "acc:" << v2.Getaccount() << endl;
  103.     //print cheack
  104.     // Deposit//
  105.     v1.Setaccount(10);
  106.     print(v1);
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement