C++/can u help me with this question...
can u help me with this question coz i don't know to start and to do. if u help this, it's really will help me to solve other question maybe simmilar with that. thaks and the below is the question!
design,implement, and test a set class in c++ that provides te operation; set membership; set intersection, set union and set difference. An array is to be used to represent a set within a class.
As you know if you read my instructions to questioners I will _not_ do your homework or coursework for you.
So I am only going to give you general advise to get you started.
The first piece of advise is: don't panic.
The second is: read what you have been told to do.
The third is: use your brain, think for yourself!
In effect your question is a requirement specification for the solution you are required to produce. In this case you are also told what your 'job' responsibilities are: designing, implementing and testing the system required.
You are also told what is required:
"a set class"
and what it should be able to do:
"provides te operation; set membership;
set intersection, set union and set difference."
(I presume this should start "provides the operations:" )
You are also told in this case what the solution environment (for want of a better term) is : C++
And some constraints on the implementation:
"An array is to be used to represent a set within a class."
You have several hurdles to over come.
You have to understand the problem, for example:
- What is a set?
- How do you perform the required operations on these sets?
You have to understand the solution environment - i.e. C++, for example:
- What is a class?
- How should you represent a set (see previous notes
on information from the question)
- How do you specify the operations?
Once you have satisfied yourself that you understand these things then you can start to think how to represent the one in the other i.e. a set in C++.
Start by ensuring you know how to perform all operations on a set yourself - try out some examples, read up on subject if necessary. Keep a reference to hand, it will probably be useful when you come to implement the operations in C++.
Next design an initial outline for your class: start with what it needs to do, what operations and attributes it requires, what the types, parameters and return types are of these things.
Add anything that C++ requires into the mix. Keep a C++ reference (or three...C++ is a big complex beastie) to hand.
You might like to think on how your class would be used: you will need to use it to test it anyhow. Doing this may help you firm up your design in your head, and make you think on what instances of your class should be responsible for and what users of instances of your class are responsible for.
Do not be afraid to get it 'wrong' the first, second, third... time; understanding often comes by getting it wrong - that "oh dear this is not going to work" feeling followed by some deep thoughts on what is really required and (hopefully) the light of inspiration and understanding...go around as often as you require.
The same goes for when you come to implement your design. The compiler (and possibly the linker) will probably complain. Remember the pieces of advise I gave at the beginning: don't panic, read what you are told (compiler/linker errors and warnings in this case), and use your brain. OK so compiler errors can be cryptic so the last piece of advise is often necessary to devise ways of locating non-obvious problems. Remember compilers are _very_ picky about the code you write - even more so than spelling checkers are about your spelling in text you write into work processors and the like. Expect to get a load of errors when you first compile your code - be suspicious if all seems to compiler and link first time - we all mistype things, use the spelling or case of names inconsitently, forget the occasional semi colon etc. Be prepared to look for these sort of things. After a bit you should get down to the real problems!
Once you have your class compiling you should think on creating a "test bed" program that exercises it. You can probably do this using a simple program (main and using std::out for the results). If things look like getting messy then consider at least splitting the code into more than one function. I suspect writing a set of helper classes is a bit too much for you at this point.
_Never_ assume that a compiled piece of code is correct. All you have is some object code translated from C++, what is does is an entirely different question.
Create uses of instances of your class that test certain specific things: Setting up a set, intersecting 2 classes etc... All operations should be tested as completely as possible.
Pick test instances that check out special or boundary conditions such as performing operations with empty sets or default constructed instances (which I would hope would be the same as an empty set...).
Use your test bed program to check that the set class functions correctly. If not go back and fix the problem.
You might like to consider writing the test bed program as you implement each part of the set class. Each time you add something to the set class you add something to the test program to ensure the new functionality works correctly. This way you know as soon as possible if things are wrong and can fix them before moving on...
Finally I repeat: do not be afraid to go back and change things, even across several stages. For example you might need to go back and check the workings of a set operation and update the design when you come to test an operation and find you have not understood what was required until you had your face rubbed in it when it did not work as expected (yes I have been there...).
Hope this helps.