Question: #include using namespace std; / / Function to calculate permutations ( N choose X ) long long Permutations ( long long N , long long

#include
using namespace std;
// Function to calculate permutations (N choose X)
long long Permutations(long long N, long long X){
long long result =1;
for (long long i =0; i < X; ++i){
result *=(N - i);
}
return result;
}
// Function to calculate combinations (N choose X)
long long Combinations(long long N, long long X){
if (X > N - X) X = N - X;
long long result =1;
for (long long i =0; i < X; ++i){
result *=(N - i);
result /=(i +1);
}
return result;
}
int main(){
//1. Hospital emergency room problem
long long doctors =12;
long long nurses =36;
long long doctorsInBatch =4;
long long nursesInBatch =12;
//1a. Ways to select doctors for the first set of doses
long long waysToSelectDoctors = Combinations(doctors, doctorsInBatch);
cout <<"1a. Ways to select doctors: "<< waysToSelectDoctors << endl;
//1b. Ways to select nurses for the first set of doses
long long waysToSelectNurses = Combinations(nurses, nursesInBatch);
cout <<"1b. Ways to select nurses: "<< waysToSelectNurses << endl;
//1c. Ways to administer the first dose
long long totalPeople = doctors + nurses;
long long waysToAdministerFirstDose = Permutations(totalPeople, doctorsInBatch + nursesInBatch);
cout <<"1c. Ways to administer the first dose: "<< waysToAdministerFirstDose << endl;
//1d. Ways to administer the second dose
long long remainingPeople = totalPeople -(doctorsInBatch + nursesInBatch);
long long waysToAdministerSecondDose = Permutations(remainingPeople, doctorsInBatch + nursesInBatch);
cout <<"1d. Ways to administer the second dose: "<< waysToAdministerSecondDose << endl;
//1e. Total ways to administer all doses
long long totalWays = waysToSelectDoctors * waysToSelectNurses * waysToAdministerFirstDose * waysToAdministerSecondDose;
cout <<"1e. Total ways to administer all doses: "<< totalWays << endl;
cout << "Formula: waysToSelectDoctors * waysToSelectNurses * waysToAdministerFirstDose * waysToAdministerSecondDose
"<< endl;
//2. Bonuses distribution problem
long long employees =23;
long long bonuses =4;
//2a. Ways to distribute different bonuses
long long waysToDistributeBonuses = Permutations(employees, bonuses);
cout << "The number of ways to distribute 4 bonuses to 23 people if different is: "<< waysToDistributeBonuses << endl;
//2b. Ways to distribute identical bonuses
long long waysToDistributeIdenticalBonuses = Combinations(employees, bonuses);
cout <<"If the bonuses are the same, there are: "<< waysToDistributeIdenticalBonuses << endl;
// Test the functions
long long permTest = Permutations(35,12);
cout <<"
Permutations of 35 things taken 12 at a time: "<< permTest << endl;
long long combTest = Combinations(23,11);
cout << "Combinations of 23 things taken 11 at a time: "<< combTest << endl;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!