In this assignment,you’ll write two functions: one which reads a file and uses the information from the
file to create an array of Set objects; and a second which takes an array of Set objects and writes the set
to a file. For this assignment, assume all sets will have the default range of 0 through 100.
bool readSet(char *filename, Set **mysets, int &numSets);
Regarding the signature for this function. The double pointer (“**”) definition for the mysets
parameter is to allow the function to return the storage that it allocates for the new array of Set objects.
This could have been declared as follows:
Set *&mysets
which, reading from the variable name, is a reference to a pointer to Set type. However, for this
program use the signature above. Keep in mind that to use the pointer that you wish to change and use
as an array, you need to use *mysets, as in:
*mysets = new Sets[size]; or
*(mysets)[i]
Also, keep in mind, that when you allocate an array of Set objects, the array holds actually objects, not
pointers to objects. The sets are initialized using the default constructor: they are empty and will hold
members in the range of 0 through 100.
Remember you can use the constructor to create Sets on the fly. You can collect integers in an array
and create a temporary set which you assign to the array:
*mysets[i] = Set(a, size);
where a is an array of integers and size is its size.
You can also add the integers to a set one by one using the operator+(int) overloading.
The readSet function returns success or failure as its return value (true for success and false for failure).
It takes pointer to char type (which is a string), a pointer to an array of sets and a reference int
parameter. The int parameter is used to return the number of set created; the pointer to the array of sets
is used to return the array. readSet opens the file (for reading) using the filename parameter; then reads
the file and creates the sets.
The format of the file containing the information to create the sets is up to you. Minimally, it must
supply your with two basic pieces of information: how many sets are to be created; and what each is
the membership of each set.
One possibly style of format is to have an initial integer which specifies the number of sets the file
contains. Each set is then represented by an integer describing the number of elements in the set,
followed by that number of integers representing elements.
Another possibility is to have a delimiter for each set; that is, each list of integers describing a set is
preceding by a special character (non-digit) indicating the start of a set and followed by a special
character (it could be the same character), ending the list of integers for the set. All of the integers
between the delimiter characters belong to the set.
Your function and file format should allow the creation of empty set (zero elements).
You function should return success if it was able to create all of the sets. It should return false if it was
not. For example, if the file specifies 15 sets and there is data for only 14, that would be a failure as
would the presence of data for 20 sets. Your function should also return failure if it detects other input
file formatting errors: a discrepancy between the set sizes and the number of elements providing or the
appearance of integers outside of the delimiter characters for sets. The function should return false if is
not able to open the file.
Your function should close the file.
bool writeSet(char *filename, Set *mysets, int numSets);
This function should take the supplied filename parameter; open the file, and write the members of
each set to the file. The writeSet function should use the same format as the readSet function. writeSet
should also return success or failure. The primary failure mode will be the inability to open the output
file.
Your program should read the names of the input and output files.
Deliverables:
You will submit your program as a single .zip or .rar file containing your Set.h, Set.cpp, and main.cpp
files, along with your input and output files, through the link on blackboard for the assignment. The
definition of your readSet and writeSet functions should be in your main.cpp file. The due date will be
June 13h at 11:59pm..
Do not cut and paste your source code to submit it, rather, attach the file using th0 “Browse my
computer” below the Assignment Materials window.
Sample File Formats:
These are some possible files formats. All three formats represent the same three sets. These are not
the only possible formats, but are simply provided as examples.
{ 3, 5, 6, 29 } with size four
{ 3, 4, 5, 9, 11, 20, 45, 54, 89, 92 } with size 10
{ 2, 3, 97, 98 ,99 } with size 5
34
3 5 6 29
10
20 4 5 9 11 89 45 92 54 3
5
99 98 97 2 3
3
4 3 5 6 29
10 20 4 5 9 11 89 45 92 54 3
5 99 98 97 2 3
3
& 3 5 6 29 *
& 10 20 4 5 9 11 89 45 92 54 3 *
& 5 99 98 97 2 3 *