Question
C++ please! I am so confused on this assignment, I want to learn as much as I can from this. May you please include //comments
C++ please! I am so confused on this assignment, I want to learn as much as I can from this. May you please include //comments so I can follow what you are doing if that is okay?
Pascal's triangle, named after the French mathematician Blaise Pascal, among its many applications, is used in the areas of binomial theory and combinatorics. The field of combinatorics is the branch of mathematics concerned with the study of finite or countable discrete structures or objects. For instance, given a group of r people, how many different subgroups of n people can be formed? Pascal's triangle provides answers to these questions.
Pascal's triangle can be visualized as a two-dimensional array in which the top half of the array, above the diagonal, is blank. It also has the property that each row begins and ends with a 1, and every other element in the row is the sum of the element directly above it and the element to the left of the one directly above. That is, assuming that r, the number of sub-groups, represents a column in the triangle, and n, the size of the group (or population), represents the rows,
triangle[n][r] = 1: if r = 0 or r = n, and
triangle[n][r] = triangle[n - 1][r] + triangle[n - 1][r - 1]
Here's what that looks like with the array indexes provided for reference:
r
|
n
Using Pascal's triangle, we can determine how many different subgroups of size r can be formed from a group of size n. For instance, if n = 5 and r = 2, we find there are ten different ways of forming subgroups.
Tasks
For this assignment, write a program that determines how many different committees of a given size (r) can be formed from a group of people of a given size (n), the population. To answer this question, your program should create a Pascal's triangle of size thirteen and print out the triangle to standard output. Then it should ask the user for the size of the committees to be created and the number of the people from which those committees should be selected, the population. Each of these values should be validated, ensuring that they are between 1 and 12, inclusive. If they are not, your program should print an error message and request another value. Then your program should print out a message telling the user how many different committees can be formed. You want your program to loop multiple times so that you dont have to run the program over and over again. See sections Output and Expected Output for what is expected.
Source Code
Your program should decomposed into at least three different functions: one to create Pascal's triangle, one to print the triangle, and another to look up the answer to the question: how many committees of a given size can be formed from a group of people of a given size. This last function should return the number of committees to the caller. Because your triangle should be declared in your main() function, you will have to pass this triangle to these functions as a parameter. There may be other parameters passed too, depending on the function.
Output
The output should display the Pascal's triangle created by your program without any indexes or row/column labels, just the values in the triangle. All numbers should be right justified and each column entry should be directly under the previous rows data. Next your program should print out a prompt for the committee size:
Committee size?
If the value entered is not within the correct range, your program should print out this error message:
Committee size must be between 1 and 12 try again.
Your program should then repeat the prompt and the error message until a valid number is entered. Next your program should print out a prompt for the number of people:
Number of people?
If the value entered is not within the correct range, your program should print out this error message:
Number of people must be between 1 and 12 try again.
Your program should then repeat the prompt and the error message until a valid number is entered. Finally, your program should print out the following message:
There are XXX way(s) to form a committee of YY from ZZ people.
where the XXX represents the number of ways, which was looked up in the triangle and can have one to three digits, YY represents the size of the committee, which can have one to two digits, and ZZ represents the number of people from which the committees can be chosen, which can have one to two digits.
The above prompts and inputs should be in a loop where the following question is asked:
Determine another committee creation (y/n)?
If you look at the expected output, below, you see that the committee size and number of persons are asked prior to asking the question above. This lends itself to being a do-while loop.
When the user enters an n or N (be sure to account for upper and lower case characters), your program should print out the following:
Program Complete.
and exit.
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