Modify C Code Convert Bag Dynamic Array Show Screenshot Sample Outputs Bagh Pragma Class B Q37238770

Modify this C++ code to convert this bag into a dynamic array.Show screenshot of sample outputs.

–Bag.h–

#pragma once

class Bag
{
public:
   static const int CAPACITY = 10;
   Bag();
   void insert(int item);
   void removeOne(int item);
   void removeAll(int item);
   int occurrences(int item);
   int size();
   void display();

private:
   int count;
   int data[CAPACITY];
};

–Bag.cpp–

#include <iostream>
#include “Bag.h”
using namespace std;

Bag::Bag()
{
   count = 0;
}

void Bag::insert(int item)
{
   if (count < CAPACITY)
   {      
       data[count] = item;
       count++;
   }
}

int Bag::occurrences(int item)
{
   int counter = 0;
   for (int i = 0; i < count; i++)
   {
       if (data[i] == item)
           counter++;
   }

   return counter;
}
void Bag::removeOne(int item)
{
   int index = 0;

  

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.