Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can someone please give me a code of this set theory? Using for statements and if-else statements. thank you in advance to the man or woman who will give me an answer.
Posted
Updated 1-Sep-11 0:53am
v3
Comments
LittleYellowBird 1-Sep-11 6:46am    
This looks rather like homework and if so you would learn far more if you researched it yourself. Also, for your information, not everyone here is a man!

1 solution

I assume you know/understand what each set operation does (they are not difficult concepts).

(just talking about technicality)
What kind of data structure are you using ? arrays ? STL collections ?

If you are using STL, there are operations already defined for those (for example set_symmetric_difference ).

ok, you are not using STL (or don't want to).

First, If I give you two bags of numbered balls ( like lottery balls ), can you simulate on paper how to do the different set operations ?

In code, for example, the union, the simplest operation is just adding the two sets, so, you will need to have 1 or 2 for loops to loop the 2 arrays to copy the elements from the arrays into a 3rd one (the result); if you need to have only unique items in the resulting set, then you will have a couple of if conditions to check if the item is already in the resulting array.

This should get you started.

Good luck ...

Max.
 
Share this answer
 
v2
Comments
Member 8204896 1-Sep-11 7:14am    
im using c++. and i am required to do this using for statements and if-else statements. i know it is possible to do. will you please help me?
Member 8204896 1-Sep-11 7:47am    
i forgot to mention i also use arrays
Stefan_Lang 1-Sep-11 8:35am    
Is it a requirement to use arrays? Just asking, because that is about the worst way to store a set, both for performance and for the effort to program the functions you want. Note that the standard template library (STL) already has a set type which would be perfect for this:
http://www.cplusplus.com/reference/stl/set/
Stefan_Lang 1-Sep-11 8:19am    
Note that it isn't actually required to know the set types, as long as you can define iterator types for them. std::sort() works like that. Ok, it also requires some kind of function object to construct the result set, so that would be clearly beyond the scope of homework ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900