菜鸟前路---c++大作业(来迟了。。。)

版权声明:属原创,引用请指明出处 https://blog.csdn.net/qq_43624878/article/details/86032008

c++三大系统之三

  1. 图书管理系统
    <源自我舍友—赵小哥,感觉写的很nb。。。(人还帅)>
#include <iostream>
#include <stdlib.h>
#include <windows.h>
#include <fstream>
#include <conio.h>
#include <string.h>
using namespace std;

class login
{
	private:
		login *next;
		login *p,*head;
	public:
		string account;
		string password;
		string stu_name;
		string sex;
		string stu_id;
		void apply_space();//为节点申请内存空间
		void registered();//会员注册
		void login_to_1();//会员登录
		void login_to_2();//管理员登陆
		int Determinefile_1();//判断文件是否打开成功(读),并赋值给链表
		int Determinefile_2();//判断文件是否打开成功(增),并存入文件
		int Determinepass();//判断账号密码是否正确
		void save_2();//保存信息函数(账号信息)
};

class book
{
	private:
		book *next_b;
		book *p_b,*head_b; 
		string bookname;//书名
		string bookid;//书籍编号 
		string price;//书籍价格 
		string author;//作者 
		string state;//存在状态
		string message_name;//学生信息 
		string message_sex;
		string message_id;
	public:
		void apply_space_b();//为节点申请内存空间 
		void lend_book(login log);//借书函数 
		void return_book(login log);//还书函数 
		void Determinefile_3(int gg);//判断文件是否打开成功(读),并赋值给链表
		void showbook_1();//展示函数(剩余的) 
		void showbook_2();//展示函数(借出的) 
		void save_1();//保存信息函数(书籍信息)
		void change_message(login log);//
		void add_book();//增加书籍函数 
		void Determinefile_4();//判断文件是否打开成功(增),并存入文件
		void change_book();//更改书籍信息
		void delete_book();//删除书籍信息 
		void free_space();//释放内存空间 
};

void main_system_1(login log);
void main_system_2();

void login::apply_space()
{
	head = new login;
	if(head == NULL)
	{
		cout << "空间申请失败" << endl;
	}
	head->next = NULL;
	p = new login;
}

void book::apply_space_b()
{
	head_b = new book;
	if(head_b == NULL)
	{
		cout << "空间申请失败" << endl;
	}
	head_b->next_b = NULL;
	p_b = new book; 
}

int login::Determinefile_1()
{
	int mm = 0;
	string mmp;
	ifstream in;
	in.open("E:\\文本夹\\图书借阅管理\\图书借阅管理-账号密码.txt",ios::in);
	if(!in)
	{
		system("color F4");
		cout << "创建文件失败!!!" << endl;
		exit(0);
	}
	p = head;
	p->next = NULL;
	while(!in.eof())
	{
		in >> mmp;
		if(mmp == "")
		{
			break;
		}
		p->next = new login;
		p = p->next;
		p->account = mmp;
		in >> p->password;
		in >> p->stu_name;
		in >> p->sex;
		in >> p->stu_id;
		mm ++;
	}
	if(mm == 0)
	{
		system("color F4");
		cout << "\n\n数据库中无账号信息!!!" << endl << "\n请先进行注册操作!!!" << endl;
		Sleep(750);
		system("color F0");
		return 1;
	}
	in.close();
	p->next = new login;
	p->next == NULL;
	return 0;
}

int login::Determinefile_2()
{
	p = head;
	while(p->next)//判断输入的信息是否已经被使用 
	{
		if(p->next->account == "")
		{
			break;
		}
		
		p = p->next;
		if(p->account == account)
		{
			system("color F4");
			cout << "\n\n该账号已被使用!!!\n" << endl;
			cout << "\n\n按任意键返回主菜单..." << endl;
			getchar();
			getchar();
			return 1;
		}
		if(p->stu_name == stu_name)
		{
			system("color F4");
			cout << "\n\n该姓名已被使用!!!\n" << endl;
			cout << "\n\n按任意键返回主菜单..." << endl;
			getchar();
			getchar();
			return 1;
		}
		if(p->stu_id == stu_id)
		{
			system("color F4");
			cout << "\n\n该学号已被使用!!!\n" << endl;
			cout << "\n\n按任意键返回主菜单..." << endl;
			getchar();
			getchar();
			return 1;
		}
	}
	
	ofstream out;
	out.open("E:\\文本夹\\图书借阅管理\\图书借阅管理-账号密码.txt",ios::app);
	if(!out)
	{
		system("color F4");
		cout << "创建文件失败!!!" << endl;
		exit(0);
	}
	out << endl << account;
	out << "   " << password;
	out << "   " << stu_name;
	out << "   " << sex;
	out << "   " << stu_id;
	out.close();
	system("color F2");
	cout << "\n创建成功!!!" << endl << "\n按任意键继续..." << endl;
	getchar();
	getchar();
	system("cls");
	system("color F0");
	return 0;
}

int login::Determinepass()
{
	p = head;
	while(p->next)
	{
		if(p->next->account == "")
		{
			break;
		}
		p = p->next;
		if((p->account == account) && (p->password == password))
		{
			stu_name = p->stu_name;
			sex = p->sex;
			stu_id = p->stu_id;
			system("color F2");
			cout << "\n\n\n\t登陆成功!" << endl;
			cout << "\n\n\t\t按任意键继续..." << endl;
			getchar();
			getchar();
			system("cls");
			return 1;
		}
	}
	system("color F4");
	cout << "\n输入错误,请重新输入" << endl;
	Sleep(500); 
	return 0;
}

void login::login_to_1()//登陆账号(会员)
{
	system("color F0");
	string account_;
	int der;
	cout << "\n请输入您的账号:";
	cin >> account_;
	if(account_ == "exit")//退出指令 
	{
		exit(0);
	}
	cout << "请输入您的密码:";
	int q=0;
	char a;
	char arr[100]="";//密码数组 
	while((a = getch()) != '\r')
	{
		if((a >= '0' && a <= '9') || (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z'))
		{
			putchar('*');
			arr[q++] = a;
		}
		if(a=='\b')
		{
			putchar('\b');
			putchar(' ');
			putchar('\b');
			arr[--q]='\0';
		}
	}
	if(strcmp(arr,"exit") == 0)//退出指令 
	{
		exit(0);
	}
	account = account_;
	password = arr;
	return;
}

void login::login_to_2()//登陆账号(管理员)
{
	int chance = 3;
	while(1)
	{
		system("color F0");
		cout << "\n请输入管理员操作密码:";
		int q=0;
		char a;
		char arr[100]="";//密码数组 
		while((a = getch()) != '\r')
		{
			if((a >= '0' && a <= '9') || (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z'))
			{
				putchar('*');
				arr[q++] = a;
			}
			if(a=='\b')
			{
				putchar('\b');
				putchar(' ');
				putchar('\b');
				arr[--q]='\0';
			}
		}
		if(strcmp(arr,"exit") == 0)//退出指令 
		{
			exit(0);
		}
		else if(strcmp(arr,"nylgnb") == 0)
		{
			system("color F2");
			cout << "\n\n\n\t登陆成功!" << endl;
			cout << "\n\n\t\t按任意键继续..." << endl;
			getchar();
			getchar();
			system("cls");
			break;
		}
		else
		{
			system("color F4");
			chance--;
			if(chance == 0)
			{
				cout << "机会用尽,本系统即将退出!!!" << endl;
				Sleep(500);
				system("color F0");
				exit(0);
			}
			cout << "\n\n操作密码错误!!!" << endl;
			cout << "您还有" << chance << "次机会." << endl;
			Sleep(500);
			continue;
		}
	}
	system("cls");
	return;
}

void login::registered()
{
	cout << "\n请完善您的信息:" << endl;
	string stuname_,sex_,stuid_,account_,password_;
	cout << "\n姓名:";
	cin >> stuname_;
	if(stuname_ == "exit")//退出指令 
	{
		exit(0);
	}
	stu_name = stuname_;
	cout << "性别:";
	cin >> sex_;
	if(sex_ == "exit")//退出指令 
	{
		exit(0);
	}
	sex = sex_;
	cout << "学号:";
	cin >> stuid_;
	stu_id = stuid_;
	cout << "\n账号:";
	cin >> account_;
	account = account_;
	cout << "密码:";
	cin >> password_;
	password = password_;
} 

void login_in()
{
	string instruction_1;//输入指令
	login log;
	log.apply_space();
	while(1)//死循环 
	{
		system("color F0");
		cout << " \t------------------------------------------------------------" << endl;
		cout << " \t|                   【欢迎使用本操作系统】                 |" << endl;
		cout << " \t|                                                          |" << endl;
		cout << " \t|                                        <请先进行身份验证>|" << endl;
		cout << " \t|                                      <非会员用户不可借书>|" << endl;
		cout << " \t|                                                          |" << endl;
		cout << " \t|                     の 1.会员登陆                        |" << endl;
		cout << " \t|                     の 2.会员注册                        |" << endl;
		cout << " \t|                     の 3.图书管理员登陆                  |" << endl;
		cout << " \t|                     の 4.退出系统                        |" << endl;
		cout << " \t------------------------------------------------------------" << endl;
		cout << "您的操作为:";
		cin >> instruction_1;
		if(instruction_1 == "1")
		{
			int der,qwq = 0;
			while(1)
			{
				qwq = log.Determinefile_1();//打开文件(读)
				if(qwq == 1)
				{
					system("cls");
					break;
				}
				log.login_to_1();//登陆(会员)
				der = log.Determinepass();
				if(der == 1)
				{
					main_system_1(log);//会员主界面
					break;
				}
			}
		}
		else if(instruction_1 == "2")
		{
			int mmp; 
			log.registered();//注册
			log.Determinefile_1();//打开文件(读)--判断信息是否有重复 
			if(log.Determinefile_2() == 0)//打开文件(增)并增加
			{
				main_system_1(log);//会员主界面 
			}
			system("cls");
		}
		else if(instruction_1 == "3")
		{
			log.login_to_2();//登陆(管理员)
			main_system_2();//管理员主界面 
		}
		else if(instruction_1 == "4")
		{
			exit(0);
		}
		else
		{
			system("color F4");
			cout << "指令输入错误,请重新输入...";
			Sleep(500);
			system("cls");
		}
	}
	return;
}

void login::save_2()
{
	p = head;
	while(p->next)
	{
		if(p->next->account == "")
		{
			break;
		}
		p = p->next;
		if(p->stu_name == stu_name || p->stu_id == stu_id)
		{
			p->password = password;
			p->stu_name = stu_name;
			p->stu_id = stu_id;
		}
	}
	ofstream out;
	out.open("E:\\文本夹\\图书借阅管理\\图书借阅管理-账号密码.txt",ios::out);
	if(!out)
	{
		system("color F4");
		cout << "创建文件失败!!!" << endl;
		exit(0);
	}
	p = head;
	while(p->next)
	{
		if(p->next->account == "" || p->next->account == p->account)
		{
			break;
		}
		p = p->next;
		out << p->account;
		out << "   " << p->password;
		out << "   " << p->stu_name;
		out << "   " << p->sex;
		out << "   " << p->stu_id << endl;
	}
	out.close();
	cout << "正在上传操作..." << endl;
	Sleep(500);
	cout << "上传成功!!!" << endl;
	Sleep(500);
	return;
}

//SAO----------------------------------两个类函数之间的分割线-------------------------------------------------------------OAS
void book::Determinefile_3(int gg)
{
	int mm = 0;
	string mmp;
	ifstream in;
	in.open("E:\\文本夹\\图书借阅管理\\图书借阅管理-书籍信息.txt",ios::in);
	if(!in)
	{
		system("color F4");
		cout << "创建文件失败!!!" << endl;
		exit(0);
	}
	p_b = head_b;
	while(!in.eof())
	{
		in >> mmp;
		if(mmp == "")
		{
			break;
		}
		p_b->next_b = new book;
		p_b = p_b->next_b;
		p_b->bookname = mmp;
		in >> p_b->author;
		in >> p_b->bookid;
		in >> p_b->price;
		in >> p_b->state;
		in >> p_b->message_name;
		in >> p_b->message_sex;
		in >> p_b->message_id;
		mm ++;
	}
	if(mm == 0 && gg == 0)
	{
		system("color F6");
		cout << "\n\n数据库中无书籍信息......" << endl << "\n请联系管理员进行增加操作---\n联系电话:400 12138 250." << endl;
		Sleep(750);
		exit(0);
	}
	in.close();
	p_b->next_b = new book;
	p_b->next_b == NULL;
	return;
}

void book::lend_book(login log)
{
	string lpl;
	cout << "\n请输入您想借出的书籍的名称或者编号:";
	cin >> lpl;
	p_b = head_b;
	bool X = false;
	bool A = false;
	while(p_b->next_b)
	{
		if(p_b->next_b->bookname == "")
		{
			break;
		}
		p_b = p_b->next_b;
		if(p_b->bookname == lpl || p_b->bookid == lpl)
		{
			if(p_b->state == "none")
			{
				A = true;
				break;
			}
			p_b->state = "none";
			p_b->message_name = log.stu_name;
			p_b->message_sex = log.sex;
			p_b->message_id = log.stu_id;
			X = true;
			break; 
		}
	}
	if(A == true)
	{
		system("color F4");
		cout << "\n\n非常抱歉,此书已被别人借走" << endl;
		cout << "您可以尝试借其他书籍" << endl;
		cout << "\n\n按任意键返回主菜单..." << endl;
		getchar();
		getchar();
		system("color F0");
		return;
	}
	if(X == false)
	{
		system("color F4");
		cout << "\n\n非常抱歉,图书馆内现在并无此书" << endl;
		cout << "\n\n按任意键返回主菜单..." << endl;
		getchar();
		getchar();
		system("color F0");
		return;
	}
	system("color F2");
	cout << "\n操作成功!" << endl << "请在门口柜台处展示您所借的书籍..." << endl; 
	cout << "\n\n按任意键返回主菜单..." << endl;
	getchar();
	getchar();
	return;
} 

void book::return_book(login log)
{
	string lkl;
	cout << "\n请输入您想归还的书籍的名称或者编号:";
	cin >> lkl;
	bool Y = false;
	bool B = false;
	p_b = head_b;
	while(p_b->next_b)
	{
		if(p_b->next_b->bookname == "")
		{
			break;
		}
		p_b = p_b->next_b;
		if(p_b->message_name != log.stu_name || p_b->message_id != log.stu_id)
		{
			system("color F4");
			cout << "\n\n   这并非是您所借的书!!!" << endl;
			cout << "(您想要归还的书的编号或者书名输入错误)" << endl;
			cout << "\n\n按任意键返回主菜单..." << endl;
			getchar();
			getchar();
			system("color F0");
			return;
		}
		if(p_b->bookname == lkl || p_b->bookid == lkl)
		{
			if(p_b->state == "left")
			{
				B = true;
				break;
			}
			p_b->state = "left";
			p_b->message_name = "###";
			p_b->message_sex = "###";
			p_b->message_id = "###";
			Y = true;
			break; 
		}
	}
	if(B == true)
	{
		system("color F4");
		cout << "\n您想要归还的书仍存在于图书馆内" << endl;
		cout << "(您想要归还的书的编号或者书名输入错误)" << endl;
		cout << "\n\n按任意键返回主菜单..." << endl;
		getchar();
		getchar();
		system("color F0");
		return;
	}
	if(Y == false)
	{
		system("color F4");
		cout << "\n非常抱歉,您想要归还的书籍查询不到记录" << endl;
		cout << "(这可能并非是本图书馆内的书籍)" << endl;
		cout << "\n\n按任意键返回主菜单..." << endl;
		getchar();
		getchar();
		system("color F0");
		return;
	}
	system("color F2");
	cout << "\n操作成功!" << endl << "请在书籍回收处交还您所借的书籍..." << endl;
	cout << "\n\n按任意键返回主菜单..." << endl;
	getchar();
	getchar();
	return;
} 

void book::showbook_1()
{
	system("color F1");
	cout << "\n库内书籍信息如下:" << endl;
	cout << "※书名※   ※作者※  ※价格※  ※书籍编号※" << endl;
	p_b = head_b;
	while(p_b->next_b)
	{
		if(p_b->next_b->bookname == "")
		{
			break;
		}
		p_b = p_b->next_b;
		if(p_b->state == "left")
		{
			cout << p_b->bookname << "    " << p_b->author << "     " << p_b->price << "         " << p_b->bookid << endl;
		}
	}
	cout << "\n\n按任意键返回主菜单..." << endl;
	getchar();
	getchar();
	return;
}

void book::save_1()
{
	ofstream out;
	out.open("E:\\文本夹\\图书借阅管理\\图书借阅管理-书籍信息.txt",ios::out);
	if(!out)
	{
		system("color F4");
		cout << "创建文件失败!!!" << endl;
		exit(0);
	}
	p_b = head_b;
	while(p_b->next_b)
	{
		if(p_b->next_b->bookname == "" || p_b->next_b->bookname == p_b->bookname)
		{
			break;
		}
		p_b = p_b->next_b;
		out << p_b->bookname << "   ";
		out << p_b->author << "   ";
		out << p_b->bookid << "   ";
		out << p_b->price << "   ";
		out << p_b->state << "   ";
		out << p_b->message_name << "   ";
		out << p_b->message_sex << "   ";
		out << p_b->message_id << endl;
	}
	out.close();
	system("color F2"); 
	cout << "正在上传操作..." << endl;
	Sleep(500);
	cout << "上传成功!!!" << endl;
	Sleep(500);
	return;
} 

void book::change_message(login log)
{
	string instruction_3;//输入指令
	system("cls");
	string alter;
	while(1)
	{
		system("color F6");
		cout << "\n\n请问您想更改什么信息?(1.密码 2.姓名 3.学号)" << endl; 
		cout << "您的操作为:";
		cin >> instruction_3;
		if(instruction_3 == "1")
		{
			cout << "\n请输入更改后的密码:";
			cin >> alter;
			log.password = alter;
			break;
		}
		else if(instruction_3 == "2")
		{
			cout << "\n请输入更改后的姓名:";
			cin >> alter;
			log.stu_name = alter;
			break;
		}
		else if(instruction_3 == "3")
		{
			cout << "\n请输入更改后的学号:";
			cin >> alter;
			log.stu_id = alter;
			break;
		}
		else
		{
			system("color F4");
			cout << "\n指令输入错误,请重新输入...";
			Sleep(500);
			system("cls");
		}
	}
	system("color F2");
	cout << "\n\n\t修改成功!" << endl << "\n按任意键上传..." << endl;
	getchar();
	getchar();
	log.Determinefile_1();//防止注册信息无法读入链表 
	log.save_2();//保存信息函数(账号信息)
	return;
}

void book::free_space()
{
	book * m,* n;
	m = head_b;
	n = m;
	while(n->next_b != NULL)
	{
		if(n->next_b->bookname == "")
		{
			break;
		}
		m = n->next_b;
		delete n;
		n = m;
	}
	m = NULL;
	n = NULL;
	delete p_b;
	delete head_b;
}

void main_system_1(login log)
{
	string instruction_2;//输入指令
	book bo;
	bo.apply_space_b();
	bo.Determinefile_3(0);
	while(1)//死循环 
	{
		system("color F0");
		cout << " \t------------------------------------------------------------" << endl;
		cout << " \t|                     【图书操作系统】                     |" << endl;
		cout << " \t|                                                          |" << endl;
		cout << " \t|                                                -->会员<--|" << endl;
		cout << " \t|                                                          |" << endl;
		cout << " \t|                      の 1.借出书籍                       |" << endl;
		cout << " \t|                      の 2.归还书籍                       |" << endl;
		cout << " \t|                      の 3.查询图书                       |" << endl;
		cout << " \t|                      の 4.修改账号信息                   |" << endl;
		cout << " \t|                      の 5.退出系统                       |" << endl;
		cout << " \t------------------------------------------------------------" << endl;
		cout << "您的操作为:";
		cin >> instruction_2;
		if(instruction_2 == "1")
		{
			string chioce_1;
			cout << "\n请确保您已查询过您所想借出的书籍的信息...\n是否继续? ( yes or no )" << endl;
			while(1)
			{
				cout << "您的选择是:";
				cin >> chioce_1;
				if(chioce_1 == "yes")
				{
					bo.lend_book(log);//借书函数
					bo.save_1();//保存信息函数(书籍信息)
					system("cls");
					break;
				}
				else if(chioce_1 == "no")
				{
					cout << "\n按任意键按返回主菜单";
					getchar();
					getchar();
					system("cls");
					break;
				}
				else
				{
					system("color F4");
					cout << "\n指令输入错误,请重新输入...\n\n";
					Sleep(500);
					system("color F0");
				}
			}
		}
		else if(instruction_2 == "2")
		{
			bo.return_book(log);//还书函数
			bo.save_1();//保存信息函数(书籍信息)
			system("cls");
			continue;
		}
		else if(instruction_2 == "3")
		{
			bo.showbook_1();//展示函数(剩余的) 
			system("cls");
			continue;
		}
		else if(instruction_2 == "4")
		{
			bo.change_message(log);//更改信息函数
			system("cls");
			continue;
		}
		else if(instruction_2 == "5")
		{
			bo.free_space();
			exit(0);
		}
		else
		{
			system("color F4");
			cout << "\n指令输入错误,请重新输入...";
			Sleep(500);
			system("cls");
		}
	}
}

//SAO------------------------------------------不同人员的函数------------------------------------------------------------OAS 
void book::Determinefile_4()
{
	p_b->next_b;
	while(p_b->next_b)//判断输入的信息是否已经被使用 
	{
		if(p_b->next_b->bookname == "")
		{
			break;
		}
		p_b = p_b->next_b;
		if(p_b->bookname == bookname)
		{
			system("color F4");
			cout << "\n\n此书名已存在!!!\n" << endl;
			cout << "\n\n按任意键返回主菜单..." << endl;
			getchar();
			getchar();
			return;
		}
		if(p_b->bookid == bookid)
		{
			system("color F4");
			cout << "\n\n此编号已存在!!!\n" << endl;
			cout << "\n\n按任意键返回主菜单..." << endl;
			getchar();
			getchar();
			return;
		}
	}
	ofstream out;
	out.open("E:\\文本夹\\图书借阅管理\\图书借阅管理-书籍信息.txt",ios::app);
	if(!out)
	{
		system("color F4");
		cout << "创建文件失败!!!" << endl;
		exit(0);
	}
	out << endl << bookname;
	out << "   " << author;
	out << "   " << bookid;
	out << "   " << price;
	out << "   " << "left";
	out << "   " << "###";
	out << "   " << "###";
	out << "   " << "###";
	out.close();
	system("color F2");
	cout << "\n创建成功!!!" << endl << "\n按任意键继续..." << endl;
	getchar();
	getchar();
	system("cls");
	system("color F0");
	return;
}

void book::add_book()
{
	cout << "\n请输入想要增加的书籍的信息:" << endl;
	string bookname_,bookid_,author_,price_;
	cout << "书籍名称:";
	cin >> bookname_;
	bookname = bookname_;
	cout << "书籍作者:";
	cin >> author_;
	author = author_;
	cout << "书籍编号:";
	cin >> bookid_;
	bookid = bookid_;
	cout << "书籍价格:";
	cin >> price_;
	price = price_;
	return;
}

void book::showbook_2()
{
	system("color F1");
	cout << "\n借出的书籍信息如下:" << endl;
	cout << "※书名※\t※作者※   ※价格※   ※书籍编号※||※姓名※||※性别※||※学号※" << endl;
	p_b = head_b;
	while(p_b->next_b)
	{
		if(p_b->next_b->bookname == "")
		{
			break;
		}
		p_b = p_b->next_b;
		if(p_b->state == "none")
		{
			cout << p_b->bookname << "    " << p_b->author << "     " << p_b->price << "         " << p_b->bookid;
			cout << "     " << p_b->message_name << "     " << p_b->message_sex << "      " << p_b->message_id << endl;
		}
	}
	cout << "\n\n按任意键返回主菜单..." << endl;
	getchar();
	getchar();
	return;
}

void book::change_book()
{
	cout << "\n请输入您想要更改的书籍的名称或者编号:";
	string change;
	cin >> change;
	cout << "\n请输入更改后的书籍信息:" << endl;
	string a,b,c,d;
	cout << "书籍名称:";
	cin >> a;
	cout << "书籍作者:";
	cin >> b;
	cout << "书籍编号:";
	cin >> c;
	cout << "书籍价格:";
	cin >> d;
	bool Q = false;
	p_b = head_b;
	while(p_b->next_b)
	{
		if(p_b->next_b->bookname == "")
		{
			break;
		}
		p_b = p_b->next_b;
		if(p_b->bookname == change || p_b->bookid == change)
		{
			p_b->bookname = a;
			p_b->author = b;
			p_b->bookid = c;
			p_b->price = d;
			Q = true;
			break;
		}
	}
	if(Q == false)
	{
		system("color F4");
		cout << "\n\n输入的信息有误!!!\n数据库中无此书籍信息..." << endl;
		cout << "\n\n按任意键返回主菜单..." << endl;
		getchar();
		getchar();
	}
	return;
} 

void book::delete_book()
{
	cout << "\n请输入您想要删除的书籍的名称或者编号:";
	string delete_book;
	cin >> delete_book;
	bool K = false; 
	p_b = head_b;
	book *q;
	q = new book;
	q = head_b->next_b;
	while(p_b->next_b)
	{
		if(p_b->next_b->bookname == "")
		{
			break;
		}
		if(q->bookname == delete_book || q->bookid == delete_book)//删除尾节点有问题 
		{
			if(q->next_b->bookname == q->bookname || q->next_b == NULL)
			{
				p_b->next_b = NULL;
				free(q);
				K = true;
				break;
			}
			p_b->next_b = q->next_b;
			free(q);
			K = true;
			break;
		}
		p_b = p_b->next_b;
		q = q->next_b;
	}
	if(K == false)
	{
		system("color F4");
		cout << "\n\n输入的信息有误!!!\n数据库中无此书籍信息..." << endl;
		cout << "\n\n按任意键返回主菜单..." << endl;
		getchar();
		getchar();
	}
	return;
}

void main_system_2()
{
	string instruction_3;//输入指令
	book boo;
	boo.apply_space_b();
	while(1)//死循环 
	{
		system("color F0");
		boo.Determinefile_3(1);//每次操作前都遍历一次,将信息存入链表 
		cout << " \t------------------------------------------------------------" << endl;
		cout << " \t|                     【图书操作系统】                     |" << endl;
		cout << " \t|                                                          |" << endl;
		cout << " \t|                                              -->管理员<--|" << endl;
		cout << " \t|                                                          |" << endl;
		cout << " \t|                      の 1.增加书籍                       |" << endl;
		cout << " \t|                      の 2.更改书籍信息                   |" << endl;
		cout << " \t|                      の 3.删除书籍信息                   |" << endl;
		cout << " \t|                      の 4.查询借出书籍                   |" << endl;
		cout << " \t|                      の 5.查询剩余书籍                   |" << endl;
		cout << " \t|                      の 6.退出系统                       |" << endl;
		cout << " \t------------------------------------------------------------" << endl;
		cout << "您的操作为:";
		cin >> instruction_3;
		if(instruction_3 == "1")
		{
			boo.add_book();//输入信息 
			boo.Determinefile_4();//将增加的信息存入链表 
			system("cls");
			continue;
		}
		else if(instruction_3 == "2")
		{
			boo.change_book();//对链表进行操作 
			boo.save_1();//存入文件 
			system("cls");
			continue;
		}
		else if(instruction_3 == "3")
		{
			boo.delete_book();//对链表进行操作 
			boo.save_1();//存入文件 
			system("cls");
			continue;
		}
		else if(instruction_3 == "4")
		{
			boo.showbook_2();//none 
			system("cls");
			continue;
		}
		else if(instruction_3 == "5")
		{
			boo.showbook_1();//left
			system("cls");
			continue;
		}
		else if(instruction_3 == "6")
		{
			boo.free_space(); 
			exit(0);
		}
		else
		{
			system("color F4");
			cout << "指令输入错误,请重新输入...";
			Sleep(500);
			system("cls");
		}
	}
}

int main()
{
	login_in();
	return 0;
}

认真看,一定会有收获—小哥寄语。

猜你喜欢

转载自blog.csdn.net/qq_43624878/article/details/86032008
今日推荐