C++商品及用户管理系统(链表、类、用户验证、代码详解、课程设计)

基本功能:商品信息管理

  • 创建商品价格信息文件
    提示具有管理员权限的用户输入保存商品价格信息记录的文件 名,在磁盘上创建该文件。用户根据提示输入商品的序号、名称、各项价格要素,如价 格、折扣和会员价。可一次性输入多条商品的价格信息记录。系统将商品价格信息记录 存储在系统磁盘的文件中,以便进行管理、查找和备份。

  • 增加商品价格信息
    在原有商品价格信息文件的基础上增加新的商品价格信息记录,并继续保存至磁盘。

  • 删除商品价格信息
    提示输入要进行删除操作的商品序号,如果在文件中有该商品的价 格信息存在,则将该序号所对应的名称、序号、各种价格要素等在对应文件中加以删除, 并提示顾客选择是否继续进行删除操作。

  • 修改商品价格信息
    提示用户输入要进行修改操作的商品序号,如果在文件中有该商品 的价格信息存在,则提示顾客输入要修改的选项,并将结果存储于文件。提示用户是否 需要继续修改。

  • 查询商品价格
    分为根据商品名称和商品序号两种查询方式,分别提示客户输入要查询 商品信息的序号或名称,如果在磁盘文件中有对应得商品价格信息,则提示用户已找到, 小型商品管理系统 1. 用户登录 2. 商品信息管理 3. 权限管理 程序的主界面 程序设计语言课程设计指导书 4 并逐项列出对应商品的价格状况。在该功能中,也需提示用户是否需要继续查找,如不 再继续查询,则返回主界面。

  • 商品价格排行浏览
    根据商品的折扣价格进行排行,以便用户对商品价格状况有较为直 观方便的了解。

  • 管理员对用户的管理
    管理员对用户进行创建、增加、删除、修改和浏览。管理员创建 的用户登录信息存储在磁盘文件中,每当有用户登录系统时,系统根据该文件中的用户 名和密码进行核实判断。

  • 用户验证
    用户在使用系统治前要进行登录验证。提示输入用户名和密码。并根据其权限提供不同操作界面。如未能通过验证则提示用户重新登录,超过三次则强制退出系统。 客户登录到系统后允许使用的系统功能和用户权限有关,普通用户只能进行查询和浏 览,具有管理员权限的用户则可进行对商品信息的增、删、改和用户登录信息的管理。

环境

编译器:Visual Studio 2019
目录结构:
在这里插入图片描述

使用方法

在这里插入图片描述
在这里插入图片描述

请在项目文件根目录中(存储代码的文件夹)创建UserData.txt以及CommodityListData.txt如需更改请到tool.h中更改读写文件代码。

代码实现

  • 用户相关代码(userData.h)
#pragma once
#include <iostream>
#include "interface.h"
using namespace std;

//用户
class User
{
public:
	User* Next;		//链表所需量
	User()			//无参构造
	{
		No = 0;
		Name = "0";
		Account = 0;
		PassWord = "0";
		Vip = false;
	}
	User(int no, string name, int account, string password,bool vip)		//有参构造
	{
		No = no;
		Account = account;
		PassWord = password;
		Name = name;
		Vip = vip;
	}

	int getNo() { return No; }						//获取私有变量函数
	string getName() { return Name; }
	int getAccount() { return Account; }
	string getPassWord() { return PassWord; }
	bool getVip() { return Vip; }

	void setNo(int no) { No = no; }					//设置私有变量函数
	void setName(string name) { Name = name; }
	void setAccount(int account) { Account = account; }
	void setPassWord(string password) { PassWord = password; }
	void setVip(bool vip) { Vip = vip; }

private:
	int No;
	string Name;
	int Account;
	string PassWord;
	bool Vip;

};
//用户库
class UserList
{
public:
	int index = 0;			//库帧

	UserList()
	{
		HeadUser = (User*)malloc(sizeof(User));		//为指针开辟空间避免越界操作
		TailUser = (User*)malloc(sizeof(User));
	}

	User* getHeadUser() { return HeadUser; }		//获得私有变量函数
	User* getTailUser() { return TailUser; }

	bool UListAdd(User* com)
	{
		bool exist = false;		//判断录入用戶是否存在

		if (index == 0)			//判断是否为第一个用戶
		{
			HeadUser = com;		//将第一个用戶作为链表头
			TailUser = com;
			index++;
			UListAddSuccess();
			Sleep(2 * 1000);

			return true;
		}
		else
		{
			User* p;			//防止链表头数据变动,创建p进行历遍
			p = HeadUser;

			while (p != NULL)
			{
				if (p->getNo() == com->getNo() || !(p->getName().compare(com->getName())))		//判断用戶的编号和姓名是否重复
				{
					exist = true;
					break;
				}
				p = p->Next;		//令链表移动
			}

			if (exist)
			{
				UListAddError();
				Sleep(2 * 1000);
				return false;
			}
			else
			{
				TailUser->Next = com;			//链表尾的移动和变化
				TailUser = com;
				index++;		//存入库+1
				UListAddSuccess();
				Sleep(2 * 1000);
				return true;
			}
		}
	}

	//用于数据的读取
	bool RListAdd(User* com)
	{
		bool exist = false;		//判断录入用戶是否存在

		if (index == 0)			//判断是否为第一个用戶
		{
			HeadUser = com;		//将第一个用戶作为链表头
			TailUser = com;
			index++;
			return true;
		}
		else
		{
			User* p;			//防止链表头数据变动,创建p进行历遍
			p = HeadUser;

			while (p != NULL)
			{
				if (p->getNo() == com->getNo() || !(p->getName().compare(com->getName())))		//判断用戶的编号和姓名是否重复
				{
					exist = true;
					break;
				}
				p = p->Next;		//令链表移动
			}

			if (exist)
			{
				return false;
			}
			else
			{
				TailUser->Next = com;			//链表尾的移动和变化
				TailUser = com;
				index++;		//存入库+1
				return true;
			}
		}
	}

	void UListDel(int num)
	{
		User* p;		//防止链表头数据变动,创建p进行历遍
		p = HeadUser;
		bool DelSuccess = false;

		if (p->getNo() == num)		//判断删除的元素是否为链表头
		{
			HeadUser = HeadUser->Next;		//将链表头进行移动
			DelSuccess = true;
		}
		else
		{
			while (p != NULL && p->Next != NULL)		//防止越界
			{
				if (p->Next->getNo() == num)		//判断中间元素是否为要删除节点
				{
					p->Next = p->Next->Next;		//将中间元素越过使第一与第三元素连接
					DelSuccess = true;
				}
				p = p->Next;		//链表移动
			}
		}

		if (DelSuccess)		//判断是否删除成功
		{
			UListDelSuccess();
			Sleep(2 * 1000);
		}
		else {
			UListDelError();
			Sleep(2 * 1000);
		}
	}

	//用户编号改变
	void UListChangeO(int num, int no)
	{
		User* p;
		p = HeadUser;
		bool ThLegal = true;
		bool ChSucess = false;

		while (p != NULL)
		{
			if (p->getNo() == no)
			{
				UChangeErrorS();
				Sleep(2 * 1000);
				ThLegal = false;
				break;
			}
			p = p->Next;
		}

		if (ThLegal)
		{
			p = HeadUser;
			while (p != NULL)
			{
				if (p->getNo() == num)
				{
					p->setNo(no);
					ChSucess = true;
					break;
				}
				p = p->Next;
			}
			if (ChSucess)
			{
				UChangeSuccess();
				Sleep(2 * 1000);
			}
			else
			{
				UChangeErrorN();
				Sleep(2 * 1000);
			}
		}
	}

	//用户姓名改变
	void UListChangeN(int num, string name)
	{
		User* p;
		p = HeadUser;
		bool ThLegal = true;
		bool ChSucess = false;

		while (p != NULL)
		{
			if (p->getName() == name)
			{
				UChangeErrorS();
				Sleep(2 * 1000);
				ThLegal = false;
				break;
			}
			p = p->Next;
		}

		if (ThLegal)
		{
			p = HeadUser;
			while (p != NULL)
			{
				if (p->getNo() == num)
				{
					p->setName(name);
					ChSucess = true;
					break;
				}
				p = p->Next;
			}
			if (ChSucess)
			{
				UChangeSuccess();
				Sleep(2 * 1000);
			}
			else
			{
				UChangeErrorN();
				Sleep(2 * 1000);
			}
		}
	}

	//用户账户改变
	void UListChangeA(int num, int account)
	{
		User* p;
		p = HeadUser;
		bool ThLegal = true;
		bool ChSucess = false;

		while (p != NULL)
		{
			if (p->getAccount() == account)
			{
				UChangeErrorS();
				Sleep(2 * 1000);
				ThLegal = false;
				break;
			}
			p = p->Next;
		}

		if (ThLegal)
		{
			p = HeadUser;
			while (p != NULL)
			{
				if (p->getNo() == num)
				{
					p->setAccount(account);
					ChSucess = true;
					break;
				}
				p = p->Next;
			}
			if (ChSucess)
			{
				UChangeSuccess();
				Sleep(2 * 1000);
			}
			else
			{
				UChangeErrorN();
				Sleep(2 * 1000);
			}
		}
	}

	//用户密码改变
	void UListChangeP(int num, string password)
	{
		User* p;
		p = HeadUser;
		bool ThLegal = true;
		bool ChSucess = false;

		while (p != NULL)
		{
			if (p->getPassWord() == password)
			{
				UChangeErrorS();
				Sleep(2 * 1000);
				ThLegal = false;
				break;
			}
			p = p->Next;
		}

		if (ThLegal)
		{
			p = HeadUser;
			while (p != NULL)
			{
				if (p->getNo() == num)
				{
					p->setPassWord(password);
					ChSucess = true;
					break;
				}
				p = p->Next;
			}
			if (ChSucess)
			{
				UChangeSuccess();
				Sleep(2 * 1000);
			}
			else
			{
				UChangeErrorN();
				Sleep(2 * 1000);
			}
		}
	}

	//根据编号查找
	void UListSeek(int num)
	{
		User* p;
		p = HeadUser;
		bool SeekSuccess = false;

		while (p != NULL)
		{
			if (p->getNo() == num)
			{
				SeekSuccess = true;
				break;
			}
			p = p->Next;		//链表移动
		}

		if (SeekSuccess)
		{
			USeekSuccess();
			cout << "编号" << p->getNo() << " 名称" << p->getName() << " 账号" << p->getAccount() << " 密码" << p->getPassWord() << endl;
			system("pause");
		}
		else
		{
			USeekError();
			Sleep(2 * 1000);
		}
	}

	//删除中使用的查找
	bool DUListSeek(int num)
	{
		User* p;
		p = HeadUser;
		bool SeekSuccess = false;

		while (p != NULL)
		{
			if (p->getNo() == num)
			{
				SeekSuccess = true;
				break;
			}
			p = p->Next;		//链表移动
		}

		if (SeekSuccess)
		{
			cout << "编号" << p->getNo() << " 名称" << p->getName() << " 账号" << p->getAccount() << " 密码" << p->getPassWord() << endl;
			return true;
		}
		else
		{
			USeekError();
			Sleep(2 * 1000);
			return false;
		}
	}

	//根据名称查找
	void UListSeek(string name)
	{
		User* p;
		p = HeadUser;
		bool SeekSuccess = false;

		while (p != NULL)
		{
			if (p->getName() == name)
			{
				SeekSuccess = true;
				break;
			}
			p = p->Next;		//链表移动
		}
		if (SeekSuccess)
		{
			USeekSuccess();
			cout << "编号" << p->getNo() << " 名称" << p->getName() << " 账号" << p->getAccount() << " 密码" << p->getPassWord() << endl;
			system("pause");
		}
		else
		{
			USeekError();
			Sleep(2 * 1000);
		}
	}

	void UListShow()
	{
		User* p;			//防止链表头变化,创建p历遍
		p = HeadUser;

		while (p != NULL)
		{
			cout << "编号" << p->getNo() << " 姓名" << p->getName() << " 账户" << p->getAccount() << " 密码" << p->getPassWord() << " VIP" << p->getVip() << endl;
			p = p->Next;		//链表移动
		}
	}

	//用户密码检验
	bool CheckAccount(int account,string password) 
	{
		User* p;			//防止链表头变化,创建p历遍
		p = HeadUser;

		while (p != NULL)
		{
			if (p->getAccount() == account && p->getPassWord() == password)
			{
				return false;
			}
			p = p->Next;
		}

		LoginFail();
		Sleep(2 * 1000);
		return true;
	}

private:
	User* HeadUser = NULL;	//链表头
	User* TailUser = NULL;	//链表尾
};
  • 商品相关代码(commodityData.h)
#pragma once
#include <iostream>
#include "interface.h"
using namespace std;

//商品
class Commodity
{
public:
	Commodity* Next;		//链表所需量
	Commodity()				//无参构造
	{
		No = 0;
		Name = "0";
		Price = 0;
		Discount = 0;
	}
	Commodity(int no, string name, double price, double discount)		//有参构造
	{
		No = no;
		Price = price;
		Discount = discount;
		Name = name;
	}

	int getNo() { return No; }							//获取私有变量函数
	string getName() { return Name; }
	double getPrice() { return Price; }
	double getDiscount() {return Discount;}

	void setNo(int no) { No = no; }						//设置私有变量函数
	void setName(string name) { Name = name; }
	void setPrice(double price) { Price = price; }
	void setDiscount(double discount) { Discount = discount; }

private:
	int No;
	string Name;
	double Price;
	double Discount;
};

//商品库
class CommodityList
{
public:
	int index = 0;			//库帧

	CommodityList()			//无参构造
	{
		HeadCommodity = (Commodity*)malloc(sizeof(Commodity));		//为指针开辟空间避免越界操作
		TailCommodity = (Commodity*)malloc(sizeof(Commodity));
	}

	Commodity* getHeadCommdity() { return HeadCommodity; }			//获取私有变量
	Commodity* getTailCommdity() { return TailCommodity; }

	void SetHeadCommdit(Commodity* commodity) { HeadCommodity = commodity; }		//设置私有变量
	void SetTailCommdit(Commodity* commodity) { TailCommodity = commodity; }

	void CListAdd(Commodity* com) 
	{
		bool exist = false;		//判断录入商品是否存在

		if (index==0)			//判断是否为第一个商品
		{
			HeadCommodity = com;		//将第一个商品作为链表头
			TailCommodity = com;
			index++;
			CListAddSuccess();
			Sleep(2 * 1000);
		}
		else
		{
			Commodity* p;			//防止链表头数据变动,创建p进行历遍
			p = HeadCommodity;

			while (p != NULL)
			{
				if (p->getNo() == com->getNo() || !(p->getName().compare(com->getName())))		//判断商品的编号和名称是否重复
				{
					exist = true;
					break;
				}
				p = p->Next;		//令链表移动
			}

			if (exist)			
			{
				CListAddError();
				Sleep(2 * 1000);
			}
			else
			{
				TailCommodity->Next = com;			//链表尾的移动和变化
				TailCommodity = com;
				index++;		//存入库+1
				CListAddSuccess();
				Sleep(2 * 1000);
			}
		}
	}

	//用于商品文件的读取
	void RListAdd(Commodity* com)
	{
		bool exist = false;		//判断录入商品是否存在

		if (index == 0)			//判断是否为第一个商品
		{
			HeadCommodity = com;		//将第一个商品作为链表头
			TailCommodity = com;
			index++;
		}
		else
		{
			Commodity* p;			//防止链表头数据变动,创建p进行历遍
			p = HeadCommodity;

			while (p != NULL)
			{
				if (p->getNo() == com->getNo() || !(p->getName().compare(com->getName())))		//判断商品的编号和名称是否重复
				{
					exist = true;
					break;
				}
				p = p->Next;		//令链表移动
			}

			if (exist)
			{

			}
			else
			{
				TailCommodity->Next = com;			//链表尾的移动和变化
				TailCommodity = com;
				index++;		//存入库+1
			}
		}
	}

	void CListDel(int num) 
	{
		Commodity* p;		//防止链表头数据变动,创建p进行历遍
		p = HeadCommodity;
		bool DelSuccess = false;

		if (p->getNo() == num)		//判断删除的元素是否为链表头
		{
			HeadCommodity = HeadCommodity->Next;		//将链表头进行移动
			DelSuccess = true;
		}
		else
		{
			while (p != NULL &&p->Next != NULL)		//防止越界
			{
				if (p->Next->getNo() == num)		//判断中间元素是否为要删除节点
				{
					p->Next = p->Next->Next;		//将中间元素越过使第一与第三元素连接
					DelSuccess = true;
					index--;
				}
				p = p->Next;		//链表移动
			}
		}

		if (DelSuccess)		//判断是否删除成功
		{
			CListDelSuccess();
			Sleep(2 * 1000);
		}
		else {
			CListDelError();
			Sleep(2 * 1000);
		}
	}

	//商品编号更改
	void CListChangeO(int num,int no)
	{
		Commodity* p;
		p = HeadCommodity;
		bool ThLegal = true;
		bool ChSucess = false;

		while (p != NULL)
		{
			if (p->getNo() == no)
			{
				CChangeErrorS();
				Sleep(2 * 1000);
				ThLegal = false;
				break;
			}
			p = p->Next;
		}

		if (ThLegal)
		{
			p = HeadCommodity;
			while (p != NULL)
			{
				if (p->getNo() == num)
				{
					p->setNo(no);
					ChSucess = true;
					break;
				}
				p = p->Next;
			}
			if (ChSucess)
			{
				CChangeSuccess();
				Sleep(2 * 1000);
			}
			else
			{
				CChangeErrorN();
				Sleep(2 * 1000);
			}
		}
	}

	//商品名称更改
	void CListChangeN(int num, string name)
	{
		Commodity* p;
		p = HeadCommodity;
		bool ThLegal = true;
		bool ChSucess = false;

		while (p != NULL)
		{
			if (p->getName() == name)
			{
				CChangeErrorS();
				Sleep(2 * 1000);
				ThLegal = false;
				break;
			}
			p = p->Next;
		}

		if (ThLegal)
		{
			p = HeadCommodity;
			while (p != NULL)
			{
				if (p->getNo() == num)
				{
					p->setName(name);
					ChSucess = true;
					break;
				}
				p = p->Next;
			}
			if (ChSucess)
			{
				CChangeSuccess();
				Sleep(2 * 1000);
			}
			else
			{
				CChangeErrorN();
				Sleep(2 * 1000);
			}
		}
	}

	//商品价格更改
	void CListChangeP(int num, double price)
	{
		Commodity* p;
		p = HeadCommodity;
		bool ThLegal = true;
		bool ChSucess = false;

		while (p != NULL)
		{
			if (p->getPrice() == price)
			{
				CChangeErrorS();
				Sleep(2 * 1000);
				ThLegal = false;
				break;
			}
			p = p->Next;
		}

		if (ThLegal)
		{
			p = HeadCommodity;
			while (p != NULL)
			{
				if (p->getNo() == num)
				{
					p->setPrice(price);
					ChSucess = true;
					break;
				}
				p = p->Next;
			}
			if (ChSucess)
			{
				CChangeSuccess();
				Sleep(2 * 1000);
			}
			else
			{
				CChangeErrorN();
				Sleep(2 * 1000);
			}
		}
	}

	//商品折扣更改
	void CListChangeD(int num, double discount)
	{
		Commodity* p;
		p = HeadCommodity;
		bool ThLegal = true;
		bool ChSucess = false;

		while (p != NULL)
		{
			if (p->getDiscount() == discount)
			{
				CChangeErrorS();
				Sleep(2 * 1000);
				ThLegal = false;
				break;
			}
			p = p->Next;
		}

		if (ThLegal)
		{
			p = HeadCommodity;
			while (p != NULL)
			{
				if (p->getNo() == num)
				{
					p->setDiscount(discount);
					ChSucess = true;
					break;
				}
				p = p->Next;
			}
			if (ChSucess)
			{
				CChangeSuccess();
				Sleep(2 * 1000);
			}
			else
			{
				CChangeErrorN();
				Sleep(2 * 1000);
			}
		}
	}

	//根据编号查找
	void CListSeek(int num) 
	{
		Commodity* p;
		p = HeadCommodity;
		bool SeekSuccess = false;

		while (p != NULL)
		{
			if (p->getNo() == num) 
			{
				SeekSuccess = true;
				break;
			}
			p = p->Next;		//链表移动
		}
		if (SeekSuccess)
		{
			CSeekSuccess();
			cout << "编号" << p->getNo() << " 名称" << p->getName() << " 价格" << p->getPrice() << " 折扣" << p->getDiscount() << endl;
			system("pause");
		}
		else
		{
			CSeekError();
			Sleep(2 * 1000);
		}
	}

	//在删除中使用的查找功能
	bool DCListSeek(int num)
	{
		Commodity* p;
		p = HeadCommodity;
		bool SeekSuccess = false;

		while (p != NULL)
		{
			if (p->getNo() == num)
			{
				SeekSuccess = true;
				break;
			}
			p = p->Next;		//链表移动
		}
		if (SeekSuccess)
		{
			cout << "编号" << p->getNo() << " 名称" << p->getName() << " 价格" << p->getPrice() << " 折扣" << p->getDiscount() << endl;
			return true;
		}
		else
		{
			CSeekError();
			Sleep(2 * 1000);
			return false;
		}
	}

	//根据名称查找
	void CListSeek(string name)
	{
		Commodity* p;
		p = HeadCommodity;
		bool SeekSuccess = false;

		while (p != NULL)
		{
			if (p->getName() == name)
			{
				SeekSuccess = true;
				break;
			}
			p = p->Next;		//链表移动
		}

		if (SeekSuccess)
		{
			CSeekSuccess();
			cout << "编号" << p->getNo() << " 名称" << p->getName() << " 价格" << p->getPrice() << " 折扣" << p->getDiscount() << endl;
			system("pause");
		}
		else
		{
			CSeekError();
			Sleep(2 * 1000);
		}
	}

	void CListShow() 
	{
		Commodity* p;			//防止链表头变化,创建p历遍
		p = HeadCommodity;

		while (p != NULL)
		{
			cout << "编号" << p->getNo() << " 名称" << p->getName() << " 价格" << p->getPrice() << " 折扣" << p->getDiscount() << endl;
			p = p->Next;		//链表移动
		}
	}

	//排序后展示
	void SCListShow()
	{
		Commodity* p;			//防止链表头变化,创建p历遍
		p = HeadCommodity;

		while (p != NULL)
		{
			cout << "编号" << p->getNo() << " 名称" << p->getName() << " 价格" << p->getPrice() << " 折扣" << p->getDiscount() << " 折扣后价格" << (p->getPrice()*p->getDiscount()) <<endl;
			p = p->Next;		//链表移动
		}
	}

private:
	Commodity* HeadCommodity  = NULL;	//链表头
	Commodity* TailCommodity = NULL;	//链表尾
};
  • 界面相关代码(interface.h)
#pragma once
#include <iostream>
#include <Windows.h>
using namespace std;

//基础界面
void Basic()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*      1)用户登录             2)用户注册            3)退出程序                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//退出界面
void ExitSystem()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                       感谢您的使用,欢迎您下次光临                               *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//注册界面
void Sign()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*          请输入您的姓名,账号与密码注册,用空格间隔(姓名 账号 密码)            *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void SignSuccess()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                          注册成功,请您继续操作                                   *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//登录界面
void Login()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*              请输入您的账号与密码登录,用空格间隔(账号 密码)                   *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void LoginSuccess()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*        1)增加商品信息                               2)删除商品信息              *" << endl;
	cout << "*        3)修改商品信息                               4)查看商品列表              *" << endl;
	cout << "*        5)查询商品信息(编号查询)                     6)查询商品信息(名称查询)  *" << endl;
	cout << "*        7)返回上一级                                 8)退出程序                   *" << endl;
	cout << "************************************************************************************" << endl;
}
void LoginFail()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                     您输入的账号密码不正确,请重新输入                           *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//选项非已给选项的错误界面
void ChoiceError()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                        请您重新输入屏幕上的选项                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//密码多次错误停止界面
void CheckTimeUp()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                   您过多次数的输错账号密码,系统退出                             *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                          欢迎您的下次使用                                        *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//添加错误界面
void UListAddError()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                    添加失败!! 存在相同的编号或姓名!!                         *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//用户界面选择
void FuctionChoice()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*        1)商品管理                2)用户管理                3)权限管理         *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//管理员用户界面
void UserAdmin()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*        1)增加用户信息                               2)删除用户信息              *" << endl;
	cout << "*        3)修改用户信息                               4)查询用户列表              *" << endl;
	cout << "*        5)查询用户信息(编号)                       6)查询用户信息(姓名)      *" << endl;
	cout << "*        7)返回上一级                                 8)退出程序                   *" << endl;
	cout << "************************************************************************************" << endl;
}
void UserAdminError()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*             对不起,您当前无权使用该功能,请提升权限后重试                       *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//权限升级界面
void AdminUp()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                     请输入管理员口令以提升用户权限                               *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void AdminUpSuccess()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                      口令正确,已将您提升为管理员                                *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void AdminUpError()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                     口令无效,请重新输入有效的口令                               *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//商品添加界面
void CAdd()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*             请依次输入商品的名称,价格,折扣如:牛奶 5.00 0.8                    *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void CListAddError()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                    添加失败!! 存在相同的编号或商品名称!!                     *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void CListAddSuccess()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                       商品填加成功,请继续操作                                   *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//商品删除界面
void CDel()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                          请您输入商品的编号                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void CListDelError()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                    未找到该商品,请重新确定商品编号                              *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void CListDelSuccess()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                       商品信息删除成功,请继续操作                               *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}


//商品修改界面
void CChange()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                         请选择您需要更改的信息                                   *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*           1)商品编号   2)商品名称    3)商品价格   4)商品折扣                 *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void CChangeEnter()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*               请您输入编号以及更改信息,使用空格区分如:1 牛奶                   *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void CChangeErrorS()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                         欲替换数据未更改原来数据!                                   *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void CChangeErrorN()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                   未找到该编号,请确定编号后重新操作                              *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void CChangeSuccess()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                        信息更改成功,请继续操作                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//商品查询界面
void CSeekO()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                        请您输入商品的编号以查询                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void CSeekN()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                        请您输入商品的名称以查询                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void CSeekError()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                    未找到该编号的商品,请重新操作                                *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void CSeekSuccess()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                       查找成功,查找结果如下所示                                 *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}


//用户添加界面
void UAdd()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*             请依次输入用户的名称,账号,密码如:王五 123 123                     *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void UListAddSuccess()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                          用户填加成功,请继续操作                                *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//用户删除界面
void UDel()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                             请您输入用户的编号                                   *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void UListDelError()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                        未找到该用户,请重新确定用户编号                          *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void UListDelSuccess()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                       用户信息删除成功,请继续操作                               *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//用户修改界面
void UChange()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                           请选择您需要更改的信息                                 *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*           1)用户编号   2)用户姓名    3)用户账号   4)用户密码                 *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void UChangeEnter()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*               请您输入编号以及更改信息,使用空格区分如:1  更改信息              *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void UChangeErrorS()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                         欲替换数据未更改原来数据!                               *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void UChangeErrorN()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                   未找到该编号,请确定编号后重新操作                              *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void UChangeSuccess()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                        信息更改成功,请继续操作                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//用户查询界面
void USeekO()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                          请您输入用户的编号以查询                                *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void USeekN()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                          请您输入用户的姓名以查询                                *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void USeekError()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                        未找到该编号的用户,请重新操作                            *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void USeekSuccess()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品用户管理系统                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                         查找成功,查找结果如下所示                               *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//重复操作界面
void Repeat()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                       请问您是否要继续相同的操作                                 *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                      输入任意键以继续,输入2退出                                 *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//库中无内容错误界面
void UListNotingError()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                      当前用户库没有用户请先注册                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
void CListNotingError()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                      当前商品库没有商品请先增加商品                              *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//删除检查界面
void DelCheck()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                           是否确认删除该信息?                                   *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*               1)确定                            2)取消                         *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}

//显示错误
void ShowError()
{
	system("cls");
	cout << "************************************************************************************" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                            小型商品管理系统                                      *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                    当前库中不存在数据,请添加后重试                              *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "*                                                                                  *" << endl;
	cout << "************************************************************************************" << endl;
}
  • 工具类代码(tool.h)
#pragma once
#include "userData.h"
#include <fstream>
#include <time.h>
#include "userData.h"
#include "interface.h"
#include "commodityData.h"

//查找数据库中是否有该用户
User* FindUser(UserList userlist,int account)
{
	User* p;
	p = userlist.getHeadUser();

	while (p != NULL)
	{
		if (p->getAccount() == account)
		{
			return p;
		}
		p = p->Next;		//链表移动
	}
}

//以时间码作为编号
int CreatNo()
{
	return time(NULL);
}

//用户的读取写入
void UFileWrite(UserList userlist)
{
	ofstream ofile;
	ofile.open("UserData.txt",ios::trunc);

	User* p;
	p = userlist.getHeadUser();
	if (!(userlist.index == 0))
	{
		while (p != NULL)
		{
			ofile << p->getNo() << " " << p->getName() << " " << p->getAccount() << " " << p->getPassWord() << " " << p->getVip() << endl;
			p = p->Next;
		}
	}
	ofile.close();
}
void UFileRead(UserList* userlist)
{
	ifstream ifile;
	ifile.open("UserData.txt");

	int userNo;
	int userAccount;
	string userName;
	string userPassWord;
	bool userVip;

	if (!(ifile.peek() == EOF))
	{
		ifile.seekg(0,ios::beg);
		while (!ifile.eof())
		{
			ifile >> userNo >> userName >> userAccount >> userPassWord >> userVip;
			User* user = new User(userNo, userName, userAccount, userPassWord, userVip);
			userlist->RListAdd(user);
		}
	}

	ifile.close();
}

//商品的读取写入
void CFileWrite(CommodityList commoditylist)
{
	ofstream ofile;
	ofile.open("CommodityListData.txt", ios::trunc);

	Commodity* p;
	p = commoditylist.getHeadCommdity();
	if (!(commoditylist.index == 0))
	{
		while (p != NULL)
		{
			ofile << p->getNo() << " " << p->getName() << " " << p->getPrice() << " " << p->getDiscount() << endl;
			p = p->Next;
		}
	}
	ofile.close();
}
void CFileRead(CommodityList* commoditylist)
{
	ifstream ifile;
	ifile.open("CommodityListData.txt");

	int commodityNo;
	string commodityName;
	double commodityPrice;
	double commodityDiscount;

	if (!(ifile.peek() == EOF))
	{
		while (!ifile.eof())
		{
			ifile >> commodityNo >> commodityName >> commodityPrice >> commodityDiscount;
			Commodity* commodity = new Commodity(commodityNo, commodityName, commodityPrice, commodityDiscount);
			commoditylist->RListAdd(commodity);
		}
	}
	ifile.close();
}

//商品折扣后排序
void SortCommodity(CommodityList* commoditylist)
{
	Commodity* p;
	p = commoditylist->getHeadCommdity();

	Commodity* c1;
	Commodity* c2;

	int No;			
	string Name;
	double Price;
	double Discount;

	//冒泡算法排序
	for (int i = 0; i <commoditylist->index - 1; i++)					
	{
		p = commoditylist->getHeadCommdity();				//指针回归
		for (int j = 0; j <commoditylist->index - i - 1; j++)
		{
			c1 = p;
			c2 = p->Next;

			if ((c1->getPrice()*c1->getDiscount()) > (c2->getPrice()*c2->getDiscount()))
			{
				//数据交换
				No = c1->getNo();
				Name = c1->getName();
				Price = c1->getPrice();
				Discount = c1->getDiscount();

				c1->setNo(c2->getNo());
				c1->setName(c2->getName());
				c1->setPrice(c2->getPrice());
				c1->setDiscount(c2->getDiscount());

				c2->setNo(No);
				c2->setName(Name);
				c2->setPrice(Price);
				c2->setDiscount(Discount);
			}
			p = p->Next;				//指针偏移
		}
	}
	commoditylist->SCListShow();
}
  • 主函数(ClassWork.cpp)
#include <iostream>
#include <windows.h>
#include "commodityData.h"
#include "userData.h"
#include "interface.h"
#include "tool.h"

int main()
{
    int Time=0;                         //记录密码输错次数
    int Choice= 0;                       //用户选项

    int Account=0;                      //用户信息输入
    string PassWord;
    string UserName;
    int UserNo;

    string SuperWord = "admin";         //管理员口令和输入
    string EnterSuperWord;

    int CommodityNo;                    //商品信息输入
    string CommodityName;
    double CommodityPrice;
    double CommodityDiscount;

    bool OrderSuc = true;               //判断是否循环
    bool Continue = true;

    int no;                             //更改信息输入
    int changeNo;
    string changeName;
    double changePrice;
    double changeDiscount;
    int changeAccount;
    string changePassWord;

    int seekNo;                         //查询信息输入
    string seekName;

    CommodityList commoditylist;        //用户及商品库
    UserList userlist;

    UFileRead(&userlist);               //读取用户库
    CFileRead(&commoditylist);          //读取商品库

    //登录界面
    while (OrderSuc)
    {
        if (Time >=3)
        {
            CheckTimeUp();
            exit(1);
        }
        Basic();
        cin >> Choice;
        switch (Choice)
        {
        case 1:                     //用户登录
                if (userlist.index == 0)
                {
                    UListNotingError();
                    Sleep(2 * 1000);
                }
                else
                {
                    Login();
                    cin >> Account >> PassWord;
                    OrderSuc = userlist.CheckAccount(Account, PassWord);
                    Time++;
                }
                break;
            
        case 2:                     //用户注册
            {
                Sign();
                cin >> UserName >> Account >> PassWord;
                User* user = new User(CreatNo(), UserName, Account, PassWord, false);            //由于使用链表需要每次创建对象使用不同的地址
                userlist.UListAdd(user);
                UFileWrite(userlist);
                break;
            }
        case 3:                     //退出系统
            ExitSystem();
            exit(0);
        default:                    //防止用户乱输入
            ChoiceError();
            Sleep(2 * 1000);
            break;
        }
    }
   
    User* LoginUser = FindUser(userlist,Account);       //在用户数据库中找到登录用户

    //商品或用户界面
    while (!OrderSuc)
    {
        OrderSuc = true;
        //界面选择
        while (OrderSuc)
        {
            FuctionChoice();
            cin >> Choice;

            switch (Choice)
            {
            case 1:                     //选择商品界面
                OrderSuc = false;
                break;
            case 2:                     //选择用户界面
                if (LoginUser->getVip())    //验证是否有权限
                {
                    OrderSuc = false;
                }
                else
                {
                    UserAdminError();
                    Sleep(2 * 1000);
                }
                break;
            case 3:                     //权限提升界面
                AdminUp();
                cin >> EnterSuperWord;
                if (EnterSuperWord == SuperWord)
                {
                    LoginUser->setVip(true);
                    AdminUpSuccess();
                    Sleep(2 * 1000);
                }
                else
                {
                    AdminUpError();
                    Sleep(2 * 1000);
                }
                break;
            default:                    //防止用户乱选
                ChoiceError();
                Sleep(2 * 1000);
                break;
            }

        }

        OrderSuc = true;        //重新循环
        //功能选择
        switch (Choice)
        {
        case 1:             //商品管理界面
            while (OrderSuc)
            {
                LoginSuccess();
                cin >> Choice;
                switch (Choice)
                {
                case 1:         //商品添加
                {
                    if (!LoginUser->getVip())   //判斷是否有权限
                    {
                        UserAdminError();
                        Sleep(2 * 1000);
                        break;
                    }
                    else
                    {
                        Continue = true;
                        while (Continue)
                        {
                            CAdd();
                            cin >> CommodityName >> CommodityPrice >> CommodityDiscount;
                            Commodity* commodity = new Commodity(CreatNo(), CommodityName, CommodityPrice, CommodityDiscount);          //使用链表应创建不同的对象防止地址相同
                            commoditylist.CListAdd(commodity);

                            Repeat();
                            cin >> Choice;
                            switch (Choice)     //判断是否继续
                            {
                            case 2:
                                Continue = false;
                                break;
                            default:
                                break;
                            }
                        }
                    }
                    break;
                }
                case  2:        //商品删除
                    if (!LoginUser->getVip())
                    {
                        UserAdminError();
                        Sleep(2 * 1000);
                        break;
                    }
                    if (commoditylist.index == 0)   //判断库中是否有数据
                    {
                        ShowError();
                        Sleep(2 * 1000);
                    }
                    else
                    {
                        Continue = true;
                        while (Continue)
                        {
                            CDel();
                            commoditylist.CListShow();
                            cin >> CommodityNo;
                            if (commoditylist.DCListSeek(CommodityNo))      //判断是否存在
                            {
                                DelCheck();
                                cin >> Choice;
                                switch (Choice)
                                {
                                case 1:
                                    commoditylist.CListDel(CommodityNo);
                                    break;
                                case 2:
                                    break;
                                default:
                                    ChoiceError();
                                    Sleep(2 * 1000);
                                    break;
                                }
                            }

                            Repeat();
                            cin >> Choice;
                            switch (Choice)     //判断是否继续
                            {
                            case 1:
                                break;
                            case 2:
                                Continue = false;
                                break;
                            default:
                                ChoiceError();
                                Sleep(2 * 1000);
                                break;
                            }
                        }
                    }
                    break;

                case 3:         //商品修改

                    if (!LoginUser->getVip())       //判断是否有权限
                    {
                        UserAdminError();
                        Sleep(2 * 1000);
                        break;
                    }

                    if (commoditylist.index == 0)   //判断库中是否有数据
                    {
                        ShowError();
                        Sleep(2 * 1000);
                    }
                    else
                    {
                        Continue = true;
                        while (Continue)
                        {
                            CChange();
                            int ChangeChoice;
                            cin >> ChangeChoice;
                            switch (ChangeChoice)
                            {
                            case 1:     //修改编号
                                CChangeEnter();
                                commoditylist.CListShow();
                                cin >> no >> changeNo;
                                commoditylist.CListChangeO(no, changeNo);
                                break;
                            case 2:     //修改名称
                                CChangeEnter();
                                commoditylist.CListShow();
                                cin >> no >> changeName;
                                commoditylist.CListChangeN(no, changeName);
                                break;
                            case 3:     //修改价格
                                CChangeEnter();
                                commoditylist.CListShow();
                                cin >> no >> changePrice;
                                commoditylist.CListChangeP(no, changePrice);
                                break;
                            case 4:     //修改折扣
                                CChangeEnter();
                                commoditylist.CListShow();
                                cin >> no >> changeDiscount;
                                commoditylist.CListChangeD(no, changeDiscount);
                                break;
                            default:    //防止用户乱输入
                                ChoiceError();
                                Sleep(2 * 1000);
                                break;
                            }

                            Repeat();
                            cin >> Choice;
                            switch (Choice)     //判断是否继续
                            {
                            case 1:
                                break;
                            case 2:
                                Continue = false;
                                break;
                            default:
                                ChoiceError();
                                Sleep(2 * 1000);
                                break;
                            }
                        }
                    }
                    break;
                case 4:         //商品列表显示
                    if (!(commoditylist.index == 0))        //判断是否有数据
                    {
                        SortCommodity(&commoditylist);
                        system("pause");
                    }
                    else
                    {
                        ShowError();
                        Sleep(2 * 1000);
                    }
                    break;
                case 5:         //商品编号查询
                    if (commoditylist.index == 0)   //判断库中是否有数据
                    {
                        ShowError();
                        Sleep(2 * 1000);
                        break;
                    }
                    Continue = true;
                    while (Continue)
                    {
                        CSeekO();
                        cin >> seekNo;
                        commoditylist.CListSeek(seekNo);

                        Repeat();
                        cin >> Choice;
                        switch (Choice)     //判断是否继续
                        {
                        case 2:
                            Continue = false;
                            break;
                        }
                    }
                    break;
                case 6:         //商品名称查询
                    if (commoditylist.index == 0)   //判断库中是否有数据
                    {
                        ShowError();
                        Sleep(2 * 1000);
                        break;
                    }

                    Continue = true;
                    while (Continue)
                    {
                        CSeekN();
                        cin >> seekName;
                        commoditylist.CListSeek(seekName);

                        Repeat();
                        cin >> Choice;
                        switch (Choice)     //判断是否继续
                        {
                        case 2:
                            Continue = false;
                            break;
                        }
                    }
                    break;
                case 7:       //返回上一级
                    OrderSuc = false;
                    break;
                case 8:       //退出程序
                    ExitSystem();
                    exit(0);
                default:      //防止用户乱输入
                    ChoiceError();
                    Sleep(2 * 1000);
                    break;
                }
                CFileWrite(commoditylist);          //将商品导出到文件
            }
            break;
        case 2:             //用户管理界面
            while (OrderSuc)
            {
                UserAdmin();
                cin >> Choice;
                switch (Choice)
                {
                case 1:         //用户添加
                {
                    Continue = true;
                    while (Continue)
                    {
                        UAdd();
                        cin >> UserName >> Account >> PassWord;
                        User* user = new User(CreatNo(), UserName, Account, PassWord, false);           //使用链表应创建不同的对象防止地址相同
                        userlist.UListAdd(user);

                        Repeat();
                        cin >> Choice;
                        switch (Choice)     //判断是否继续
                        {
                        case 2:
                            Continue = false;
                            break;
                        }
                    }
                    break;
                }
                case  2:        //用户删除
                    Continue = true;
                    while (Continue)
                    {
                        UDel();
                        userlist.UListShow();
                        cin >> UserNo;
                        if (userlist.DUListSeek(UserNo))
                        {
                            DelCheck();
                            cin >> Choice;
                            switch (Choice)
                            {
                            case 1:
                                userlist.UListDel(UserNo);
                                break;
                            case 2:
                                break;
                            default:
                                ChoiceError();
                                Sleep(2 * 1000);
                                break;
                            }
                        }

                        Repeat();
                        cin >> Choice;
                        switch (Choice)     //判断是否继续
                        {
                        case 1:
                            break;
                        case 2:
                            Continue = false;
                            break;
                        default:
                            ChoiceError();
                            Sleep(2 * 1000);
                            break;
                        }
                    }
                    break;
                case 3:         //用户修改
                    Continue = true;
                    while (Continue)
                    {
                        UChange();
                        int ChangeChoice;
                        cin >> ChangeChoice;
                        switch (ChangeChoice)
                        {
                        case 1:     //修改编号
                            UChangeEnter();
                            userlist.UListShow();
                            cin >> no >> changeNo;
                            userlist.UListChangeO(no, changeNo);
                            break;
                        case 2:     //修改姓名
                            UChangeEnter();
                            userlist.UListShow();
                            cin >> no >> changeName;
                            userlist.UListChangeN(no, changeName);
                            break;
                        case 3:     //修改账户
                            UChangeEnter();
                            userlist.UListShow();
                            cin >> no >> changeAccount;
                            userlist.UListChangeA(no, changeAccount);
                            break;
                        case 4:     //修改密码
                            UChangeEnter();
                            userlist.UListShow();
                            cin >> no >> changePassWord;
                            userlist.UListChangeP(no, changePassWord);
                            break;
                        default:    //防止用户乱输入
                            ChoiceError();
                            Sleep(2 * 1000);
                            break;
                        }

                        Repeat();
                        cin >> Choice;
                        switch (Choice)     //判断是否继续
                        {
                        case 2:
                            Continue = false;
                            break;
                        }
                    }
                    break;
                case 4:         //用户列表显示
                    if (!(userlist.index == 0))
                    {
                        userlist.UListShow();
                        system("pause");
                    }
                    else
                    {
                        ShowError();
                        Sleep(2 * 1000);
                    }
                    break;
                case 5:         //用户编号查询
                    Continue = true;
                    while (Continue)
                    {
                        USeekO();
                        cin >> seekNo;
                        userlist.UListSeek(seekNo);

                        Repeat();
                        cin >> Choice;
                        switch (Choice)     //判断是否继续
                        {
                        case 2:
                            Continue = false;
                            break;
                        }
                    }
                    break;
                case 6:         //用户姓名查询
                    Continue = true;
                    while (Continue)
                    {
                        USeekN();
                        cin >> seekName;
                        userlist.UListSeek(seekName);

                        Repeat();
                        cin >> Choice;
                        switch (Choice)     //判断是否继续
                        {
                        case 2:
                            Continue = false;
                            break;
                        }
                    }
                    break;
                case 7:       //返回上一级
                    OrderSuc = false;
                    break;
                case 8:       //退出程序
                    ExitSystem();
                    exit(0);
                default:      //防止用户乱输入
                    ChoiceError();
                    Sleep(2 * 1000);
                    break;
                }
                UFileWrite(userlist);       //将用户信息导出文件
            }
            break;
        default:            //防止用户乱输入
            ChoiceError();
            Sleep(2 * 1000);
            break;
        }
    }


    return 0;
}
  • 10
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值