⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reader.h

📁 图书馆是一个拥有许多图书并面向学生的一个机构
💻 H
字号:
#ifndef READER_H
#define READER_H

#include<fstream.h>
#include<string.h>
#include"readerhistory.h"
class reader
{	
public:	
	reader( char* a = " " , char *b =" " , char *c = " " )
	{
		strcpy(code,a) ;
	}
	void set()		//输入读者资料
	{
		cout<<"请输入读者帐号: ";
		cin>>code;
		cout<<"请输入读者姓名: ";
		cin>>name;
		cout<<"请输入帐号的密码: ";
		cin >> passward ;
	}
	char* getcode()
	{
		return code ;
	}
	char* getpassward()
	{
		return passward ;
	}
	void print()	//打印读者资料
	{
		cout<<"读者帐号: "<<code<<endl ;
		cout<<"读者姓名: "<<name<<endl ;
		cout<<"读者帐号密码: "<<passward<<endl ;
	}
	void save( fstream f ) //保存读者的信息在文本中
	{
		f.seekp( 0, ios::end ) ;		// 读指针移到文件末尾
		f.write( (char *) & (*this) , sizeof( *this ) ) ;	// 写入文件
	}
	void changemessage(fstream f)//修改读者自己的信息
	{
		reader one ;
		char key[10] ;
		f.seekg( 0, ios::end ) ;	// 读指针移到文件末尾
	    long posEnd = f.tellg() ;	// 记录文件尾位置
		f.seekp( 0, ios::beg ) ;		// 读指针移到文件开始
		cout << "请再次输入您的帐号: " ;
		cin >> key ;

		do { 
			f.read((char *) & one , sizeof(one)) ; 
		}  while ( strcmp(one.getcode(),key) && f.tellg() != posEnd ) ; //遍历查找该帐号的读者

		if ( !strcmp(one.getcode(),key) )
		{
			cout<<"您的帐号信息为:"<<endl ;
			one.print();
			cout<<"现在开始修改您的信息:"<<endl;
			one.set() ;
			f.seekp( -long( sizeof( one ) ), ios::cur );	// 指针复位
			f.write( (char *) & one , sizeof( one ) ) ;	// 重新写入文件
			cout << "您的帐号信息修改后为:" << endl ;
			one.print() ;
		}		 
		else
		{
			cout << "对不起,您的帐号输入有误!" << endl ;
		}
	}

	void checkbook(fstream f)//查询书的信息
	{
		book one ;
		int key ;
		f.seekg( 0, ios::end ) ;	// 读指针移到文件末尾
	    long posEnd = f.tellg() ;	// 记录文件尾位置
		f.seekp( 0, ios::beg ) ;		// 读指针移到文件开始
		cout << "请输入你要查询的书的编号: " ;
		cin >> key ;

		do { 
			f.read((char *) & one , sizeof(one)) ; 
		}  while ( one.getcode() != key && f.tellg() != posEnd ) ; //遍历查找书籍
         
		if( one.getcode() == key )
		{
			one.print() ;
		}
		else
			cout << "对不起,没有你所要查找的图书信息" << endl ;

	}
	void borrow(fstream f)//读者借书
	{
		readerhistory  history ;
		book one ;
		int key ;
		f.seekg( 0, ios::end ) ;	// 读指针移到文件末尾
	    long posEnd = f.tellg() ;	// 记录文件尾位置
		f.seekp( 0, ios::beg ) ;		// 读指针移到文件开始
		cout << "请输入你要借阅的书的编号: " ;
		cin >> key ;

		do { 
			f.read((char *) & one , sizeof(one)) ; 
		}  while ( one.getcode() != key && f.tellg() != posEnd ) ; //遍历查找图书
         
		if( one.getcode() == key )
		{
			one.print() ;
			if( one.getcondition() == true )
			{
				cout << "恭喜!该书成功借出!" << endl ;
				history.save(code,true,one);
				one.setcondition(false) ;
				f.seekp( -long( sizeof( one ) ), ios::cur );	// 指针复位
		    	f.write( (char *) & one , sizeof( one ) ) ;	// 重新写入文件
			}
		}
		else
			cout << "对不起,没有你所要借阅的图书信息" << endl ;


	}
	void back(fstream f)//读者还书
	{
		readerhistory  history ;
		book one ;
		int key ;
		f.seekg( 0, ios::end ) ;	// 读指针移到文件末尾
	    long posEnd = f.tellg() ;	// 记录文件尾位置
		f.seekp( 0, ios::beg ) ;		// 读指针移到文件开始
		cout << "请输入你所要还的书的编号: " ;
		cin >> key ;

		do { 
			f.read((char *) & one , sizeof(one)) ; 
		}  while ( one.getcode() != key && f.tellg() != posEnd ) ; //遍历查找图书

		if( one.getcondition() == false )
		{
			one.setcondition(true) ;
			history.save(code,false,one);
			f.seekp( -long( sizeof( one ) ), ios::cur );	// 指针复位
		   	f.write( (char *) & one , sizeof( one ) ) ;	// 重新写入文件
		}
		else
			cout << "对不起,你所要还的图书信息错误" << endl ;
	}

private:
	char code[10] ;		//读者帐号
	char name[10];		//读者姓名
	char passward[10] ; //读者帐号密码
};
#endif

⌨️ 快捷键说明

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