50 likes | 249 Views
Homework #1: C++ Basics, Flow of Control, and Function Basics. By J. H. Wang Mar. 13, 2012. Programming Exercises.
E N D
Homework #1:C++ Basics, Flow of Control, and Function Basics By J. H. Wang Mar. 13, 2012
Programming Exercises • Write a C++ program that allows the user to repeatedly enter integers until she inputs a 0 (zero). Then, your program should do the following:(a) count the number of positive values and the number of negative values in user input; (b) calculate the minimum and maximum;[Note: Do not count the ending input 0 in the result.][Note: Please do not use arrays because you don’t need them in this exercise.]
Programming Exercises • Write a C++ program that asks the user to input an integer n and computes the value of n! = n*(n-1)*…*2*1. [Note: Please inform the user if the output value would be out of range for the data type that you used (i.e., int or long int).]
You have r identical prizes to give away and a pool of n finalists. The finalists are assigned numbers from 1 to n. Write a function to randomly select the numbers of r finalists to receive a prize from n finalists. Make sure not to pick the same number twice. For example, given n=25 and r=4, picking finalists 3, 15, 22, and 14 would be valid but picking 3, 3, 31, and 17 would be invalid, because finalist number 3 is listed twice and 31 is not a valid finalist number.[Hint: input - n & r, output - a list of r numbers]
Homework Submission • Due: 2 weeks (Mar. 27, 2012) • Submission instructions: • Homework submission Web site at: http://140.124.183.39/oop/ • Account: Please use your student ID as the username and password to login the Web site. • File names: Please name your file according to our homework. For example, HW1.zip or quiz2.rar.