Answer to Question #184759 in C++ for jainab

Question #184759

Create a class switchboard. Create a function that returns how many possible outcomes can come from a certain number of switches (on / off). In other words, for a given number of switches, how many different combinations of on and off can we have?


1
Expert's answer
2021-04-23T14:14:06-0400
#include <cmath>
using namespace std;

class Switchboard
{
public:
	double getCombNumber(double switchNumb)
	{
		if (switchNumb < 0)//number of switches can not be negative
			return -1;

		return pow(2, switchNumb);//number of combinations of N two state switches (on / off) is equal to 2^N
	}
};

int main()
{
	Switchboard switchbrd;

	double numberOfCombinations = switchbrd.getCombNumber(10);

	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS