1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yulyashka [42]
4 years ago
12

Imagine you just left a store with a bag of groceries. You are concerned that the fragile items will not survive the trip home,

so when you reach your car, you place those items into their own bag. Using the templated version of the Bag class from Chapter 1 (one file version with header and implementation combined that is posted on Blackboard) write C++ statements that remove all the fragile items (eggs and bread) from storeBag place them into fragileBag. Print the contents of both bags using a method named displayBagContents that you added to the Bag class.
Again suppose that a bag contains strings that represent various grocery items. Write a 2 argument C++ function that removes and counts all occurrences of a given string from such a bag. Your function should return the number of items removed. Handle the possibility that the given bag is either empty or does not contain any occurrences of the given string. Print the count returned and the contents of the bag after the function executes displayBagContents member function that you added to the Bag class.
Computers and Technology
1 answer:
iogann1982 [59]4 years ago
3 0

Answer:

Explanation:

#include <iostream>

using namespace std;

#include <iostream> // For cout and cin

#include <string>   // For string objects

#include "Bag.h"    // For ADT bag

using namespace std;

int main()

{

int y=0;

string clubs[] = { "eggs", "eggs", "eggs", "orange", "bread", "bread" };

Bag<string> grabBag;

Bag<string> fragileBag;

for (int x = 0; x < 6; x++) {

grabBag.add(clubs[x]);

}

int count = 0;

for (int q = 0; q < 6 ; q++)

{

if (clubs[y] == "eggs" || clubs[y] == "bread") {

fragileBag.add(clubs[y]);

if(grabBag.remove("eggs")){

   ++count;

}

}

y++;

}

cout << "fragile bag contains:" << endl;

fragileBag.displayBagContents();

cout << "grocery bag contains:" << endl;

grabBag.displayBagContents();

cout << "Number of items removed from grocery bag : " << count<<endl;

return 0;

};

You might be interested in
Stores of data that are so vast that conventional database management systems cannot handle them, and very sophisticated analysi
Colt1911 [192]
Maybe an international database, where all nations are invited to contribute information, THEREFORE, there would be a vast amount of data.
5 0
3 years ago
The data components of a class that belong to every instantiated object are the class's ____ variables.
ryzh [129]
The data components of a class that belong to every instantiated object are the class's Instance variables.
7 0
3 years ago
Read 2 more answers
Which type of VBA code is common for grouping statements that perform a certain task?
svet-max [94.6K]

Answer:

Module

Explanation:

Don’t listen to this answer it’s probably not rt

8 0
3 years ago
_______ is malware that encrypts the user?s data and demands payment in order to access the key needed to recover the informatio
Phoenix [80]
Ransomware is the malware that encrypts the users data
4 0
3 years ago
What is a fixed expense<br> everfi
Gelneren [198K]

Answer:

A fixed expense is an expense that has a constant total expense value (the total amount of the fixed expense) that remains the same (does not change) when there is a change in the number being managed, manufactured, or sold

Examples of fixed  expense includes; depreciation of assets, salaries of workers, payment for rental lease, and some utility payment, such as road users toll fees payment at a toll gate

Explanation:

8 0
3 years ago
Other questions:
  • Q) Select the two obstacles for data parsing
    5·2 answers
  • A Windows systems administrator should use the Administrator account ________.a. As little as possible, and only when needed b.
    15·1 answer
  • Which is the correct expansion of the term Internet? 
    9·2 answers
  • A) A cable that is mainly used in the cable television network
    11·1 answer
  • What is the keyboard shortcut used to paste previously copied text?
    15·2 answers
  • People read all caps in e-mails as _____. yelling important points necessary for readability all of the above
    15·2 answers
  • NEED HELP WILL MARK BRAINLIEST AND 100 POINTS FOR ANSWER Which LIKE operator would match a single character?
    9·2 answers
  • A computer that supports LoJack technology must have two main components installed. It needs an Application Agent (residing in t
    13·1 answer
  • Which of the following describes why graphical interfaces quickly became popular after their introduction to the mass market?
    5·1 answer
  • Can u please help me solve this
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!