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

📄 books.cpp

📁 图书馆程序设计
💻 CPP
字号:
#include "books.h"
#include <fstream>
namespace jixia
{
	Books::Books()
	{ 
	  v.clear();
	}

	void Books::Open(char fname[])
	{ ifstream fin(fname);
      while( !fin.eof() )
	  { int x1; string x2,x3,x4;
		fin>>x1>>x2>>x3>>x4;
        Book b(x1,x2,x3,x4);
	    v.push_back(b); 
	  }
	}

	void Books::Save(char fname[])
	{
	   ofstream fout;fout.open(fname);
	   for(int i=0;i<v.size();i++)
		   fout<<v[i].ID<<"  "<<v[i].Name<<"  "<<v[i].Author<<"  "<<v[i].Price<<endl;
	}

	ostream& operator<<(ostream &o,Books &bs)
	{
	  for(int i=0;i<bs.v.size();i++)
		 o<<bs.v[i]<<endl;
	  return o;
	}

	void Books::Search(int ID)
	{
	 for(int i=0;i<v.size();i++)
		 if(v[i].ID==ID)
			 cout<<v[i];
	}

	void Books::Append(int ID1,string Name1,string Author1,string Price1)
	{  Book s(ID1,Name1,Author1,Price1);
		v.push_back(s);

	}


	
	void Books::Delete(int ID)
	{
	  for(int i=0; i<v.size()-1; i++)
        if(v[i].ID==ID)
			v.erase(v.begin()+i);
	}

}

⌨️ 快捷键说明

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