473,666 Members | 2,237 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2807
On 10 Mar, 05:18, "Richard Gromstein" <rgr...@gmail.c omwrote:
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.c omwrote:

>>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
561
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 number of window handle, because if I reduce to about 2 instances of each window, it can run. But not 20 instances of each window. Does anyone know what the problem is? is it really because it exceeds the maximum number of window handle?
4
10746
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 consisting of 6 numbers - with a total of 50 groups of numbers. A well-known girl that some publishing companies use to provide introductory level textbooks to various Junior Colleges in the U.S., not surprisngly, asks for this same exact...
8
9086
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 another class. i can see the properties of the first class and the namespace of the second (inner class) but can't see the properties of the 2nd....
7
1592
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 will (after parsing the XML) return an object that is accessible by name? Such as the following:
1
6452
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 MVC-ipmlementation from the JAVA by using the observer-pattern. I used an interface IObservable (AddObserver, RemoveObserver,...). My Model implemented this interface.
25
1853
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 exercise, I'm creating a program that takes a quote and converts it into a cryptogram. Right now I have four functions: convert_quote -- the main function that starts it all make_code -- makes and returns the cryptogram make_set -- called from...
9
2260
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 /Date structures/. "Date" struct carries 3 things: month, date & year. i wrote the following code & of course it gives an error: #include <iostream>
26
5354
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 because I am not always able to control/create all the different constructors the base class has. My problem can be described in code as follows ... /* This is the base class with a whole heap of constructors/functionality*/ public class Animal
2
3973
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: D:\original\CaseStudy-2-5\CaseStudy\Day02\exercise>asant database Buildfile: build.xml env-user: prop-user: set-user:
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.