In a cricket game, the two teams A and B have different characteristics of players in terms of batsman and bowler. Find similar characteristics of player using union operations. Write a program for set operations using pointers.
#include<iostream>
using namespace std;
#define NUMBER_OF_PLAYERS 11
int BATSMAN = 1;
int BOWLER = 2;
int WK = 3;
int ALL_ROUNDER = 4;
int *pointer_for_sets;
void Union_Of_sets(int first_array[], int second_array[], int x, int y)
{
int a = 0, f = 0,final_union[x+y],n=0,r;
while (a< x && f< y)
{
if (first_array[a] < second_array[f])
{final_union[n] = first_array[a++]; n++;}
else if (second_array[f] < first_array[a])
{final_union[n] = second_array[f++]; n++;}
else
{
a++;
}
}
while(a < x)
{*(pointer_for_sets+n) = first_array[a++]; n++;}
while(f < y)
{*(pointer_for_sets+n) = second_array[f++]; n++;}
while(a < x)
{final_union[n] = first_array[a++]; n++;}
while(f < y)
{final_union[n] = second_array[f++]; n++;}
cout<<"\n\n\t\tTeam Union\n";
for(a=0;a<n-1;a++)
{
if(final_union[a]>0 && final_union[a]<5)
{
cout<<"\t"<<a+1<<"\t";
if(final_union[a]==BATSMAN) cout<<"Batsman ";
//DISPLAYING BOWLER
if(final_union[a]==BOWLER ) cout<<"BOWLER ";
if(final_union[a]==WK ) cout<<"Wicket Keeper";
if(final_union[a]==ALL_ROUNDER) cout<<"All Rounder ";
cout<<"\n";
}
}
}
int main()
{
int j,Sum=0,k;
int first_team[NUMBER_OF_PLAYERS] = {BATSMAN, BATSMAN, BATSMAN, BATSMAN, WK , ALL_ROUNDER, ALL_ROUNDER, BOWLER, BOWLER, BOWLER, BOWLER};
int second_team[NUMBER_OF_PLAYERS] = {BATSMAN, BATSMAN, ALL_ROUNDER, WK, ALL_ROUNDER, ALL_ROUNDER, ALL_ROUNDER, BOWLER, BOWLER, BOWLER, BOWLER};
int Z;
pointer_for_sets=&Z;
cout<<"\n\t\tFIRST TEAM\t\tSECOND TEAM\n";
for(j=0;j<NUMBER_OF_PLAYERS;j++)
{
cout<<"\t"<<j+1<<"\t";
if(first_team[j]==BATSMAN) cout<<"Batsman ";
if(first_team[j]==BOWLER ) cout<<"BOWLER ";
if(first_team[j]==WK ) cout<<"Wicket Keeper";
if(first_team[j]==ALL_ROUNDER) cout<<"All Rounder ";
if(second_team[j]==BATSMAN) cout<<"\t\tBatsman ";
if(second_team[j]==BOWLER ) cout<<"\t\tBOWLER ";
if(second_team[j]==WK ) cout<<"\t\tWicket Keeper";
if(second_team[j]==ALL_ROUNDER) cout<<"\t\tAll Rounder ";
cout<<"\n";
}
cout<<"\n";
Union_Of_sets(first_team, second_team, NUMBER_OF_PLAYERS, NUMBER_OF_PLAYERS);
return 0;
}
Comments
Leave a comment