|
1. FREE LUNCH Mac Duffy's is offering a FREE LUNCH to anyone who buys the proper combination of hamburgers, french fries, and soft drinks. Here are the rules: 1.The menu consists of three items: Hamburgers............$1.13 FrenchFries...........$ 52 SoftDrinks............$ 44 2.You must buy at least one hamburger. 3.You can buy at most three of each item. 4.If L is the subtotal for the lunch, then the sales tax is equal to .04xL. 5. If the sales tax comes out exactly to the penny without any fractional part, then the lunch is free. For example, if a lunch cost $2.09, then the tax is .0836 or 8.36 cents which is not exact to the penny. You pay!! 6.The bill is the sum of the tax and the subtotal. Write a program that finds all the ways to get a FREE LUNCH. Sample Run FREE LUNCH AT MAC DUFFY'S ITEM COST NUMBER HAMBURGERS....$1.13 3 FRENCH FRIES...$.52 2 SOFT DRINKS$ .$.44 3 SUBTOTAL $5.75 SALES TAX .23 **EXACT! YOU WIN** BILL $5.98 2. DE BUG The process of debugging a computer program can be simulated with the following model. 1. The probability that a program is debugged on the first try is 1/2. If it doesn't run properly on the first try, debug it and try again. 2. The probability that a program is debugged on the second try is 2/3. If it doesn't run after two tries, debug it and try again. 3. The probability that it is debugged on the Nth trial is N/(N+1). Continue in this manner until it is finally debugged. Write a program that uses this model to simulate the debugging of 1,000 programs. Print a report of the results of your experiment in the format shown in the sample run. Since this is a simulation, your numbers will be different. Sample Run DE BUG SIMULATION NUMBER OF PROGRAMS N DEBUGGED IN N TRIALS 1 47 2 36 3 11 4 5 5 1 AVERAGE NUMBER OF TRIALS TO DEBUG A PROGRAM IS 1.78 3. FACTORIAL POWER The factorial power of a whole number N is defined as follows: N! = 1x2x3x4x(N-1)xN For example, 10! =1x2x3x 4 x 5 x 6 x 7 x 8 x 9 x 10 = 3628800 The length of a factorial is defined as the number of digits its answer. The length of 10! is 7. Write a program that computes the length of N! for any whole number N from 1 to 500. Test your program for N =10, 52, 105. Sample Run ENTER A WHOLE NUMBER? 52 THE LENGTH OF 52! IS 68 4. ALPHABETICALLY SPEAKING Write a program that asks the user for a sentence and reorders the letters within each sentence in alphabetical order as and places them in the same size words as follows: Input: THE PRICE OF BREAD IS $1.25 PER POUND. Output: ABC DDEEE EF HIIINO OP $1.25 PPR RRSTU. Only letters from A to Z are affected. All other characters remain fixed. Test your program with the sentence above and the sentence: THE LICENSE PLATE READ G76-ZA3. Sample Run ENTER A SENTENCE: THE LICENSE PLATE READ G76-ZA3. AAA CDEEEEE GHILL NPRS T76-TZ3. 4. ALPHABETICALLY SPEAKING Write a program that asks the user for a sentence and reorders the letters within each sentence in alphabetical order as and places them in the same size words as follows: Input: THE PRICE OF BREAD IS $1.25 PER POUND. Output: ABC DDEEE EF HIIINO OP $1.25 PPR RRSTU. Only letters from A to Z are affected. All other characters remain fixed. Test your program with the sentence above and the sentence: THE LICENSE PLATE READ G76-ZA3. Sample Run ENTER A SENTENCE: THE LICENSE PLATE READ G76-ZA3. AAA CDEEEEE GHILL NPRS T76-TZ3. 5. SMALLEST LATIN SQUARE A square arrangement of numbers such as 1 2 3 4 5 2 1 4 5 3 3 4 5 1 2 4 5 2 3 1 5 3 1 2 4 is a 5 x 5 LATIN SQUARE because each whole number 1, 2, 3, 4 and 5 appears once and only once in each row and column. Of all the possible 5 x 5 LATIN SQUARES that can be generated the one above is the smallest in the following sense: If the five rows of the Latin Square are strung together (top to bottom) the resulting integer: 12345 21453 34512 53124 is the smallest one possible. Write a program that will generate the SMALLEST NxN LATIN SQUARE for any integer N between 2 and 9. Test your program for N = 4 and N = 5. Sample Run ENTER A WHOLE NUMBER BETWEEN 2 AND 9: 5 THE SMALLEST 5X5 LATIN SQUARE 1 2 3 4 5 2 1 4 5 3 3 4 5 1 2 4 5 2 3 1 5 3 1 2 4
|