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