Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective Recursive Functions Project The formula for computing the number of co

ID: 3809845 • Letter: O

Question

Objective Recursive Functions Project The formula for computing the number of combinations that result from choosing r different items from a set of size n is n! C (n,r) (n -r where the factorial notation is defined as Develop a recursive version of the combinations formula C (n r) and write a recursive function that computes the value of the formula. Add the function as a subfunction of a driver function that tests it. Overall you project will consist of the project function, the printHeader function, an input function that will prompt the user for n and r and error check that r S n, your recursive combinations function, and an output function. Note: Do not use the factorial function that we developed in class as a part of your program. Hint: Write out the calculation for several small combinations such as C(5,3) and C 7, 4) and then simplify the calculation as a repeated product of fractions.

Explanation / Answer

//#include"Combinations.h"
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;

class Combinations
{
public:
   int n, r;
   int result;

   Combinations();
};

int Arr[20][20];
void printHeader(string s1, string s2, string s3, string s4);
void getInputs(int &var1, int &var2);
int getN(void);
int getK(int n);
int calcCombinations(int var1, int var2);
void printResults(Combinations);
bool isInRange(int inData, int min, int max);

void printHeader(string s1, string s2, string s3, string s4)
{
   cout << s1 << " " << s2 << " " << s3 << " " << s4 <<endl;
}

void getInputs(int &n, int &r)
{
   cout << "Enter values of n and r" << endl;
   cin >> n >> r;}

}

int getN(void)
{
  
}

int getK(int n)
{
  
}


bool isInRange(int inData, int min, int max)
{
   bool inRange = 0;
   bool s = (inData < min);
   bool t = (inData <= max);

   inRange = s * t * 0 + (1 - s) * t * 1 + (1 - s) * (1 - t) * 0;
   return inRange;
}

// recursive method
int calcCombinations(int n, int r)
{
   if (r == 0 || r == n){
       return 1; //terminate
   }
   else{
       return calcCombinations(n - 1, r - 1) + calcCombinations(n - 1, r); //recursive calls
   }
}

void printResults(Combinations obj)
{
   cout << obj.result << endl;
}

int main()
{
   //Combinations obj;
   printHeader("Your Name", "CMPSC 121", "Date", "Program Description");
   Combinations arrangements;
   int n, r;
   getInputs(n, r);
   arrangements.n = n;
   arrangements.r = r;
   arrangements.result = calcCombinations(arrangements.n, arrangements.r);
   printResults(arrangements);
}