niedziela, 23 kwietnia 2017

C++ - set (class)

#pragma hdrstop
#pragma argsused

#ifdef _WIN32
#include <tchar.h>
#else
  typedef char _TCHAR;
  #define _tmain main
#endif

#include <stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;


class SET
{
private:
char *ascii_TABLE;
public:
SET()
{
ascii_TABLE=new char[256];
}
~SET()
{
delete ascii_TABLE;
}
void init_TABLE()
{
int i;
for(i=0;i<256;i++)
 ascii_TABLE[i]=0;
}
SET &operator +(char x)
{
ascii_TABLE[x]=1;
return *this;
}
SET &operator -(char x)
{
ascii_TABLE[x]=0;
return *this;
}
bool is_in_TABLE(char x)
{
if(ascii_TABLE[x]==1)
 return true;
else
 return false;
}
SET &Connect(SET Next)
{
int i;
for(i=0;i<256;i++)
 if(Next.is_in_TABLE(i))
  ascii_TABLE[i]=1;
return *this;
}
void Write_SET()
{
int i;
for(i=0;i<256;i++)
 if(ascii_TABLE[i]==1)
  printf("%c",(char)i);
 if(i==0)
  printf("Is empty\n");
 printf("\n");
}
};

 int _tmain(int argc, _TCHAR* argv[])
{
 SET new_Set1,new_Set2;
 new_Set1.init_TABLE();
 new_Set2.init_TABLE();
 new_Set1=new_Set1+'N';
 new_Set1=new_Set1+'e';
 new_Set1=new_Set1+'w';
 new_Set2=new_Set2+'Y';
 new_Set2=new_Set2+'o';
 new_Set2=new_Set2+'r';
 new_Set2=new_Set2+'k';
 new_Set1.Write_SET();
 new_Set2.Write_SET();
 new_Set1.Connect(new_Set2);
 new_Set1.Write_SET();
 new_Set1=new_Set1-'N';
 new_Set1=new_Set1-'e';
 new_Set1=new_Set1-'w';
 new_Set1.Write_SET();


 getch();
return 0;
}

Brak komentarzy:

Prześlij komentarz