Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

1/25/22, 1:25 PM Lab 2 - Hermione's Handbag: (22SS-Full) ENGINEERING DATA STRUCTURES (001) https://uc.instructure.com/courses/1519734/pages/lab-2-hermiones-handbag 1/5 Lab 2 - Hermione's Handbag Due...

1 answer below »

1/25/22, 1:25 PM Lab 2 - Hermione's Handbag: (22SS-Full) ENGINEERING DATA STRUCTURES (001)
https:
uc.instructure.com/courses/1519734/pages/lab-2-hermiones-handbag 1/5
Lab 2 - Hermione's Handbag
Due on January 25 and 11:59pm.
Introduction
Though small physically, the volume of Hermione’s beaded handbag is
actually quite vast! In fact, it is infinite. In the Ha
y Potter series, the small
sack Hermione ca
ies, pictured at right, was enough to hold at least a pair of
jeans, a sweatshirt, a pair of socks and an invisibility cloak! My sister is a
world traveler, but not even she could fit that much stuff in luggage that size!
[1]
(https:
ha
ypotter.fandom.com/wiki/Hermione_Granger%27s_beaded_handbag)
Don’t wo
y, you don’t have to be a Ha
y Potter fan to complete this lab. No
do you have to believe in Wizardry because, in the end, all you need is some
C++ and you too can create a beaded handbag of your own!
ADTs
Recall our discussion in class about abstract data types (ADTs). ADTs are “a collection of data and a
set of operations on that data”.
As the textbook author is at pains to remind us, an ADT is not a data structure. In a sense, the ADT
precedes the data structure. A data structure is a means of implementing an ADT.
Beaded-Bag ADT
In this lab, you will implement the beaded-bag ADT. But, before we can implement the ADT we must
define the ADT. Recall the definition of an ADT: “a collection of data and a set of operations on that
data”.
First, we will define the data. Like Hermione’s physical bag, the beaded-bag ADT holds an infinite
number of elements. Unlike her bag, however, the elements in the beaded-bag ADT are all of the
same type. The user of the beaded-bag ADT specifies the type of the element when they create and
use the ADT. This type of ADT is known as a type generator in the realm of theoretical compute
science, although our textbook does not necessarily use that term. Like Hermione’s real bag may
contain more than one pair of socks so that she can keep her feet warm while fording streams in thei
pursuit of horcruxes.
th
https:
ha
ypotter.fandom.com/wiki/Hermione_Granger%27s_beaded_handbag
1/25/22, 1:25 PM Lab 2 - Hermione's Handbag: (22SS-Full) ENGINEERING DATA STRUCTURES (001)
https:
uc.instructure.com/courses/1519734/pages/lab-2-hermiones-handbag 2/5
Having defined the data of the bag, we turn our attention to defining its operations. The user of a bag
should be able to insert a new element into the bag. The user of a beaded-bag ADT should be able
to query it to determine whether the bag contains a certain item. Finally, though its capacity is infinite,
the user of a beaded-bag ADT should be able to determine how many elements it actually contains –
in other words, a user should be able to find out the size of the beaded-bag ADT.
The following are the specifications of the beaded-bag ADT:
Operation Task Input Output
insert
Insert an
object (of the
proper type)
into the
eaded bag.
An object to insert. Nothing.
contains
Check
whether a
given object is
in the beaded
ag or not.
An object (of the
proper type)
potentially
contained in the
eaded bag.
True or False
depending on whethe
the given object is
contained in the
eaded bag.
size
Access the
number of
elements
contained in
the beaded
ag.
Nothing.
The number of
elements in the
eaded bag, as an
integer.
Programming Task and Requirements
Your programming task for this lab is to implement the beaded-bag ADT. Implementing an ADT
involves writing a data structure that adheres to the ADT’s specifications.
Your implementation will be a class named BeadedBag . Given that the beaded-bag ADT is a type
generator, BeadedBag will need to be a class template (pp XXXXXXXXXXin Walls and Mi
ors) whose type
template parameter (https:
en.cppreference.com/w/cpp/language/template_parameters) is the type
of the elements that the beaded bag holds.
There is no restriction on how you store the beaded bag’s elements internally. However, using a
std::vector (https:
en.cppreference.com/w/cpp/containe
vector) (pp XXXXXXXXXXof Walls and Mi
ors)
may be a good idea (hint, hint!).
You must use the == operator when determining whether an element is contained in the beaded
ag.
Your implementation must use only private member variables.
https:
en.cppreference.com/w/cpp/language/template_parameters
https:
en.cppreference.com/w/cpp/containe
vecto
1/25/22, 1:25 PM Lab 2 - Hermione's Handbag: (22SS-Full) ENGINEERING DATA STRUCTURES (001)
https:
uc.instructure.com/courses/1519734/pages/lab-2-hermiones-handbag 3/5
Any methods that implement operations of the beaded-bag ADT that do not modify the contents of
the bag (e.g., size and contains) must be const methods (p. 741 of Walls and Mi
ors).
Normally, you would separate your interface from your implementation – the best practice in C++
(see Walls and Mi
ors p. 32). However, when dealing with templates, this is not possible – as we
discussed in class. In other words, you should declare the class and define it entirely in a heade
( .hpp ) file. The skeleton code for this lab should make it easy for you to meet this requirement.
Examples
Assuming that you have properly defined the BeadedBag class, the following code should print
#include
eadedbag
eadedbag.hpp>
#include
int main() {
BeadedBag
_of_doubles{};
BeadedBag
_of_ints{};

_of_doubles.insert(5.0);

_of_doubles.insert(6.0);

_of_doubles.insert(7.0);

_of_doubles.insert(8.0);
if (
_of_doubles.size() == 4) {
std::cout
"The Beaded Bag of Doubles properly contains 4 elements.\n";
}
if (!
_of_doubles.contains(9.0)) {
std::cout
"Yes, the Beaded Bag of Doubles is missing the element 9.0\n";
}

_of_ints.insert(1);

_of_ints.insert(2);

_of_ints.insert(3);

_of_ints.insert(4);

_of_ints.insert(5);
std::cout
"There are "

_of_ints.size()
" integers in the Beaded Bag of Integers.\n";
if (
_of_ints.contains(5)) {
std::cout
"Yes, the Beaded Bag of Integers does contain the element 5.\n";
}
return 0;
}
should print
The Beaded Bag of Doubles properly contains 4 elements.
Yes, the Beaded Bag of Doubles is missing the element 9.0
There are 5 integers in the Beaded Bag of Integers.
Yes, the Beaded Bag of Integers does contain the element 5.
Critical-Thinking Task and Requirements
1/25/22, 1:25 PM Lab 2 - Hermione's Handbag: (22SS-Full) ENGINEERING DATA STRUCTURES (001)
https:
uc.instructure.com/courses/1519734/pages/lab-2-hermiones-handbag 4/5
The authors of Walls and Mi
ors define and distinguish a complete interface from a minimal
interface. In this lab we defined an interface for the beaded-bag ADT. Your job in this Critical-Thinking
Task is to argue persuasively that the interface is either complete or minimal. There is no right
answer. However, you must choose a side and defend your position according to the definitions of
those terms.
Your response may be no longer than 500 words and you may use any external reference you deem
appropriate. All references to external resources must be properly documented and formatted. The
choice of formatting for external references is up to you, but you may find it helpful to consult the
Purdue OWL (https:
owl.purdue.edu/owl/purdue_owl.html) for information. The Purdue OWL also
has extensive information on ways to avoid plagiarism
(https:
owl.purdue.edu/owl/avoiding_plagiarism/index.html) .
Submission
Submit your beadedbag.hpp file to Gradescope. In order to access Gradescope, click on Load Lab 2 -
Hermione's Beaded Bag in a new window on the Lab’s assignment page
(https:
uc.instructure.com/courses/1519734/assignments/ XXXXXXXXXX) .
When you submit, ensure that the autograder gives you the full credit. Remember, you have
unlimited submissions before the lab due date to get all the autograder points! Your submission must
also include a file named interface.pdf which contains your response to the Critical-Thinking Task.
You must submit these both at the same time.
Note: The names of the file are case sensitive. beadedBag.hpp is not the same as beadedbag.hpp and
Interface.pdf is not the same as interface.pdf . The autograder is fussy!
Grading
Your submission for this lab will be graded according to the following ru
ic:
Points Requirements
50 BeadedBag passes all tests executed by the autograder.
5
The template type parameter of the BeadedBag class has a
semantically meaningful name.
15
All member functions that implement the beaded-bag ADT’s
operations are properly documented according to the standards
set forth in Appendix I in Walls and Mi
ors (pp XXXXXXXXXX).
5 BeadedBag class contains only private member variables.
10
Member functions implementing the size and contains operation
of the beaded-bag ADT are marked const (5 points for each).
https:
owl.purdue.edu/owl/purdue_owl.html
https:
owl.purdue.edu/owl/avoiding_plagiarism/index.html
https:
uc.instructure.com/courses/1519734/assignments/ XXXXXXXXXX
1/25/22, 1:25 PM Lab 2 - Hermione's Handbag: (22SS-Full) ENGINEERING DATA STRUCTURES (001)
https:
uc.instructure.com/courses/1519734/pages/lab-2-hermiones-handbag 5/5
Points Requirements
15
Your response to the critical thinking task contains a persuasive
argument why the beaded-bag ADT specification is eithe
minimal or complete. Although there is no right answer, you
must choose a side in order to receive full points for this
equirement.
Associated Learning Objectives
1. Implement basic ADTs using C++.
2. Distinguish between ADTs and data structures.
3. Use templates to write generic code.
Answered Same Day Jan 25, 2022

Solution

Kshitij answered on Jan 26 2022
113 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here