During this activity, students will be able to:
For this programming assignment, students are required to complete all work independently and are not permitted to use AI-assisted tools, such as GitHub Copilot, ChatGPT, Gemini, or similar platforms, to automatically generate code. Using AI tools in this way undermines the learning process and violates academic integrity policies. The purpose of this assignment is to assess your understanding and application of the concepts covered in the course. Failure to comply with these guidelines may result in academic penalties, including but not limited to a lower grade.
If you have any questions about the assignment or need clarification on any concepts, please do not hesitate to visit your instructor during office hours. Rely solely on your own knowledge, the course materials, and any authorized resources provided by the instructor.
This activity must be developed in the pre-assigned teams of two.
NOTE: The files needed to start this lab are available in this tarball file: dinoset.tgz
. To uncompress, type at the Linux terminal:
tar xzf dinoset.tgz
Your good friend, paleontologist Alan Grant, has asked you to implement a C++ class that allows working with sets of dinosaurs (DinoSet
) in order to develop a project for mangaging fossils of saurian species found in different excavation locations.
A set is a collection of well-defined elements without repetitions. A DinoSet
can be implemented using a boolean array with a size equal to the number of dinosaur species we want to represent. Each element in the array represents the presence or absence of a dinosaur species within the DinoSet
.
The specific species of dinosaurs that are required in your DinoSet
class can be represented as a C++ enumeration:
enum class DinoId { velociraptor, // 0 stegosaurus, // 1 tyrannosaurus, // 2 procompsognathus, // 3 triceratops, // 4 pachycephalosaurus, // 5 parasaurolophus, // 6 pteranodon // 7 };
The integer values in the code comments above correspond to an index in the boolean array. So, for example, if array location 0 is true
, it means that the array contains a velociraptor. In case the array location 0 equals false
, then the array does not contain a velociraptor. The DinoId
enumeration allows dinosaurs to be referred to by name rather than number, i.e. instead of referring to dinosaur 1, one must refer to dinosaur DinoId::stegosaurus
, which makes the program more legible.
The member functions of the DinoSet
class are described below:
Member Function | Description |
---|---|
void add(DinoId id)
|
Adds to this object the element specified by the DinoId taken as input.
|
void remove(DinoId id)
|
Removes from this object the element specified by the DinoId taken as input.
|
bool contains(
|
Returns true if this object contains the DinoId taken as input, or false otherwise.
|
int size() const
|
Returns the number of elements contained in this object. |
bool is_empty() const
|
Returns true if this object is an empty set (has zero elements), or false otherwise.
|
DinoSet operator+(
|
Union: returns a new DinoSet consisting of all the elements contained in this object and/or in the DinoSet taken as input.
|
DinoSet operator*(
|
Intersection: returns a new DinoSet consisting of all the elements contained in this object and also in the DinoSet taken as input.
|
DinoSet operator-(
|
Difference: returns a new DinoSet consisting of all the elements contained in this object but that are not contained in the DinoSet taken input.
|
DinoSet operator!() const
|
Complement: returns a new DinoSet consisting of all those elements that are not contained in this object.
|
bool operator==(
|
Returns true if the DinoSet taken as input contains exactly the same elements as this object. Otherwise it returns false .
|
std::string to_string()
|
Returns the representation of this object as string of characters. The precise format can be seen in the corresponding section of the tests.cpp file.
|
Place all your code in a file called dinoset.h
. Test your class implementation using the tests.cpp
unit tests file (it contains a total of 93 assertions).
Place in a comment at the top of the dinoset.h
source file the authors’ personal information (student ID and name), for example:
/*---------------------------------------------------------- * Lab #1: DinoSets * Implementation of the DinoSet class. * * Date: 23-Aug-2024 * Authors: # A01770771 James Howlett # A01777771 Wade Wilson *----------------------------------------------------------*/
To deliver the dinoset.h
file, please provide the following information:
Only one team member needs to upload the file.
Due date is Friday, August 23.