473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

creating a Set in C++ using classes (need help on an exercise)

Hello, I have an exercise that I need to finish very soon and I really
need help understanding what to do and how exactly to do it. I am
working on reading the chapter right now and working on it myself, but
I have a feeling I won't get far. Please help me complete the
exercise. I am posting what needs to be done and will be updating
with pieces of code that I come up with. Thank you all for your
attention.
-----------------------------------------
// Exercise text

Implement a Set class, where a set is an unordered collection of zero
or more elements with no duplicates. For this exercise, the elements
should be ints. The public interface consists of methods to

- Create s Set.
- Add a new element to a Set.
- Remove an elemnt from a Set.
- Enumerate the elements in the Set.
- Compute the intersection of two Sets S1 and S2, that is, the set of
elemtns that belong to both S1 and S2.
- Compute the union of two Sets S1 and S2, that is, the set of
elements that belong to S1 or S2 or both.
- Compute the difference of two Sets S1 and S2, that is, the set of
elements that belong to S1 but not to S2.
------------------------------------------
// Instructor't notes

implement with a linked list, using classes

intent: to write classes correctly
Set.h has class declarations (including inlines)
Set.cpp has method definitions for the class
main.cpp is the "driver" (i.e. uses the Set class)
if l is a linked list, is x already on the list?
bool search(x,l) /* search for x on list l*/
if l is null return false
if l->info == x return true
return search(x, l->next)

assume you store the items in order
how to do union of two sets?

create a copy constructor which copies the set -- if you dont, any
copies will destroy the original
when they are destroyed.

of course, your destructor must delete any dynamically
allocated storage

destructor():
if l == null return;
destructor(l->next);
delete(l);

your destructor will call delete on each dynamically
created element. when you creat a copy, if its a
shallow copy, the originals dynamically allocated
parts will be destroyed. (you implicity make copies
when you do call by value, return by value,
initialization copies (i.e. when the copy constructor
is called) the copies are destroyed when they go out
of scope).

-------------------------------------------------------------------

Mar 10 '07 #1
5 2789
On 10 Mar, 05:18, "Richard Gromstein" <rgr...@gmail.comwrote:
I have a feeling I won't get far. Please help me complete the
exercise. I am posting what needs to be done and will be updating
with pieces of code that I come up with. Thank you all for your
attention.
<...>

Break it down. Your instructor told you where to start. Ignore the set
part and complete the first part...
// Instructor't notes

implement with a linked list, using classes.
So try to make a linked list...
If and when you get that to work then you will have partially
completed the task (and so may get some marks) and also may be able to
move on.

regards
Andy Little
Mar 10 '07 #2
kwikius wrote:
On 10 Mar, 05:18, "Richard Gromstein" <rgr...@gmail.comwrote:

>>I have a feeling I won't get far. Please help me complete the
exercise. I am posting what needs to be done and will be updating
with pieces of code that I come up with. Thank you all for your
attention.


<...>

Break it down. Your instructor told you where to start. Ignore the set
part and complete the first part...

>>// Instructor't notes

implement with a linked list, using classes.


So try to make a linked list...
If and when you get that to work then you will have partially
completed the task (and so may get some marks) and also may be able to
move on.

regards
Andy Little

Good advice, to which I would add, don't underestimate the time it will
take you to get a linked list working, if you have never done it before
(unless of course you are a programming genius). Sounds like you've left
it a bit late already. Don't be afraid to ask for an extension.

john
Mar 10 '07 #3
Richard Gromstein wrote:
Hello, I have an exercise that I need to finish very soon and I really
need help understanding what to do and how exactly to do it. I am
working on reading the chapter right now and working on it myself, but
I have a feeling I won't get far. Please help me complete the
exercise. I am posting what needs to be done and will be updating
with pieces of code that I come up with. Thank you all for your
attention.
Show us what you already have. We won't do your homework for you.
[problem statement redacted]
Mar 10 '07 #4
Working on a linked list creation. Digging through old C notes and
reading online tutorials... I'll post what I have when I get
something solid.

Mar 11 '07 #5
Working on a linked list creation. Digging through old C notes and
reading online tutorials... I'll post what I have when I get
something solid.

Mar 11 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
4
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group...
8
by: Simon Edwards | last post by:
Something thats been bugging me for a while... how do you create a namespace that has many children (namespaces) I.e system.io.blah.blah Iv'e done it by creating a class which contains...
7
by: Michael Williams | last post by:
Hi All, I'm looking for a quality Python XML implementation. All of the DOM and SAX implementations I've come across so far are rather convoluted. Are there any quality implementations that...
1
by: Marcel Hug | last post by:
Hi NG ! I have already written a task about MVC and I tried to get the best informations together. I would like to implement the MVC pattern and it work on the way I did it. At first i know the...
25
by: John Salerno | last post by:
Just a quickie for today: Is it common (and also preferred, which are two different things!) to create a function that has the sole job of calling another function? Example: for fun and...
9
by: arnuld | last post by:
problem: define a /struct Date/ to keep track of dates. provide functions that read Dates from input, write Dates to output & initialize a date with date. solution: i thought of a /vector/ of...
26
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
2
by: astolpho | last post by:
I am using a slightly outdated reference book on J2EE programming. It gives 2 methods of creating a database used in its casestudies. The first is an ANT script that gives the following output: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.