Your program should read the data from a text file (in .txt)of an unknown length
ID: 3623027 • Letter: Y
Question
Your program should read the data from a text file (in.txt)of an unknown length that corresponds to items weights. The program would then prompt the user for the weight limits for the knapsack and then prints out the best solution to the problem on the screen and to an output file(out.txt) as well. a typical input file would have the following data (the first line contains only the number of lines in the input file):
13
3 8 50
7 12 15
4 9 12....
IT SHOULD RUN LIKE THIS
Enter the weight limit of your knapsack:
15
The output of your program would be something like this:
I have found the solution that maximizes your knapsack value when you pick the following items:
6 15
3 18
5 22
The total value of your knapsack is: 55 $. The total weight is 14kg
Explanation / Answer
Okay, First thing is first, C++ teachers really hate when you get help from outside. I have had experience. so I will not write any code but I will give a simple algorithm in a comments format. And I am assuming you know how to do the math. //Open the file. //Open a loop to get the input. // Do the math // One the math is done use foutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.