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?
#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;
}
Comments
Leave a comment