1. Homepage
  2. Programming
  3. CSCI251 Advanced Programming - Assignment 3: Knapsack

CSCI251 Advanced Programming - Assignment 3: Knapsack

Engage in a Conversation
University of WollongongCSCI251Advanced ProgrammingC++Knapsack

School of Computing & Information Technology CourseNana.COM

CSCI251 Advanced Programming Spring 2023 CourseNana.COM

Assignment 3 (Worth 8%) CourseNana.COM

Due 11:55pm Friday in Week 13 (27th Oct,2023) CourseNana.COM

Overview CourseNana.COM

This assignment involves a Knapsack class containing a function template to add objects of various sizes until the knapsack is near full. CourseNana.COM

A knapsack CourseNana.COM

Knapsack problems relate to resource allocation. In this assignment, the emphasis is not on optimization, you will add objects as they arrive if they fit. There is a collection of classes A to G provided in collect.h and you will need to pass instances of them to a knapsack in the order they arrive, until the next object cannot fit. You are to write a Knapsack class and the main() to demonstrate the functionality required here. Your program should compile to KAP and run as: CourseNana.COM

./KAP size seed durability CourseNana.COM

size : A positive integer. The size of the knapsack.
seed:Apositiveinteger.Randomseedtobepassedtothegeneratefunction.
durability: A positive integer. The maximum number of resets the knapsack can execute. CourseNana.COM

A function generate(int) is prototyped in collect.h and defined in the library libKnap.a.
It returns a letter (char) that identifies which object you need to try and fit into your knapsack. The generated letter can be A to G and R and S. The letters R and S are for special classes which trigger special condition 2 and 3. The special conditions will be described shortly.
CourseNana.COM

You need to define a function template inside Knapsack and pass an object of that type to the knapsack using the function template. That function template should take an object of arbitrary type as input (i.e., generic to objects of different types) and attempt to ”add it” to the knapsack. Note that the function template is allowed to take more than one input parameter if necessary. However, only one single parameter related to the object (i.e., the object itself) is allowed. CourseNana.COM

If the object fits, based on the size using the built-in function sizeof(), you record that object as being included, using the name attribute of the classes. The object itself should not be stored in the knapsack, which means that the actual object information is not stored. However, it takes some space of the knapsack which is equal to the returned value of sizeof(this object). When one of the following conditions occurs, you need to output a conditioned message based on the condition we meet and then a summary report. The summary report and conditions with corresponding conditioned messages are described as below: CourseNana.COM

Summary report: It consists of two parts separated with “=======================”: CourseNana.COM

  • Knapsacksize,fillsize,andalistofobjecttypesintheorderadded.Forinstance: ==========================
    Knapsack size:
    Added object size: ...
    CourseNana.COM

    BADACEGD CourseNana.COM

  • Information of objects in the knapsack based on the alphabetical order, with the size of each type and the number of each included. For instance:The program produces a conditioned message followed by a summary report. After that, the Knapsack is reset, and all the previously stored objects are removed. If reaching the maximum number of resets, the process will be terminated. For instance, if the current reset is 4 and the durability is 10, the conditioned message is as below: Condition 2: Attempt to add an R object CourseNana.COM

which triggers a reset. The number of used resets: 4 out of 10” CourseNana.COM

Condition 3 (Attempt to add an S object) CourseNana.COM

The program displays a conditioned message followed by a summary report, then stops the adding process. The conditioned message is below: “Condition 3: Attempt to add an S object which triggers early termination.” CourseNana.COM

Notice and Example outputs CourseNana.COM

Notice: The three conditions above are mutually exclusive; conditions 2 and 3 can be triggered without considering the size of R and S objects, and R and S objects cannot be added into the Knapsack; Objects not included in the knapsack should not appear in the summary report; The collect.h and libKnap.a can be changed for our marking, so you should not hardcode sizes or attempt to predict the output from libKnap.a. CourseNana.COM

Below are some examples. Note that if you test your code on Capa, you should produce the same output given the same input. CourseNana.COM

Example 1 CourseNana.COM

Example 2 CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
University of Wollongong代写,CSCI251代写,Advanced Programming代写,C++代写,Knapsack代写,University of Wollongong代编,CSCI251代编,Advanced Programming代编,C++代编,Knapsack代编,University of Wollongong代考,CSCI251代考,Advanced Programming代考,C++代考,Knapsack代考,University of Wollongonghelp,CSCI251help,Advanced Programminghelp,C++help,Knapsackhelp,University of Wollongong作业代写,CSCI251作业代写,Advanced Programming作业代写,C++作业代写,Knapsack作业代写,University of Wollongong编程代写,CSCI251编程代写,Advanced Programming编程代写,C++编程代写,Knapsack编程代写,University of Wollongongprogramming help,CSCI251programming help,Advanced Programmingprogramming help,C++programming help,Knapsackprogramming help,University of Wollongongassignment help,CSCI251assignment help,Advanced Programmingassignment help,C++assignment help,Knapsackassignment help,University of Wollongongsolution,CSCI251solution,Advanced Programmingsolution,C++solution,Knapsacksolution,