大一下學期項目設計—綜合儲蓄平臺—Node類

簡述實驗:創建節點

頭文件:

#ifndef HEADER_NODE//預處理命令,防止文件被多次引用。
#define HEADER_NODE//預處理命令,防止文件被多次引用。
#include"Record.h"//將文件Bank包含

class Node
{
private:

	Record * record;//新建記錄
	Node * next;//指向下一節點的指針

public:

	Node ();
	~Node();

	void set_record(Record * record);
	void set_next(Node * next);
	Record * get_record();
	Node * get_next();

	void display_Node();//顯示節點信息
};
#endif


源文件:

#include"Node.h"//包含頭文件
#include<iostream>
using namespace std;

Node::Node()
{
	this->record = NULL;
	this->next = NULL;
}

Node::~Node ()
{
	delete this->record;//先將Record撤銷掉
	this->record = NULL;//再將其賦空
	this->next = NULL;
}

void Node::set_record(Record * record) 
{
	this->record = record;
}

void Node::set_next(Node * next)
{
	this->next = next;
}

Record * Node::get_record()
{
	return this->record;
}

Node * Node::get_next()
{
	return this->next;
}

void Node::display_Node()
{
	cout << "print Node elements..." << endl;
	
	if(this->record != NULL)
	{
		Record * r = this->record;
		r->display_Record();
	}
	else
	{
		cout << "Record is NULL..."<< endl;
	}

	cout << "Next:" << this->next << endl;
	cout << "End of Node..." << endl;
}

 

測試文件:

#include"Node.h"
#include<iostream>
using namespace std;

int main()
{
	Node * node = new Node();
	node->display_Node();
	cout << endl;

	Record * record = new Record();
	record->set_number(10001);
	record->set_userName("lihongxuan");
	record->set_passWord("123456");
	record->set_balance(10000);
	record->set_flag(1);

	node->set_record(record);
	node->display_Node();

	return 0;
}

輸出結果:

經驗總結:

由Record構成一個Node

 

發佈了122 篇原創文章 · 獲贊 80 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章