Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
84
Добавлен:
10.12.2013
Размер:
4.07 Кб
Скачать
#include "Class.h"
BIBL::BIBL()
{
	name = "Неизвестен";
	autor = "Неизвестен";
	price=0;
}
//-----------------------------------------------------------------------
BIBL::BIBL(string Name,string Autor,float Price)
{
	name = Name;
	autor = Autor;
	price = Price;
}
//-----------------------------------------------------------------------
BIBL::BIBL(const BIBL& a)
{
	name = a.name;
	autor = a.autor;
	price = a.price;
}
//-----------------------------------------------------------------------
string BIBL::GetAutor() {return autor;}
int BIBL::GetPrice() {return price;}
//-----------------------------------------------------------------------
void BIBL::Show()
{
	Rus("Название : "); cout<<name<<endl;
	Rus("Автор : ");cout<<autor<<endl;
	Rus("Цена : ");cout<<price<<endl;
}
//-----------------------------------------------------------------------
istream& operator>>(istream& in, BIBL& B)
{
	char name[30],autor[30];
	in.read(name,30);
	B.name = name;
	in.read(autor,30);
	B.autor = autor;
	in.read((char*)&B.price,4);
	return in;
}
//-----------------------------------------------------------------------
ostream& operator<<(ostream& out,BIBL& B)
{
	out<<B.name<<endl;
	out<<B.autor<<endl;
	out<<B.price<<endl;	
	return out;
}

BIBL& BIBL::operator =(const BIBL& b)
{
	if(this==&b) return *this; 
	name = b.name;
	autor = b.autor;
	price = b.price;
	return *this;
}
//-----------------------------------------------------------------------
bool BIBL::operator <(const BIBL& b)
{
	if(name < b.name) return true;
	else return false;
}
//-----------------------------------------------------------------------
bool BIBL::operator ==(const BIBL& b)
{
	if(name == b.name) return true;
	else return false;
}
//-----------------------------------------------------------------------
void Remove_copy_if(db& d,sb& s,comp_price p)
{
	BIBL b;
	iter j;
	j=d.begin();
	while(j!=d.end())
	{
		if(p(*j))
		{
			s.push(*j);
			d.erase(j);
		}
		j++;
	}
}
//-----------------------------------------------------------------------
void PrintDeque(string str,db d)
{
	deque<BIBL>::iterator p = d.begin();
	cout<<Rus(str)<<endl;
	if(d.empty())
		Rus("\nОчередь пуста\n");
	else
		for(;p!=d.end();p++)
			cout<<*p<<endl;
}
//-----------------------------------------------------------------------
void PrintStack(string str,sb s)
{
	deque<BIBL> d;
	deque<BIBL>::iterator p = d.begin();
	cout<<Rus(str)<<endl;
	while(!s.empty())
	{
		cout<<s.top()<<endl;
		s.pop();
	}
}
//-----------------------------------------------------------------------
void Sort(sb& s)
{
	deque<BIBL> d;
	while(!s.empty())
	{
		d.push_back(s.top());
		s.pop();
	}
	sort(d.begin(),d.end(),comp_grater());
	for(int i=0;i<d.size();i++)
		s.push(d[i]);
}
//-----------------------------------------------------------------------
string Rus(string Str)
{
	unsigned char c;
	for(int i=0;i<Str.size();i++)
	{
		c=Str[i];
		if(c>127)
		{
			if(c<240) c-=64;
			else     c-=16;
		}
		Str[i]=c;
	}
	return Str;
}
//-----------------------------------------------------------------------
void AddOfFile(ifstream& in,db& d)
{
	in.seekg(0,ios::end);
	int Num=in.tellg()/64;
	in.seekg(0,ios::beg);
	BIBL b;	
	for(int i=0;i<Num;i++)
	{
		in>>b;
		d.push_back(b);
	}
}
//-----------------------------------------------------------------------
void FindAutor(db d,string s)
{
	cout<<Rus("\n***Книги с автором ")<<Rus(s)<<endl;
	iter j=d.begin();
	int i=0;
	while(j!=d.end())
	{
		j=find_if(d.begin(),d.end(),comp_autor(Rus(s)));
		if(j!=d.end())
		{
			cout<<*j<<endl;
			d.erase(j);
			i++;
		}		
	}
	if(i==0)
		cout<<Rus("\nТаких нет!\n");
}
//-----------------------------------------------------------------------
db Merge(db& Deq,sb& St)
{
	db temp,ret;
	while(!St.empty())
	{
		temp.push_back(St.top());
		St.pop();
	}
	ret.resize(Deq.size()+temp.size());
	merge(Deq.begin(),Deq.end(),temp.begin(),temp.end(),ret.begin());
	return ret;
}
Соседние файлы в папке Prog3