Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do this in C++ // --------------------------------------------------------------------------- // Assignment #1 The Subset-Sum Problem Part A - int Version #include #include #include using namespace std; //

Please do this in C++

image text in transcribedimage text in transcribed

// --------------------------------------------------------------------------- // Assignment #1 The Subset-Sum Problem Part A - int Version

#include #include #include using namespace std;

// global scope helpers double computeMasterSum( vector data ); void showEntireVector( vector data );

// --------------- Sublist Prototype --------------- class Sublist { public: Sublist(vector *orig = NULL) : sum(0), originalObjects (orig) { } Sublist addItem( int indexOfItemToAdd ); void showSublist() const; int getSum() const { return sum; }

private: int sum; vector *originalObjects; vector indices; };

// ------------------ main ------------------

int main() { int target = 0; vector dataSet; vector choices; int k, j, numSets, max, masterSum, newSum, bestSublist; bool foundPerfect, needAlgorithm;

dataSet.push_back( 20 ); dataSet.push_back( 12 ); dataSet.push_back( 22 ); dataSet.push_back( 15 ); dataSet.push_back( 25 ); dataSet.push_back( 19 ); dataSet.push_back( 29 ); dataSet.push_back( 18 ); dataSet.push_back( 11 ); dataSet.push_back( 13 ); dataSet.push_back( 17 );

choices.clear(); cin >> target; cout

// dispose of easy case immediately to save lots of time masterSum = (int) computeMasterSum( dataSet ); if ( target >= masterSum ) { cout

choices[bestSublist].showSublist(); return 0; } }

// global scope functions --------------------------- // Helper method to compute full sum double computeMasterSum( vector data ) { // code provided by student // // }

void showEntireVector( vector data ) { // code provided by student // // }

// --------------- Sublist Method Definitions ---------------

void Sublist::showSublist() const { int k;

cout

Sublist Sublist::addItem(int indexOfItemToAdd ) { // code provided by student // // }

12.1 The Subset-Sum Problem (Part A - For ints) Parts A and B are required. Part C is optional and is worth 2 points extra credit (but must be submitted in addition to Part A and Part B). Make sure you have read and understood both modules A and B of this week before submitting this assignment. Part A (required) - The Subset Sum Problem For Ints Create a simple main() and complete other needed globe functions and class methods to solve the subset sum problem for any vector of ints. Here is an example of the set-up. You would fill in the actual code that makes it happen. int main() { int target = 0; vector int> dataSet; vector choices; int k, j, numSets, max, masterSum, newSum, bestSublist; bool foundPerfect, needAlgorithm; dataSet.push_back (20); dataSet.push_back(12); dataSet.push_back (22); dataSet.push_back (15); dataSet.push_back (25); dataset.push_back(19); dataset.push_back (29); dataSet.push_back(18); dataSet.push_back(11); dataset.push_back (13); dataset.push_back (17); choices.clear(); cin >> target; cout 5 #include 6 #include 7 using namespace std; 8 9 // global scope helpers 10 double computeMasterSum( vector int> data ); 11 void showEntireVector( vector int> data ); 12 13 // --- Sublist Prototype 14 class Sublist 15 { 16 public: 17 Sublist(vector int> *orig = NULL) 18 : sum(), originalobjects (orig) { }

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

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago