C++ code only! Objective: In this assignment, you will familiarize with C++ prim
ID: 3798310 • Letter: C
Question
C++ code only!
Objective: In this assignment, you will familiarize with C++ primitive types, raw arrays, and functions. Additionally, you will have to analyze the runtime of your design. You are provided with the signatures for multiple functions. Your task is to complete the functions and solve the appropriate task
Required: bool neighborhoodIsViable (…) This function should take in the customer data and return true if you will break even or profit, or return false if there will be a loss. All input values are positive numbers (aside from chosenCust data). If you will return true, values should be set in chosenCust representing a set of customers making this true.
numCust: number of customers
maxBandwidth: maximum amount of bandwidth you can support (positive number) ***When selecting customers, the total bandwidth requested by the customers should be less than or equal to this maximum***.
#include
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) {
return false;
}
int main() {
//////////////////////////////////////////////
// Change these values to get a new test case.
int numCust = 5;
int maxBandwidth = 150;
int maintenanceCost = 100;
int reqBand[] = {30, 40, 150, 20, 60};
int reqPrice[] = {40, 60, 100, 20, 70};
bool chosenCust[5];
double partialCust[5];
//////////////////////////////////////////////
// Check if neighboorhood is viable.
bool isViable = neighborhoodIsViable(numCust, maxBandwidth, maintenanceCost, reqBand, reqPrice, chosenCust);
int bandwidthUsed = 0;
int moneyCharged = 0;
if(isViable) {
cout << "Viable venture. A set of customers that works: " << endl;
cout << "{" << chosenCust[0];
for(int i=1; i cout << ", " << chosenCust[i];
}
cout << "}" << endl;
for(int i=0; i if(chosenCust[i]) {
bandwidthUsed += reqBand[i];
moneyCharged += reqPrice[i];
}
}
cout << "Bandwidth used by customers: " << bandwidthUsed << ", money paid by customers: " << moneyCharged << endl;
}
else {
cout << "Not viable." << endl;
}
Explanation / Answer
#include<iostream.h>
#include<conio.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) {
return false;
}
int main() {
//////////////////////////////////////////////
// Change these values to get a new test case.
int numCust = 5;
int maxBandwidth = 150;
int maintenanceCost = 100;
int reqBand[] = {30, 40, 150, 20, 60};
int reqPrice[] = {40, 60, 100, 20, 70};
bool chosenCust[5];
double partialCust[5];
//////////////////////////////////////////////
// Check if neighboorhood is viable.
bool isViable = neighborhoodIsViable(numCust, maxBandwidth, maintenanceCost, reqBand, reqPrice, chosenCust);
int bandwidthUsed = 0;
int moneyCharged = 0;
if(isViable) {
cout << "Viable venture. A set of customers that works: " << endl;
cout << "{" << chosenCust[0];
for(int i=1; i< numCust ;i++)
{
cout << ", " << chosenCust[i];
}
cout << "}" << endl;
for(int i=0; i < numCust ;i++)
{
if(chosenCust[i]) {
bandwidthUsed += reqBand[i];
moneyCharged += reqPrice[i];
}
}
cout << "Bandwidth used by customers: " << bandwidthUsed << ", money paid by customers: " << moneyCharged << endl;
}
else {
cout << "Not viable.";
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.