基于搜索二叉树的停车收费管理系统
创始人
2025-01-08 19:36:58
0

系统效果:
录入汽车信息

查看汽车信息

收费信息查看

查询车库车辆

 

代码展示:

//SearchBinaryTree.h #pragma once #include #include #include #include using namespace std;  template struct BSTNode { 	K _key; 	V _value; 	BSTNode* _left; 	BSTNode* _right; 	BSTNode(const K& key,const V& value) 		:_key(key) 		,_value(value) 		,_left(nullptr) 		,_right(nullptr) 	{} };  template class BSTree { 	typedef BSTNode Node; public:  	BSTree() 		:_root(nullptr) 	{}  	~BSTree() 	{ 		Destroy(_root); 		_root = nullptr; 	}  	bool Insert(const K& key, const V& value); 	bool Erase(const K& key);  	Node* Find(const K& key) 	{ 		{ 			Node* cur = _root; 			while (cur) 			{ 				if (cur->_key < key) 				{ 					cur = cur->_right; 				} 				else if (cur->_key > key) 				{ 					cur = cur->_left; 				} 				else 				{ 					return cur; 				} 			} 			return nullptr; 		} 	}  	void Destroy(Node* root) 	{ 		if (root == nullptr) 			return; 		Destroy(root->_left); 		Destroy(root->_right); 		delete root; 	}  	void InOeder() 	{ 		_InOeder(_root); 	}  private: 	void _InOeder(Node* root);  private: 	Node* _root; };  template inline bool BSTree::Insert(const K& key, const V& value) { 	if (_root == nullptr) 	{ 		_root = new Node(key, value); 		return true; 	} 	Node* parent = nullptr; 	Node* cur = _root; 	while (cur) 	{ 		if (cur->_key < key) 		{ 			parent = cur; 			cur = cur->_right; 		} 		else if (cur->_key > key) 		{ 			parent = cur; 			cur = cur->_left; 		} 		else 		{ 			return false; 		} 	} 	cur = new Node(key, value); 	if (parent->_key > cur->_key) 	{ 		parent->_left = cur; 	} 	else if (parent->_key < cur->_key) 	{ 		parent->_right = cur; 	} 	return true; }   template inline bool BSTree::Erase(const K& key) { 		Node* cur = _root; 	Node* parent = nullptr; 	while (cur) 	{ 		if (cur->_key < key) 		{ 			parent = cur; 			cur = cur->_right; 		} 		else if (cur->_key > key) 		{ 			parent = cur; 			cur = cur->_left; 		} 		else 		{ 			if (cur->_left = nullptr) 			{ 				if (parent == nullptr) 				{ 					_root = cur->_right; 				} 				else 				{ 					if (parent->_left == cur) 					{ 						parent->_left = cur->_right; 					} 					else 					{ 						parent->_right = cur->_right; 					} 				} 				delete cur; 				return true; 			} 			else if (cur->_right == nullptr) 			{ 				if (parent == nullptr) 				{ 					_root = cur->_left; 				} 				else 				{ 					if (parent->_left == cur) 					{ 						parent->_left = cur->_left; 					} 					else 					{ 						parent->_right = cur->_left; 					} 				} 				delete cur; 				return true; 			} 			else 			{ 				Node* rightMin = cur->_right; 				Node* rightMinParent = cur; 				while (rightMin->_left) 				{ 					rightMinParent = rightMin; 					rightMin = rightMin->_left; 				} 				cur->_key = rightMin->_key; 				if(rightMinParent->_left == rightMin) 					rightMinParent->_left = rightMin->_right; 				else 					rightMinParent->_right = rightMin->_right; 				delete rightMin; 				return true; 			} 		} 	} 	return false; }  template inline void BSTree::_InOeder(Node* root) { 		if (root == nullptr) 		return; 		_InOeder(root->_left); 		cout << "汽车车牌号:" << root->_key << " "; 		struct tm info; 		localtime_s(&info, &root->_value); 		char buffer2[80]; 		strftime(buffer2, 80, "%Y-%m-%d %H:%M:%S", &info); 		cout << "入库的时间:" << buffer2 << endl; 		_InOeder(root->_right); } 

//Parking_Fee.h #pragma once #include"SearchBinaryTree.h"  class ParFee { public: 	void menu(); 	void entering(); 	void Find(); 	void Erase(); 	void statistics(); 	BSTree par; };

//Parking_Fee.cpp #include"SearchBinaryTree.h" #include"Parking_Fee.h"  void ParFee::entering() {     time_t seconds = time(NULL);     time_t curLocalTime;     time(&curLocalTime);     struct tm info;     localtime_s(&info, &curLocalTime);     char buffer2[80];     strftime(buffer2, 80, "%Y-%m-%d %H:%M:%S", &info); 	cout << "请输入识别的汽车车牌号>:" << endl; 	string ID; cin >> ID; 	cout << "====>" << endl; 	Sleep(1000); 	cout << "=========>" << endl; 	Sleep(1000); 	cout << "=================>" << endl; 	Sleep(1000); 	cout << "录入成功" << endl; 	system("pause"); 	system("cls"); 	cout << "*-----------------------*" << endl; 	cout << "<<><>汽车车牌号:" << ID << endl; 	cout << "<<><>入库的时间:" << buffer2 << endl; 	cout << "*-----------------------*" << endl; 	par.Insert(ID, seconds);     system("pause"); }  void ParFee::Find() {     cout << "<*请输入你要查询的车辆*>" << endl;     string ID; cin >> ID;     auto ret = par.Find(ID);     if (ret)      {         cout << "<<><>汽车车牌号:" << ID << endl;         struct tm info;         localtime_s(&info, &ret->_value);         char buffer2[80];         strftime(buffer2, 80, "%Y-%m-%d %H:%M:%S", &info);         cout << "<<><>入库的时间:" << buffer2 << endl;      }     else      {         cout << "无此汽车,请重新输入" << endl;      }     system("pause"); }  void ParFee::Erase() {     cout << "<*请输入将要离开的车辆*>" << endl;     string ID; cin >> ID;     auto ret = par.Find(ID);     time_t  leave_seconds = time(NULL);     time_t curLocalTime;     time(&curLocalTime);     struct tm info;     localtime_s(&info, &curLocalTime);     char buffer3[80];     strftime(buffer3, 80, "%Y-%m-%d %H:%M:%S", &info);     if (ret)     {         cout << "<<><>汽车车牌号:" << ID << endl;         struct tm info;         localtime_s(&info, &ret->_value);         char buffer2[80];         strftime(buffer2, 80, "%Y-%m-%d %H:%M:%S", &info);         cout << "<<><>入库的时间:" << buffer2 << endl;         cout << "<<><>离开的时间:" << buffer3 << endl;         long long int course_timt = difftime(leave_seconds, ret->_value);         int a, b, c;         a = course_timt % 60;         b = course_timt / 60 % 60;         c = course_timt / 60 / 60;         cout << ID << "车辆 停车花费时间为:" << c << " h " << b << " min " << a << " sec " << endl;         cout << "需要收取费用:" << 20 * c << " 元" << endl;     }     else     {         cout << "无此汽车,请重新输入" << endl;     }     par.Erase(ID);     system("pause"); }  void ParFee::statistics() {     par.InOeder();     system("pause"); }    void ParFee::menu() {     while (true)     {         printf("\t\t\t*****************************************************\n");         printf("\t\t\t*---------------------------------------------------*\n");         printf("\t\t\t*                   停车场收费管理系统              *\n");         printf("\t\t\t*****************************************************\n");         printf("\t\t\t********************系统功能菜单*********************\n");         printf("\t\t\t----------------------     --------------------------\n");         printf("\t\t\t*****************************************************\n");         printf("\t\t\t**    1、录入汽车信息   *     2、查看汽车信息      **\n");         printf("\t\t\t*****************************************************\n");         printf("\t\t\t**    3、收费信息查看   *     4、查询车库车辆      **\n");         printf("\t\t\t*****************************************************\n");         printf("\t\t\t----------------------     --------------------------\n");         int input;         cin >> input;         system("cls");         switch (input)         {         case 1:         {             entering();             system("cls");             break;         };         case 2:         {             Find();             system("cls");             break;         };         case 3:         {             Erase();             system("cls");             break;         };         case 4:         {             statistics();             system("cls");             break;         };         }     } } 

//main.cpp #include"SearchBinaryTree.h" #include"Parking_Fee.h"      int main()     {         system("color F4");         ParFee par;         par.menu();         return 0;     }

相关内容

热门资讯

第1分钟了解!游戏浙江大厅脚本... 第1分钟了解!游戏浙江大厅脚本修改,科乐辅助工作室,指南教程(有挂规律)-哔哩哔哩该软件可以轻松地帮...
七分钟了解!微乐四川辅助,微乐... 七分钟了解!微乐四川辅助,微乐小程序免费黑科技下载,步骤教程(确实有挂)-哔哩哔哩1)微乐小程序免费...
第5分钟了解!土豪辅助,新道游... 第5分钟了解!土豪辅助,新道游辅助软件下载,策略教程(有挂分析)-哔哩哔哩1、全新机制【新道游辅助软...
第四分钟了解!中至鹰潭亲友圈辅... 第四分钟了解!中至鹰潭亲友圈辅助,兴动海满麻浆辅助,经验教程(有挂攻略)-哔哩哔哩1、玩家可以在中至...
7分钟了解!闲逸辅助器,广西老... 7分钟了解!闲逸辅助器,广西老友修改器,法子教程(有挂教程)-哔哩哔哩1、广西老友修改器脚本辅助下载...
第3分钟了解!红黑大战控制系统... 第3分钟了解!红黑大战控制系统,拱趴大菠萝玩的是运气吗,练习教程(果真有挂)-哔哩哔哩1、游戏颠覆性...
第九分钟了解!家乡大二辅助免费... 第九分钟了解!家乡大二辅助免费,奇迹陕西游戏辅助挂,妙招教程(有挂助手)-哔哩哔哩奇迹陕西游戏辅助挂...
8分钟了解!海南琼崖海南辅助功... 8分钟了解!海南琼崖海南辅助功能,传送屋辅助,模板教程(有挂详情)-哔哩哔哩1、海南琼崖海南辅助功能...
第5分钟了解!天天开心王国辅助... 第5分钟了解!天天开心王国辅助器,手机填大坑辅助器,策略教程(真实有挂)-哔哩哔哩天天开心王国辅助器...
五分钟了解!德普之星透视挂,川... 五分钟了解!德普之星透视挂,川南九九辅助,攻略教程(有挂细节)-哔哩哔哩1、每一步都需要思考,不同水...