Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
67
Добавлен:
10.12.2013
Размер:
3.75 Кб
Скачать
//Class.h
//------------------------------------------------------------------------
#ifndef CLASS
#define CLASS 1
#include <iostream.h>
#include <string.h>
//------------------------------------------------------------------------
template <class Stype> class Set
{
	Stype* beg;
	int len;
	int max_s;
public:
	
	Set();
	Set(int);
	~Set();
	Set(const Set&);

	void Insert (int,Stype*);
	void PrintStan();
	void PrintUser();	

	Set& operator=(const Set& );
	bool operator>(Set&);
	void operator-(Stype);
	bool operator!=(Set&);

	bool ToBe(Stype);
	
};
//------------------------------------------------------------------------
class BIBL
{
	char name[20]; 
	char autor[20];
	double price;
public:
	BIBL ();
	BIBL (char*,char*,double);
	BIBL (const BIBL&);
	~BIBL ();
	void Set(char*,char*,double);
	void Show();
	bool operator ==(BIBL);
	bool operator !=(BIBL);
};

//------------------------------------------------------------------------
template <class Stype> Set<Stype>::Set()
{	
	beg=new Stype [max_s=MAX];
	len=0;
}
//------------------------------------------------------------------------
template <class Stype> Set<Stype>::Set(int t)
{	
	max_s=t;
	beg=new Stype [max_s];
	len=0;
}
//------------------------------------------------------------------------
template <class Stype> Set<Stype>::~Set()
{	delete[] beg;	}

template <class Stype> Set<Stype>::Set(const Set& Obj)
{
	delete[] beg;
	len=Obj.len;
	beg=new Stype [len];
	for(int i=0;i<len;i++)
		beg[i]=Obj.beg[i];
}
//------------------------------------------------------------------------
template <class Stype> void Set<Stype>::Insert (int n,Stype* type)
{
	if(n>max_s) Rus(" Неверное кол-во элементов \n");
	else
	{
		len=n;
		for(int i=0;i<len;i++)
			beg[i]=type[i];
	}
}
//------------------------------------------------------------------------
template <class Stype> void Set<Stype>::PrintStan()
{
	if(!len) Rus("Пустое множество \n");
	else
	Rus(" Множество : ");cout<<endl;
	for(int i=0;i<len;i++)
		cout<<*(beg+i)<<endl;
}
//------------------------------------------------------------------------
template <class Stype> void Set<Stype>::PrintUser()
{
	if(!len) Rus("Пустое множество \n");
	else
	Rus(" Множество : ");cout<<endl;
	for(int i=0;i<len;i++)
		beg[i].Show();
}
//------------------------------------------------------------------------
template <class Stype> Set<Stype>& Set<Stype>::operator=(const Set& Obj)
{
	if(this==&Obj) return *this;
	delete[] beg;
	len=Obj.len;
	beg=new Stype [len];
	for(int i=0;i<len;i++)
		beg[i]=Obj.beg[i];
	return *this;
}
//------------------------------------------------------------------------
template <class Stype> bool Set<Stype>::operator>(Set& Obj)
{
	int Len=0;
	if(len<Obj.len) return false;
	for(int i=0;i<len;i++)
	{
		if(ToBe(Obj.beg[i])) Len++;
	}
	if (Len==Obj.len) return true;
	return false;
}
//------------------------------------------------------------------------
template <class Stype> void Set<Stype>::operator -(Stype c)
{
	int i,j=0;
	len-=1;
	Stype* t=new Stype[len];
	for(i=0;i<len+1;i++)
	{
		if(beg[i]!=c)
		{
			t[j]=beg[i];
			j++;
		}
	}
	delete[] beg;
	beg=t;
}
//------------------------------------------------------------------------
template <class Stype> bool Set<Stype>::operator!=(Set& Obj)
{
	if(len!=Obj.len) return true;
	for(int i=0;i<len;i++)
	{if(beg[i]!=Obj.beg[i]) return true;}
	return false;
}
//------------------------------------------------------------------------
template <class Stype> bool Set<Stype>::ToBe(Stype c)
{
	Stype* t=this->beg;
	for(int i=0;i<len;i++)
		if(t[i]==c) return true;
	return false;
}
#endif
Соседние файлы в папке Lab_6
  • #
    10.12.20133.75 Кб67Class.h
  • #
    10.12.20132 Кб67Fun.cpp
  • #
    10.12.20134.13 Кб68Lab_6.dsp
  • #
    10.12.2013535 б69Lab_6.dsw
  • #
    10.12.201366.56 Кб68Lab_6.ncb
  • #
    10.12.201349.66 Кб68Lab_6.opt