My homework assignment is to implement a class that represents a set of integers. Each set object may contain up to 100 integers. The main program will allow the user to create up to 10 different Set objects and perform actions on them. Actions such as return the interaction, union, difference,....etc.

I know that each set object will be an array. I can figure that much out. But, I am nsure how to go about letting the user name the 10 different Set objects. I can ask the user to enter a string but then how do I initialize the array using the string entered by the user?

int name[100]; is how I would normally create an array with up to 100 integers. What I need to do is create an array that has the name entered by the user. If the string is s for instance, I stick int s[100]; it doesn't work. Any help would be greatly appreciated.

Member Avatar for Siersan

Do the requirements say that the user should be able to create up to 10 Set objects, or up to 10 named Set objects? It appears to me like you can just have an array of Sets:

Set a[10];
int n = 0;

Then increment n when the user asks for another set and have the user identify each set by its index in the array.

If you want to map a name to each set then you need to use (oddly enough) a map:

#include <map>
#include <string>

map<string, Set> m;

But I really don't think that the assignment wants you to go that far.

You know, looking it over, I guess I don't have to allow the user to name the object set just say that he/she wants to create another set. But, I see how you are saying to count up to 10 object sets, but each object set will be an array of 100 integers in itself. I will work on that for a while. Thanks.

Thought about this a little more. If for example a[1] is the first object, how do I create an array within a[1] where the user can enter 100 integers?

a[1][100]? Is it a two dimensional array?

Member Avatar for Siersan

a[0] is the first object. Don't forget that arrays in C++ are zero based. But yes, a two dimensional array can do what you want.

I have gotten a little further. A two dimensional array is not the way that I am going about this. What I have is S[10] to represent the ten sets of integers. The class contains a[100] which is the 100 elements in the array. If the user asks for 3 objects or sets, there is a loop that creates S[1] and a corresponding a[100]. Then S[2] and another a[100]. then S[3] and another a[100]. I have part of it down but I am sure I am gonna need some more help with it.

im trying to imagine why you would need something like this

kind of like math class when you would ask the teacher, "how is this used in the real world?" or "why are we learning this, how is it going to help me in the real world?"

what PRACTICAL use would all of this serve once you get it working?

just a question as i try to understand what you need help with

>what PRACTICAL use would all of this serve once you get it working?
Each set could be a collection of vertices in a graph used for routing packets through a network in the most efficient manner possible.

Hmmmm...yet again another great example...you have no idea how much you help me

so let me see if i've got this correctly, this vertices would act as plots on the graph

you know what, i have to read up on packet routing and vertices a little more

this is new to me...i will be back to finish this conversation :)

This is an assignment in my C++ class. I went to a University that taught in Java. There were C classes available, but I took the Java route. I am 28 now and trying to get into grad school. The grad school I want to go to said that I should take Object Oriented C++ at a JC. That is how I got to this point. From this assignment, we are going to go on to make a card game using sets of numbers.

i haven't read up either just yet but lets look a this some more

and see how the coding concept would work for your example

10 sets of objects/intergers

100 objects/intergers per set

i don't know what you mean, i'm guessing the vertices would be nodes on a network

i don't see how that could be an example of how his assignment works in real life though

*reads up on routing alogrithms

http://www.stanford.edu/~boyd/reports/obliv_route.pdf#search='plotting%20vertices%20routing%20packets%20through%20network'

that's no help

http://www.cisco.com/univercd/cc/td/doc/cisintwk/ito_doc/routing.htm#xtocid4

ahhhh, i think i have something

10 sets of objects/intergers = ADDRESSES OF NODES IN NETWORK

100 objects/intergers per set = NUMBER OF PATHS SPROUTING FROM NODE

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.