图书馆信息管理系统——》你说这是你的大作业?>>>C++项目实战

前言:你说这是你的大作业?>>>虽然看起来很简单,很普通,但它确实是大作业在这里插入图片描述
,你可以从中发现无限乐趣…
ヾ(◍°∇°◍)ノ゙——

【1】客户需求描述(题目描述):

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

【2】难点分析:

难点1️⃣(题目本身)

  • 最开始看到这个作业时,我是很不以为然的,毕竟都是提前自学过的了( •̀ ω •́ )✧,可——

  • 我还是太弱小了ಥ_ಥ

  • 看看这变态需求

  • 1:支持大数据,比如书籍记录突破百万,用户数量突破万级规模

  • 2:搜索时性能考察,调查、思考、设计加强搜索性能的方式

  • 3.样本数据

在这里插入图片描述

难点2️⃣(卷神同学)

  • 同学A😎:我要用Qt,做一个。

很多同学不知道Qt是什么,这里简单地介绍一下。
在这里插入图片描述> < 这是Qt的软件
这:你可以在Codeblock看到它
在这里插入图片描述
这是简单的界面,他教我写的
在这里插入图片描述

还有…

  • 同学B😼:我要创个桌面程序!!!

可能还有朋友不知道C++怎么弄桌面应用
看这里——
在这里插入图片描述
`

  • 同学C😈:你们都在编程,我整个网页

他自学了前端,学了HTML,还参加过网页设计比赛
这是他发给我的软件
在这里插入图片描述
在这里插入图片描述

  • 同学D👻:mySQL选手

这个是我猜的≡(▔﹏▔)≡
学院那么大,来个学完数据库的同学,不过分吧》》》》
在这里插入图片描述
我都来不及装软件ヽ(≧□≦)ノ

在这里插入图片描述





【3】开始——

世界纵已内卷,编程不容躺平
在这里插入图片描述
编程必须强!!!💥🐉





【4】代码实现:

注:使用CB编写,VS需要重写时间函数
Libray(图书馆),Labray属拼写错误

1️⃣Labray.h

#ifndef LABRAY_H
#define LABRAY_H

#include<iostream>
#include<string>
#include<cstring>
#include<windows.h>
#include<functional>
#include<algorithm>
using namespace std;
#include<vector>
#include<ctime>
#include<unordered_map>
//----------------------------------引用的库
//界面美化
void toxy(int x, int y);    //将光标移动到X,Y坐标处
void SetColorAndBackground(int ForgC, int BackC);  //设置颜色
//----------------------
//-------图书类,管理员类,读者类的设定
class Book {
   
public:
	string Book_name;
	string IBSN;
	string writer;
	string classify;
    int cur_num;
	Book() {
   }
	Book(string n,string i,string w,string c,int num):Book_name(n),IBSN(i),writer(w),classify(c),cur_num(num){
   }
};
class Administrator
{
   
	friend class Labray;
public:
	string a_account;
	string a_code;
	Administrator() {
   };
	Administrator(string account, string code) :a_account(account), a_code(code) {
   }
};
class User
{
   
	friend class Labray;
public:
	string u_account;
	string u_code;
	unordered_map<string,int>u_memo;
	unordered_map<string,int>u_back_memo;
	User(){
   };
	User(string account, string code) :u_account(account), u_code(code) {
   }
};
//-------
//------------------------------
class Labray
{
   
private:
	unordered_map<string, Administrator>Admins;//用哈希表查找,更加快
	unordered_map<string, User>Users;
	vector<Book>tmbook;
	vector<string>Borrow_memo;
    vector<string>Back_memo;
	string Landed_accout="0";//C++11标准,可直接这样初始化用,这里使用是为了后面的部分操作
	//---------------------------
	void init_book();
	void init_Admin();
	void init_User();
	void init_Borrow_memo();
	void init_Back_memo();
	void Save_Book();
	void Save_Admins();
	void Save_Users();
	void Save_Borrow_memo();
	void Save_Back_memo();
	//----------------------
    void Search_thebook();
	void myover(); //强制退出
	//---------------------
	void AdminStart();
	void UserStart();
	string getCur_time();
public:
	Labray();
	void Landing();
};
#endif // LABRAY_H

2️⃣Labray.cpp

#include "Labray.h"
#include<windows.h>
#include<fstream>
constexpr auto Bookfile = "H_books.txt";
constexpr auto Adminfile = "Admins.txt";
constexpr auto Usersfile = "users.txt";
constexpr auto Borrowfile="Borrow_memo.txt";
constexpr auto Backfile="Back_memo.txt";

//----------------------------------辅助函数,帮助查找
class help_find{
   //,辅助find_if查找,无需泛型编程,就不用写模板
private:
    string name; //你可以用适配器,只要你能正确匹配函数即可
public:
    help_find(string t_name):name(t_name){
   };
	bool operator()(const Book& book) {
   
		if (book.Book_name == name)return true;
		else return false;
	}
};
int str_to_num(string str){
   
    int jie=0;
for(int i=0;i<str.size();i++){
   
   jie=jie*10+(str[i]-'0');
}
return jie;
}
//-----------------------------------------------------设置
void SetColorAndBackground(int ForgC, int BackC) {
   
	WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}


void toxy(int x, int y)      //将光标移动到X,Y坐标处
{
   
	COORD pos = {
    x , y };
	HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(Out, pos);
return ;
}
//对界面设置函数的定义,这两个函数,记住就行了,现阶段不要求理解
//----------------------------------------------------
//--获取时间
string Labray::getCur_time(){
   
	time_t t;    //typedef long time_t;
	time(&t);    //获取系统时间
	char* str = ctime(&t);  //将时间t转换为字符串
	return str;
}
//-------------------关键的构造函数,初始化
Labray::Labray(){
   
	ifstream ifs1;
	ifs1.open(Bookfile, ios::in);
	if (!ifs1.is_open()) {
   //情况一:文件未创建,即文件不存在
			//初始化属性
		cout << "-----------------------------------------------------" << endl;
		cout << "提示:--!!!图书信息文件未创建,运行系统可自动生成文件!!! --" << endl;
		cout << "-----------------------------------------------------" << endl;
		ifs1.close();
		return;
	}
	//2.文件存在,但数据为空
	char ch;
	ifs1 >> ch;
	if (ifs1.eof()) {
   
		cout << "--------------------------------------------------------" << endl;
		cout << "提示:--!!!图书馆尚无存书,等待管理员添加图书!!!--" << endl;
		cout << "--------------------------------------------------------" << endl;
		ifs1.close();
		return;
	}
	//图书馆有图书,我们需要把文件中的图书信息读到程序中
	ifs1.close();
	this->init_book();
	this->init_Admin();
	this->init_User();
	this->init_Borrow_memo();
	this->init_Back_memo();
	SetColorAndBackground(1,0);
	cout << "-------------------------   " << endl;
	cout << "[H]系统现有【用户人数】为:" << this->Users.size() << endl;
	cout << "[H]系统现有【管理员人数】为:" << this->Admins.size() << endl;
    cout << "[H]系统现有【图书种类】为:" << this->tmbook.size() << endl;
	cout << "-------------------------   " << endl;
	SetColorAndBackground(7,0);
	cout << endl;
}
//---------------------
void Labray:: Save_Book() {
   
	//保存图书文件
		ofstream ofs;
		ofs.open(Bookfile, ios::out);//写文件
		//将每个人的数据写入文件中
		for (int i = 0; i < this->tmbook.size(); i++) {
   
			ofs << this->tmbook[i].Book_name << ' '
				<< this->tmbook[i].IBSN << ' '
				<< this->tmbook[i].writer<<' '<<
				this->tmbook[i].classify <<' '<<this->tmbook[i].cur_num<<endl;
		}
		ofs.close();
		return;
}
void Labray::Save_Admins() {
   
	ofstream ofs;
	ofs.open(Adminfile, ios::out);//写文件
	//将每个人的数据写入文件中
	for (pair<string,Administrator> it:this->Admins) {
   
		ofs << it.second.a_account << ' '
			<< it.second.a_code<< endl;
	}
	ofs.close();
	return;
}
void Labray::Save_Users() {
   
	ofstream ofs;
	ofs.open(Usersfile, ios::out);//写文件
	//将每个人的数据写入文件中
	for (pair<string, User> it : this->Users) {
   
		ofs << it.second.u_account << ' '
			<< it.second.u_code << endl;
	}
	ofs.close();
	return;
}
void Labray::Save_Borrow_memo(){
   
    ofstream ofs;
    ofs.open(Borrowfile,ios::out);
    //写入借阅记录
    for(string it:this->Borrow_memo){
   
        ofs<<it<<endl;
    }
    ofs.close();
    return;
}
void Labray::Save_Back_memo(){
   
    ofstream ofs;
    ofs.open(Backfile,ios::out);
    //写入借阅记录
    for(string it:this->Back_memo){
   
        ofs<<it<<endl;
    }
    ofs.close();
    return;
}
void  Labray::init_book() {
   
	ifstream ifs;
	ifs.open(Bookfile, ios::in);
	string name;
	string IBSN;
	string writer;
	string classify;
	string tmp_cur_num;
	while (ifs >>name && ifs >>IBSN && ifs >>writer && ifs >>classify && ifs >>tmp_cur_num) {
   
        int cur_num=str_to_num(tmp_cur_num);
        Book tmp(name,IBSN,writer,classify,cur_num);
		this->tmbook.push_back(tmp);
	}
	ifs.close();
	return;
}
void Labray::init_Admin() {
   
	ifstream ifs;
	ifs.open(Adminfile, ios::in);
	string account, code;
	while (ifs >> account && ifs >>code) {
   
        Administrator tmp(account,code);
		this->Admins[tmp.a_account]=tmp;
	}
	ifs.close();
	if(this->Admins.empty()){
   
        Administrator tmp("20220101","123456");
        this->Admins["20220101"]=tmp;//添加默认管理员
        this->Save_Admins();
	}
	return;
}
void Labray::init_User() {
   
	ifstream ifs;
	ifs.open(Usersfile, ios::in);
	string account;
	string code;
	while (ifs >> account && ifs >> code) {
   
		User tmp(account,code);
		this->Users[tmp.u_account] = tmp;
	}
	ifs.close();
	return;
}
void Labray::init_Borrow_memo() {
   
	ifstream ifs;
	ifs.open(Borrowfile, ios::in);
	string informantion;
	while (getline(ifs,informantion)) {
   
      this
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

0<Solving)1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值