Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignments you are given 2 classes (Item, Bag) and 1 main() that uses them. For simplicity sake, everything is in one .cpp file

For this assignments you are given 2 classes (Item, Bag) and 1 main() that uses them.

For simplicity sake, everything is in one .cpp file ( main.cpp in Clion)

First write the Item class:

It has a couple of constructors, and a few functions that let you change or see the variables: name , cost.

First thing to do is, test the Item class to see if it works from the main():

Now add another class (in the same file, before the main) called Bag:

The Bag class creates an array of items:

Provides two different ways to insert an item into the Bag:

Lets you show everything in the Bag:

Lets you delete the first element (index 0), then shift all other to the left on top of it to avoid a gap

Checks to see if the Bag contains a particular Item name

=== WRITE and TEST the Functions below:

void most_expensive ( ) (shows the most expensive item)

void show_reverse ( ) (shows everything in the bag in reverse order of showItems() )

void get_frequency (Item item) (show how many times an Item (the name) appears in the bag)

bool deleteItem (Item item) (delete item(based on the name), shift array elements to the left, return true if successful

int get_index_of (Item item) (returns the index of an item (based on the name))

double sum_of_all ( ) (returns the sum of all Items)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Solve for x: 2(3x 1)2(x + 5) = 12

Answered: 1 week ago