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

📄 administrator.h

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

#include<fstream.h>
#include<string.h>
#include"book.h"
#include"reader.h"

class administrator
{
public:
	void set()		//输入管理员资料
	{
		cout<<"请输入管理员帐号:";
		cin>>code;
		cout<<"请输入管理员姓名:";
		cin>>name;
		cout<<"请输入管理员密码:" ;
		cin >> passward ;
	}
	void save( fstream f )//保存管理员的信息在文本中
	{
		f.seekp( 0, ios::end ) ;		// 读指针移到文件末尾
		f.write( (char *) & (*this) , sizeof( *this ) ) ;	// 写入文件
	}
	char* getcode()
	{
		return code ;
	}
	char* getpassward()
	{
		return passward ;
	}
	void append( fstream f ) //图书的入库
	{ 	
		book one ; 
		int choice ;	
		f.seekp( 0, ios::end ) ;		// 读指针移到文件末尾
		
		cout << "------------------------------------新书入库登记--------------------------------\n" ;
		while (1)
		{ 
			cout<<" 1.新书号\n"
				<<" 0.退出\n" ;
			cout << "请键入操作选择:"<<endl ;
				cin >> choice ;
			switch( choice )
			{
			case 1:
				one.set() ;
				f.write( (char *) & one , sizeof( one ) ) ;	// 写入文件
				break ;
			case 0:
				return ;
			}	
		}
	} 

	void checkreader(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();
		}		 
		else
		{
			cout << "对不起,没有该帐号的用户!" << endl ;
		}
	}
	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 print()	//打印管理员资料
	{
		cout<<"管理员帐号: "<<code<<endl;
		cout<<"管理员姓名: "<<name<<endl;
		cout<<"管理员帐号密码: "<<passward << endl;
	}
private:
	char code[10] ;		//管理员帐号
	char name[10];		//管理员姓名
	char passward[10] ; //管理员帐号密码
} ;
#endif

⌨️ 快捷键说明

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