64,654
社区成员
发帖
与我相关
我的任务
分享
class Book {
private:
char name[100];
long long ISBN;
int id;
int state;
char reader[50];
Date borrow_date;
int borrow_time;
Date repay_date;
public:
Book* last;
Book* next;
Book(const char* bookname, long long isbn);
Book();
int borrow(Person* reader, int time);
int repay();
char* show_book_name();
long long show_book_ISBN();
int show_book_state();
string show_borrow_person();
int show_book_id();
Date show_repay_date();
bool is_exceed_limit();
void modify(string s, int a);
void modify(string s, char* a);
void modify(string s, Date a);
void modify(string s, long long a);
};
void save_book()
{
ofstream out("book.dat", ios::out);
if (out.is_open()) {
out.write((char*)&book_count, sizeof(int));
out.write((char*)&book_last_id, sizeof(int));
Book* p = book_head;
for (int i = 0; i < book_count; i++) {
out.write((char*)p, sizeof(Book));
p = p->next;
}
out.close();
}
else {
cout << "Book信息保存错误。" << endl;
system("PAUSE");
}
}
ifstream b("book.dat", ios::_Noreplace | ios::binary);
if (b.is_open()) {
Book* last = nullptr;
b.read((char*)&book_count, sizeof(int));
b.read((char*)&book_last_id, sizeof(int));
for (int i = 0; i < book_count; i++) {
Book* p = new Book;
b.read((char*)p, sizeof(Book));
p->next = nullptr;
if (book_head == nullptr) {
book_head = p;
p->last = nullptr;
last = p;
}
else {
p->last = last;
last->next = p;
last = p;
}
}
last_book = last;
b.close();
}