Homework 2 Csc309.
Due Monday April 10, 2006 by 11:59pm.
Problem 1
(25 Points)
From the Kalin text.
The expression C(n,r) denotes the number of r-element subsets on an n-element set. For example C(4,2) is 6 because there are six 2-element subsets of a 4-element set. The value of C(n,r) is given by the formula.
Write a program that computes C(n,r) using at least these component functions, which are invoked by main:
input
: prompts the user for two numbers, storing them in n and r , respectivelycheck
: compares r and n . If r > n, check invokes the function errMsg which prints an error message.comb
: computes the above formulafact
computes the factorial. (Done is class, see course homepage)
The function main prints the result
Work incrementally, that is after you write a function test it out. Make up some test cases and check for invalid inputs. Don't forget factorial grows rapidly so use reasonable numbers. Later we will look at another way to deal with large numbers.
Problem 2
(25 Points)
For this problem you will add two functions to statistics.cpp. You must use iterators in each of the functions when interacting with the vector.
max
- returns the maximum temperaturehot
- This function takes in two vectors, the first one the temperatures the other an empty vector. The function fills the empty vector with all the temperatures greater than 80.
Modify main to test these two functions.
Extra Credit
(2 percent)Add another function to compute the standard deviation of the temperatures
Here is a website about the standard deviation. gcseguide.com
Turn in Instructions
Upload each problem to COL