readerhistory.h

来自「图书馆是一个拥有许多图书并面向学生的一个机构」· C头文件 代码 · 共 57 行

H
57
字号
#ifndef READERHISTORY_H
#define READERHISTORY_H

#include<fstream.h>
class readerhistory
{
public:
	void save(char *a , bool b , book c )//保存读者的借阅历史
	{
		strcpy(number,a);
		bo = c ;
		condition = b ;
		fstream f( "d:\\history.dat" , ios::binary|ios::in|ios::out ) ;
		f.seekg( 0, ios::end ) ;	// 读指针移到文件末尾
		f.write( (char *) & (*this) , sizeof(*this) ) ;	// 写入文件
	}

	void print()
	{
		int sg = 0 ;//标志
		char key[10] ;
		fstream f( "d:\\history.dat" , ios::binary|ios::in|ios::out ) ;
		f.seekg( 0, ios::end ) ;	// 读指针移到文件末尾
	    long posEnd = f.tellg() ;	// 记录文件尾位置
		f.seekp( 0, ios::beg ) ;		// 读指针移到文件开始

		cout << "请输入你要查询的帐号: " ;
		cin >> key ;
		do 
		{ 
			f.read((char *) & (*this) , sizeof(*this)) ;
		
			if( !strcmp(number,key) )
			{
				sg = 1 ;
				cout << "读者帐号为: " << number << endl ;
				cout << "图书编号为: " << bo.getcode() << endl ;
				cout << "图书名称为: " << bo.getname() << endl ;
				cout << "该图书" ;
				if( condition == false )
					cout << "已还!" << endl ;
				else
					cout << "未还!" << endl ;
			}
		}  while ( f.tellg() != posEnd ) ; //遍历查找

		if( !sg )
			cout << "没有该读者借阅信息!" << endl ;

	}
private:
	char number[10] ;
	book bo ;
	bool condition ;
} ;
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?