


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Practical No-1 Discrete mathematics
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



#include
#include
using namespace std;
class set {
int *arr;int cnt;int pos;
int n;
public:
set()
{
n=0;
arr=0;
}
void setsize();
void enterset();
void showset();
void uniqueset();
int cardinality();
bool member (int);
void powerset();
};
void set::setsize()
{
cout<<"\n\nenter the size or array :) : ";
cin>>n;
arr=new int [n];
}
void set ::enterset()
{
cout<<"\nenter elements of set:) : ";
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
}
void set::showset()
{
cout<<"\nentered set : ";
for(int i=0;i<n-1;i++)
{
cout<<arr[i]<<" ,";
}
cout<<arr[n-1];
}
void set::uniqueset()
{
int i,j;
int count = 1;
for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
{
if(arr[i] == arr[j] && i != j)
break;
}
if(j == n )
{
cout<<"\nNon repeating element :"<<arr[i];
++count;
}
}
}
int:: set::cardinality()
{
return n;
}
bool set::member(int num)
{
for(int i=0; i<n; i++)
{
if(arr[i]==num)
{
cnt=1;
pos=i+1;
break;
}
}
if(cnt==0)
{
cout<<"\n Element Not Found..!!";
}
else
{
cout<<"\n Element "<<num<<" Found At Position "<<pos;
}