Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I feel quite confused about this homework, so I need some advice or hints. The Problem We are going to work on making our own
I feel quite confused about this homework, so I need some advice or hints.
The Problem We are going to work on making our own container class using dynamically allocated memory. We are going to build a Knapsack class, which is also called a Bag or Multiset in computer science texts. You are then going to solve, sort of, a Knapsack problem using your data structure Some Background A Knapsack is best described by an example. Imagine you have some packages that you have to deliver in your delivery truck. Each package you have to deliver has two aspects e a priority e a weight You should deliver all your packages but it turns out that the sum of all the available packages exceeds the maximum weight you can carry in your truck. You have to make a decision, which packages to take. You should deliver as many of the most important/high-priority packages as you can. That is, maximize the sum of the priority of the packages you deliver stay below the weight limit of truck. That is, the sum of the weight of the packages should be below the . truck weight limit This is often called the Knapsack problem. The Knapsack data structure is a container that can hold items of some type and has a fixed weight limit (can hold a maximum weight). The problem is to fill the Knapsack up to (but not over) its maximum weight while maximizing its priority. We need to do three things to address this problem make a Package struct make a Knapsack class write an algorithm to address the Knapsack problem. In particular, you cannot use an STL container inside ofyour Knapsack class. Memory has to be dynamically allocated and deleted Interface, proj10 package.h The Package is a good example of needing a struct, not a class. A Package exists to carry information on its weight and priority, that's about it. It represents the individual packages you are to deliver Data Members . public data member long weight public data member long priorityStep 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