图书管理系统——C++实现

这是一个使用C++编写的图书管理系统,不依赖数据库,通过头文件Book.h和Book.cpp实现。用户可以按照提示进行操作,提供了源码下载链接。
摘要由CSDN通过智能技术生成

Book.h头文件

#pragma once
#define NUM1 128
#define NUM2 50
#define Col 80
#define Line 25
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
using namespace std;

class Book {
public:
	Book() {}
	Book(char* bookno,char* Name, char* lsbn, char* Price, char* Author,char* time,char* banci);
	~Book() {}
public:
	char* Getbookno();
	void Setbookno(char *bookno);
	char* GetName();
	void SetName(char *Name);
	char* Getlsbn();
	void Setlsbn(char* lsbn);
	char* GetPrice();
	void SetPrice(char* Price);
	char* GetAuthor();
	void SetAuthor(char* Author);
	char* Gettime();
	void Settime(char* time);
	char* Getbanci();
	void Setbanci(char* banci);
	virtual void WriteData();
	virtual void DeleteData(int count);
	void GetBookFromFile(int count);
	char m_bookno[NUM2];
protected:
	char m_Name[NUM1];
	char m_lsbn[NUM1];
	char m_Price[NUM2];
	char m_Author[NUM2];
	char m_time[NUM1];
	char m_banci[NUM1];
};

class Reader {
public:
	Reader() {}
	Reader(char* Name, char* age, char* sex, char* No, char* address);
	~Reader() {}
public:
	char* GetName();
	void SetName(char *Name);
	char* Getage();
	void Setage(char* age);
	char* Getsex();
	void Setsex(char* sex);
	char* GetNo();
	void SetNo(char* No);
	char* Getaddress();
	void Setaddress(char* address);
	virtual void WriteData();
	virtual void DeleteData(int count);
	void GetReaderFromFile(int count);
protected:
	char n_Name[NUM1];
	char n_age[NUM1];
	char n_sex[NUM2];
	char n_No[NUM2];
	char n_address[NUM2];
};

class Borrow {
public:
	Borrow() {}
	Borrow(char* bookno, char* readerno, char* outtime, char* intime);
	~Borrow() {}
public:
	char* Getbookno();
	void Setbookno(char *bookno);
	char* Getreaderno();
	void Setreaderno(char* readerno);
	char* Getouttime();
	void Setouttime(char* outtime);
	char* Getintime();
	void Setintime(char* intime);
	virtual void WriteData();
	virtual void DeleteData(int count);
	void GetBorrowFromFile(int count);
protected:
	char n_bookno[NUM2];
	char n_readerno[NUM2];
	char n_outtime[NUM2];
	char n_intime[NUM2];
};

void Wait() {
	int inputpage = 0;
	cout << "enter:返回主菜单       q:退出" << endl;
	char buf[256];
	gets_s(buf);
	if (buf[0] == 'q')
		system("exit");
}

void SetScreenGrid() {
	char sysSetBuf[80];
	sprintf(sysSetBuf, "mode con cols=%d lines=%d", Col, Line);
	system(sysSetBuf);
}

void SetSysCaption() {
	system("title Sample");
}

void ClearScreen() {
	system("cls");
}

void SetSysCaption(const char* Text) {
	char sysSetBuf[80];
	sprintf(sysSetBuf, "title %s", Text);
	system(sysSetBuf);
}

void ShowWelcome() {
	for (int i = 0; i < 2; i++) {
		cout << endl;
	}
	cout << setw(40);
	cout << "**************" << endl;
	cout << setw(40);
	cout << "图书管理系统" << endl;
	cout << setw(40);
	cout << "**************" << endl;
}

void ShowMenu() {
	cout << setw(40);
	cout << "请选择功能:" << endl;
	cout << endl;
	cout << setw(38);
	cout << "1、添加新书" << endl;
	cout << endl;
	cout << setw(42);
	cout << "2、浏览图书信息" << endl;
	cout << endl;
	cout << setw(38);
	cout << "3、删除图书" << endl;
	cout << endl;
	cout << setw(38);
	cout << "4、添加读者" << endl;
	cout << endl;
	cout << setw(42);
	cout << "5、浏览读者信息" << endl;
	cout << endl;
	cout << setw(38);
	cout << "6、删除读者" << endl;
	cout << endl;
	cout << setw(42);
	cout << "7、添加借阅信息" << endl;
	cout << endl;
	cout << setw(42);
	cout << "8、浏览借阅信息" << endl;
	cout << endl;
	cout << setw(42);
	cout << "9、删除借阅信息" << endl;
}

int GetSelect() {
	char buf[256];
	gets_s(buf);
	return atoi(buf);
}


Book.cpp

#include "Book.h"
#include<string>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
using namespace std;

Book::Book(char* bookno,char* Name, char* lsbn, char* Price, char* Author, char* time, char* banci) {
	strncpy(m_bookno, bookno, NUM2);
	strncpy(m_Name, Name, NUM1);
	strncpy(m_lsbn, lsbn, NUM1);
	strncpy(m_Price, Price, NUM2);
	strncpy(m_Author, Author, NUM2);
	strncpy(m_time, time, NUM1);
	strncpy(m_banci, banci, NUM1);
}

char* Book::Getbookno() {
	return m_bookno;
}
void Book::Setbookno(char* bookno) {
	strncpy(m_bookno, bookno, NUM2);
}

char* Book::GetName() {
	return m_Name;
}
void Book::SetName(char* Name) {
	strncpy(m_Name, Name, NUM1);
}

char* Book::Getlsbn() {
	return m_lsbn;
}
void Book::Setlsbn(char* lsbn) {
	strncpy(m_lsbn, lsbn, NUM1);
}

char* Book::GetPrice() {
	return m_Price;
}
void Book::SetPrice(char* Price) {
	strncpy(m_Price, Price, NUM2);
}

char* Book::GetAuthor() {
	return m_Author;
}
void  Book::SetAuthor(char* Author) {
	strncpy(m_Author, Author, NUM2);
}

char* Book::Gettime() {
	return m_time;
}
void Book::Settime(char* time) {
	strncpy(m_time, time, NUM1);
}

char* Book::Getbanci() {
	return m_banci;
}
void Book::Setbanci(char* banci) {
	strncpy(m_banci, banci, NUM1);
}

void Book::WriteData() {
	ofstream file;
	file.open("F://book.dat", ios::binary | ios::app);
	try {
		file.write(m_bookno, NUM2);
		file.write(m_Name, NUM1);
		file.write(m_lsbn, NUM1);
		file.write(m_Price, NUM2);
		file.write(m_Author, NUM2);
		file.write(m_time, NUM1);
		file.write(m_banci, NUM1);
	}
	catch (...) {
		throw "file error occurred";
		file.close();
	}
	file.close();
}

void Book::GetBookFromFile(int count) {
	char bookno[NUM2];
	ch
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值