GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Nov-2008, 08:22
khushal_kkk's Avatar
khushal_kkk khushal_kkk is offline
Awaiting Email Confirmation
 
Join Date: Mar 2008
Posts: 50
khushal_kkk is an unknown quantity at this point

Finding the Union, Intersection, Difference and Symmetric


Given Below is my code for finding the Union , Intersection , Difference and Symetric but every time when i run my program i gets the forllwing
Code:
Invalid Enteries either in A or in B

and i want this sentence to be executed when the values of AUB or A intersection B are not Present In Universal set .


CPP / C++ / C Code:
void main()
{
int i,j,temp;
 int u[10];
 int a[5];
 int b[5];
 int aw[10]={0};
 int bw[10]={0};
 //clrscr();
  cout<<"Programme for union,intersection,difference,symmetric difference"<<endl;
  cout<<"Enter the values of Universal set i.e set U:";
  for(i=0; i<10; i++)
  cin>>u[i];
  cout<<"\n\t  U:\t{ ";
  for(i=0; i<10; i++)
  cout<<u[i]<<",";
  cout<<"\b"<<" }"<<endl<<endl;

  cout<<"Enter the values of set A:";
  for(i=0; i<5; i++)
  cin>>a[i];
  cout<<"\n\t  A:\t{ ";
  for(i=0; i<5; i++)
  cout<<a[i]<<",";
  cout<<"\b"<<" }"<<endl<<endl;

  cout<<"Enter the values of set B:";
  for(i=0; i<5; i++)
  cin>>b[i];
  cout<<"\n\t  B:\t{ ";
  for(i=0; i<5; i++)
  cout<<b[i]<<",";
  cout<<"\b"<<" }"<<endl<<endl;
  for(i=0;i<10;i++)
       {
	if((a[i]!=u[i])||(b[i]!=u[i]))
	temp=1;
	if(temp==1)
	cout<<endl<<endl<<"Invalid Enteries either in A or in B"<<endl;
	else

      for(i=0;i<5;i++)
   {
     for(j=0;j<10;j++)
      {
	if(a[i]==u[j])
	aw[j]=1;
	if(b[i]==u[j])
	bw[j]=1;
      }
   }


cout<<"\n\n\n  AUB:\t{ ";
  for(i=0;i<10;i++)
  if(aw[i]==1||bw[i]==1)
  cout<<u[i]<<",";
  cout<<"\b"<<" }"<<endl<<endl;

cout<<"\n\n\n\n  AnB:\t{ ";
  for(i=0;i<10;i++)
  if(aw[i]==1&&bw[i]==1)
   cout<<u[i]<<",";
  cout<<"\b"<<" }"<<endl<<endl;

 cout<<"\n\n\n\n  A-B:\t{ ";
  for(i=0;i<10;i++)
	  if(aw[i]==1 && bw[i] != 1)
		  cout<<u[i]<<",";
	  cout<<"\b"<<" }"<<endl<<endl;

cout<<"\n\n\n\n AcB:\t{ ";
  for(i=0;i<5;i++)
       if(aw[i]!=1 || bw[i]!=1)
		  cout<<u[i]<<",";
	  cout<<"\b"<<" }"<<endl<<endl;
  getch();


}
}

please help me as soon as possible
  #2  
Old 13-Nov-2008, 00:52
andylee andylee is offline
New Member
 
Join Date: Nov 2008
Posts: 2
andylee is on a distinguished road

Re: Finding the Union, Intersection, Difference and Symmetric


I got to say than your code sucks.
I suggest you get Union of a and b to "a_b" firstly,
get Intersection of a and b to "a&b" secondly.
then check if the elements are Present In Universal set or not.
CPP / C++ / C Code:
int main()
{
	int a[ 5 ];
	int b[ 5 ];
	vector< int > c;
	int i = 0;
	for( i = 0; i < 5; ++i )
	{
		cin >> a[ i ];
	}
	for( i = 0; i < 5; ++i )
	{
		cin >> b[ i ];
	}
	sort( a, a + 5 );
	sort( b, b + 5 );
	set_intersection( a, a + 5, b, b + 5, back_inserter( c ) );
	cout << "intersection" << "\t" << endl ;
	for( i = 0; i < c.size(); ++i )
	{//intersection a&b
		cout << c[ i ] << "\t" ;
	}
	cout << endl;
	c.clear();
	set_union( a, a + 5, b, b + 5, back_inserter( c ) );
	cout << "union" << "\t" << endl ;
	for( i = 0; i < c.size(); ++i )
	{//union a+b
		cout << c[ i ] << "\t" ;
	}
	cout << endl;
	c.clear();
	set_difference( a, a + 5, b, b + 5, back_inserter( c ) );
	cout << "difference" << "\t" << endl ;
	for( i = 0; i < c.size(); ++i )
	{//difference : a-b
		cout << c[ i ] << "\t" ;
	}
	cout << endl;
	return 0;
}
  #3  
Old 13-Nov-2008, 00:53
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Finding the Union, Intersection, Difference and Symmetric


Well, first thing is your formatting -- you need to make your code clearer.

Next, void main() is just plain wrong.

Then,
CPP / C++ / C Code:
  cout<<"\n\t  A:\t{ ";
  for(i=0; i<5; i++)
  cout<<a[i]<<",";
  cout<<"\b"<<" }"<<endl<<endl;
is probably not a good idea. This might be a cleaner way to output a list (and with better code formatting):
CPP / C++ / C Code:
  cout << "\n\t  A:\t{ ";
  for (i = 0; i < 4; i++)
  {
      cout << a[i] << ",";
  }
  cout << a[4] << " }" << endl << endl;

Here's where the actual coding problem comes in:
CPP / C++ / C Code:
  for(i=0;i<10;i++)
       {
	if((a[i]!=u[i])||(b[i]!=u[i]))
What's the value of a[6]? Doesn't the array only contain 5 values (0-4)?

That might help you figure out why you're getting the error.


Quote:
Originally Posted by khushal_kkk
please help me as soon as possible
You've been here long enough to know this request is frowned upon.
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #4  
Old 13-Nov-2008, 23:09
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Finding the Union, Intersection, Difference and Symmetric


Quote:
Originally Posted by WaltP
Quote:
Originally Posted by khushal_kkk
please help me as soon as possible
You've been here long enough to know this request is frowned upon.
Seconded. Some would say rude too.
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
run script command on ns2.26 newbie06 Computer Software Forum - Linux 65 19-Aug-2009 08:50
Plz anyone help to fix the linking errors: dathatreya MS Visual C++ / MFC Forum 0 03-Apr-2008 01:19
Need urgent help. Nonsensical compile errors on test code (for game) seasons C++ Forum 1 29-Nov-2007 13:41
Compile Errors due to Default Parameters jdbrine C++ Forum 1 17-Jun-2006 15:45
Can somebody look at this and point out any errors to me soulfly C Programming Language 7 31-Mar-2004 10:45

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:09.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.