Looking for MySet class examples

Hi there, Im trying to do kind of a project of sets that contains the following:
1) A parameter-free constructor that creates an empty set.
2) A constructor that receives as parameters a sorted array of integers and its size. There is no need to check the integrity of the input. Assume the array is sorted and without repetitions.
3) Copier constructor.
4)operator=
5) operator<< Prints the group members.
6) operator + accepts as a parameter a group object, and returns an object that is a union of the two groups. The function does not change the existing groups.
7)operator- accepts as a parameter a group object, and returns an object that is the difference of the two groups. (All the organs that are in this and not in the parameter.) The function does not change the existing groups.
8)operator * accepts an integer as a parameter, and returns a group obtained from the group this by multiplying each member of the group by the parameter. For example, if the set of this is {3,6,30,60}, and the parameter is 10, then the object to be returned will be {30,60,300,600}. The function does not change this.
9)operator && accepts an integer as a parameter. Returns true if the number belongs to the group. Otherwise, returns false. The function does not change this.
10)total_sum returns the sum of the members of all groups.

If you have something similar let me know.
this is pretty screwy and no one is likely to have anything similar. A set without intersection etc, but with a numerical multiply (most sets would be generic, not tied to numerical types, so this is nonsense -- no one would make an integer only set) and accepting a C-array is also weird, those are rarely used anymore, and no one would code up one that trusts the input to be correct without any checking. The assignment asks you to break like 3 or 4 rules of good design.. overloading things to unusual behavior (+ and * are totally unrelated, usually * does + in a loop), no error checking, object is trying to be a container AND do other stuff (normally would have a container and a class that uses the container to process the data, separately), and it appears to violate the rules of 3.

You will have to code it up, which is probably the reason why it has such specific, odd requirements -- to prevent cheating.

Speaking of cheating, this site frowns on that -- code something, get stuck, show us what you have, ask a question, get some feedback and try again... learn something.

I will offer that << is the 'hard' one if you have not seen it before, but there are a ton of examples of that in old posts or on the web. The rest are very basic.

I will explain myself:
First of all I am not a programmer or anything like that but I try to combine math with software to present my dad a supportive version of the actions because he is interested in learning about it so there are some actions beyond expectation and I would be equally happy to see a class that has only union of sets and subtraction.
you should be able to find a class that does math sets in c++.
be warned: c++ has a 'set' that is, like 'vector', not what MATH has for these terms. They are data structures that are sort of like the math things, but not quite. You don't want a c++ set here, you want a math set, and have to watch out when searching the terms.

here on this site, consider:
http://www.cplusplus.com/reference/algorithm/set_intersection/
^^ has links to union, difference, more.
note that it uses vectors, and not c++ sets, in the example, because c++ sets are not math sets :)

you can wrap up the examples into a class to make a set-object or find one online that does it for you somewhere.
then you can use the set-object to do the other things you asked for, either in a new class or stand alone routines, depending on how much bigger your program needs to be

Last edited on
Topic archived. No new replies allowed.