Answer to Question #205256 in C for Swetha

Question #205256

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.


1
Expert's answer
2021-06-10T13:35:00-0400
using namespace std;


#define TEAM_SIZE	11
#define BATSMAN	1
#define BOWLER	2
#define WK		3
#define ALL_ROUNDER	4


int *ptr;


void Union(int arr1[], int arr2[], int m, int n) 
{ 
  int i = 0, j = 0,UnionArray[m+n],u=0,r; 
  
  while (i < m && j < n) 
  { 
    if (arr1[i] < arr2[j]) 
       {UnionArray[u] = arr1[i++]; u++;}
      
    else if (arr2[j] < arr1[i]) 
       {UnionArray[u] = arr2[j++]; u++;}
    
    else
    { 
       i++; 
    } 
  } 
  
  while(i < m) 
       {*(ptr+u) = arr1[i++]; u++;}
  
  while(j < n) 
         {*(ptr+u) = arr2[j++]; u++;}


 
  while(i < m) 
       {UnionArray[u] = arr1[i++]; u++;}
  
  while(j < n) 
         {UnionArray[u] = arr2[j++]; u++;}


	cout<<"\n\n\t\tUnion of Teams\n";
	for(i=0;i<u-1;i++)
	{
		if(UnionArray[i]>0 && UnionArray[i]<5)
		{
			cout<<"\t"<<i+1<<"\t";
			if(UnionArray[i]==BATSMAN)		cout<<"Batsman      ";
			if(UnionArray[i]==BOWLER )		cout<<"BOWLER       ";
			if(UnionArray[i]==WK     )		cout<<"Wicket Keeper";
			if(UnionArray[i]==ALL_ROUNDER)	cout<<"All Rounder  ";
			cout<<"\n";
		}
	}
} 
  


main(void)
{
	int r,Sum=0,k;
	int Team_1[TEAM_SIZE] = {BATSMAN, BATSMAN, BATSMAN,     BATSMAN, WK         , ALL_ROUNDER, ALL_ROUNDER, BOWLER, BOWLER, BOWLER, BOWLER};
	int Team_2[TEAM_SIZE] = {BATSMAN, BATSMAN, ALL_ROUNDER, WK,      ALL_ROUNDER, ALL_ROUNDER, ALL_ROUNDER, BOWLER, BOWLER, BOWLER, BOWLER};
	int m=0,n=0,U,i;
	ptr=&U;
	cout<<"\n\t\tTeam-1\t\t\tTeam-2\n";
	for(r=0;r<TEAM_SIZE;r++)
	{
		cout<<"\t"<<r+1<<"\t";
		if(Team_1[r]==BATSMAN)		cout<<"Batsman      ";
		if(Team_1[r]==BOWLER )		cout<<"BOWLER       ";
		if(Team_1[r]==WK     )		cout<<"Wicket Keeper";
		if(Team_1[r]==ALL_ROUNDER)	cout<<"All Rounder  ";


		if(Team_2[r]==BATSMAN)		cout<<"\t\tBatsman      ";
		if(Team_2[r]==BOWLER )		cout<<"\t\tBOWLER       ";
		if(Team_2[r]==WK     )		cout<<"\t\tWicket Keeper";
		if(Team_2[r]==ALL_ROUNDER)	cout<<"\t\tAll Rounder  ";
		cout<<"\n";
	}


  cout<<"\n";
  Union(Team_1, Team_2, TEAM_SIZE, TEAM_SIZE); 


  return 0; 
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS