Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please solve the complete program using the given copy-able format, Thanks! // // Your Name // CMPSC 121 // Date // Description // // If
Please solve the complete program using the given copy-able format, Thanks!
// // Your Name // CMPSC 121 // Date // Description // // If you choose to use a preprocessor directive - ie to turn debugging // notes on an off - you would put them here // #define debug 1 // Pound includes #includeProject 10 Due: April 5, 2017 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, T) (n r)! where the factorial notation is defined as n! Ta (n 1) (n 2) .2.1 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#include #include #include using namespace std; // Class Definitions class Combinations { public: // Integer parameters for the calculation // Integer for the number of combinations // Any other variables would be considered temporary and can be // declared when you use them }; // Function Prototypes void printHeader(string, string, string, string); void getInputs(int &, int &); // Input Function int getN(void); // Input Function for n int getK(int n); // Input Function for k int calcCombinations(int, int); // Calculate the combinations void printResults(Combinations); // Definition of the program function int main(void) { // Call the splash screen function printHeader("Your Name", "CMPSC 121", "Date", "Program Description"); // Create an object to hold the input data and output information Combinations arrangements; // Prompt the user for the input data. Both variables are // passed by reference not value // Call appropriate function to calculate the combinations // Call the appropriate function to print the results by passing the // object return 0; } void getInputs(int &n, int &k) { // GETINPUTS getInputs(int &n, int &k) // is the recursive function used to enter the data for the combinatoric // calculation. // // All variables are passed by reference so that multiple values can be // passed and entered into the program // // This is a wrapper function to simply call the individual input functions // // Name: // Course: CMPSC 121 // Date: // // Call a function to enter n // This function has no input parameters and returns n // Call a function to k - this is passed n because is needs to check // if 0 // it returns k return; // Since n and k are passed by reference there is no return value } int getN(void) { // GETN getN(void) // is the recursive function used to enter the data for the number of // elements in the set. // // Name: Prof. Adams // Course: CMPSC 121 // Date: 30 March 2017 // // Call a function to enter n // This function has no input parameters and returns n cout > n; // Check if the value is at least 0. If not it calls itself recursively bool goodValue = false; goodValue = isInRange(0, 1e99); // if - else as a stopping case if(!goodValue) { // Print an error message cout return n; // Returns n } int getK(int n) { // GETK getK(int n) // is the recursive function used to enter the data for the number of // elements to be selected from the set. // // Name: // Course: CMPSC 121 // Date: // return k; // Returns k } bool isInRangle(int inData, int min, int max) { // ISINRANGE isInRangle(int inData, int min, int max) // is a boolean function that checks if a value is within the limits // The inData is the value to be checked while min and max are the // range. If the data is within the range the function returns true // while if it is outside of the range it returns false // // Name: Prof. Adams // Course: CMPSC 121 // Date: 30 March 2017 // bool inRange = 0; // Set to false as a failsafe bool s = (inData bool t = (inData // Check inRange or not using the step function approach inRange = s * t * 0 + (1-s) * t * 1 + (1-s) * (1-t) * 0; return inRange; } void printHeader(string name, string course, string dueDate, string description) { // PRINTHEADER printHeader(string, string, string, string) is the // function used to hide away the splash screen // // Name: Prof. Adams // Course: CMPSC 121 // Date: 12 March 2017 // // Print the splash screen cout return; } int calcCombos(int n, int k) { // CALCCOMBOS calcCombos(int n, int k) is the // recursive function used calculate the combinations // // Name: // Course: CMPSC 121 // Date: // // Declare the variable for the combinations int combos; // if - else structure to make the recursive call // In the if make the recursive call. In the else // set the stopping case // return the combinations return combos; } void printResults(Combinations comboObject) { // PRINTRESULTS printResults(Combinations comboObject) is the // function used to print the results of the program. It is // passed a copy of the object currently holding the number // of inputs, outputs and the number of combinations // // Name: // Course: CMPSC 121 // Date: // // This function should print the input data // and the results // Does not return anything - thus no variable here return; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started