Question
In c++. Included is the starter code the new ReceiptBag class will be based off of. Please help write the new class ReceiptBag. #pragma once
In c++. Included is the starter code the new ReceiptBag class will be based off of. Please help write the new class ReceiptBag.
#pragma once
#include
#include
template
class Bag {
public:
void insert(Thing aThing) {
bagContents.push_back(aThing);
bagSize++;
}
Thing &pop() {
Thing aThing;
if (bagContents.size() > 0) {
aThing = bagContents[bagSize];
bagSize--;
}
else {
cout
}
return aThing;
}
int count(Thing aThing) {
int bagCount = 0;
for (int i = 0; i
if (bagCount[i] == aThing) {
bagCount++;
}
}
return bagCount;
}
private:
vector
int bagSize = 0;
};
Suppose we want to be able to remove a specific item from a bag. So, when you put an item into a bag, also return some integer value you will use as a receipt. Modify the code for taking something out of the bag so that it looks for the item that matches that integer. Build a ReceiptBag class that implements this variation of a Bag data type. HINTS: - This is an application of the parallel arrays/vectors design that we discussed (and many of you hated) in CS318. - You will need to think about how to address what happens in the data structure(s) storing bag contents when someone removes an item. You can no longer assume you just peel an item from the start or end of that structureStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started