/* Name: Toh Weiqing Matric Number: U098494N Description: Generates all the possible combinations using a truth table with some binary notation and selects the highest satisfaction that is within budget. */ #include #include #include #include #include using namespace std; struct item { string item, type; double price; int satis; bool buy; }; void maximise (vector& shoplist, double totalbudget){ float a = 2; int length = shoplist.size(), n= pow(a,length); int count, maxsat = 0, satisfaction, combi; double budget; //Iterate through each combination to find //the combination with the maximum satisfaction. for (int i=1;i<=n-1;i++){ count = i; budget = 0; satisfaction = 0; for (int j=length;j>=0;j--){ if (count>=pow(a,j)){ count = count - pow(a,j); budget += shoplist[j].price; satisfaction += shoplist[j].satis; } } //Records the combination with the highest satisfaction //and is within budget if ((budget<=totalbudget) && (satisfaction > maxsat)){ combi = i; maxsat = satisfaction; } } //Set the optimal combination for (int j=length;j>=0;j--){ if (combi>=pow(a,j)){ shoplist[j].buy = true; combi = combi - pow(a,j); } } //Prints the necessary output cout<<"Buy:"< shoplist; char dummy; int n; double B; item a; a.buy = false; cin>>n; for (int i=0;i>a.item>>a.price>>a.satis>>dummy>>a.type; shoplist.push_back(a); cout<<"woohoo"<>B; cout<