maxBandwidth is the total your network can support. If you take multiple custome
ID: 3799042 • Letter: M
Question
maxBandwidth is the total your network can support. If you take multiple customers, you need to combine their requests. This is not per person.
maintenanceCost is the total cost to run your network, regardless of the number of customers. If you take 1 person or multiple customers, this is the same.
reqBand: bandwidth customer needs
reqPrice: price customer pay
chosenCust is a return value. You can only return one combination of customers within chosenCust. In the required portion, this should represent a subset of customers that, in total, request at most () maxBandwidth bandwidth in total and will pay, in total, at least () maintenanceCost. Adding up their respective requests should meet these overall constraints.
main.cpp
#
Explanation / Answer
I have edited only a1.hpp with putting the comments at the aside
a1.hpp
#include <iostream>
#include <math.h>
using namespace std;
bool neighborhoodIsViable(const int& numCust,
const int& maxBandwidth,
const int& maintenanceCost,
const int* const reqBand,
const int* const reqPrice,
bool* const chosenCust) {
int currentBand = maxBandwidth;
int currentCost = maintenanceCost;
for (int i = 0; i < numCust ; i++) {
if (reqBand[i] <= currentBand && reqPrice[i] <= currentCost) {
chosenCust[i] = true;
currentBand -= reqBand[i];
currentCost -= reqPrice[i];
}
}
Replace the for loop with while or do while for more columns of data
for (int i = 0; i < numCust; i++){
if(chosenCust[i]){
return true;
}
}
//use while loop or do while loop
int i = 0;//i = 0
while(i<numCust){
if(chosenCust[i]){
return true
}
i++;
}
or
Use//do while loop
int i =0;
do{
if(chosenCust[i]){
return true
}
i++;
}while (i<numCust);
//If you want to terminate the loop
//use the below code
System.exit(1);
return false;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.