|
1. TRIANGULAR DESIGN The triangle below is generated by following a certain algorithm. Discover this algorithm and use it to write a program which will generate similar triangles of up to 20 rows. 1 232 34543 4567654 567898765 67890109876 7890123210987 Your program must ask the user to input the number of rows, N, and output the corresponding Triangular Design. Test your program for N = 7 and 14. 2. FRACTION SORT A fraction is the quotient of two integers M/N. A pair of integers 2,3 can be used to represent the fraction 2/3. Consider the set of fractions 1/2, 3/4, 1/3, 23/28, 2/9. This set of fractions written in ascending order would appear as follows: 2/9 1/3 1/2 3/4 23/28 Write a program that will sort and print any such set of fractions in increasing order. You can assume the numerators and denominators do not exceed 99 and there are less than 100 fractions in any set. Run your program using the sample data set with the fraction 1/4 added. 3. TENNIS GAME A tennis game between two players has the following rules: 1. A point can be won by either player. 2. A game is won when one player wins at least four points and leads the opponent by at least two points. Write a program to simulate the playing of a game of tennis as follows: The players are labeled 'A' and 'B'. You are asked to enter the probability P (in whole number percent) that A will win any given point. Each point won by player A should be indicated by printing the letter A. If A loses the point, then B wins and the letter B should be printed. The winner of the game is indicated by printing in brackets the appropriate letter. For example, a given game might be indicated by the sequence below where A wins. ABBABAABAA (A) Display the results of N games, where N is entered by the user. After displaying the results of the N games you are to display the summary line: PLAYER A WON ___ GAMES OUT OF ___ Test your program with N = 10 and P = 55, and with N = 20 and P = 60. Sample Run ENTER NUMBER OF GAMES: 10 ENTER % CHANCE THAT PLAYER A WINS EACH POINT: 55 ABBAAA (A) BAABBAAA (A) BBABB (B) ABABBABB (B) AAAA (A) AAAA (A) BAABABBAABABBB (B) BBBAAB (B) AABAA (A) AABBAA (A) PLAYER A WON 6 GAMES OUT OF 10 4. VERTICAL HISTOGRAM Write a program that accepts a set of N digits (0 through 9) as input and prints a vertical histogram (bar graph) representing the occurrences of each digit. Test your program with the set of 13 digits: 1, 7, 2 ,9 ,6, 7, 1, 3, 7, 5, 7, 9, 0 Sample Run ENTER A VALUE FOR N: 12 ENTER 12 DIGITS: 1,7,2,9,6,7,1,3,7,5,7,9 * * * * * *** *** * 0123456789 5. AUTOMATED INFLATION Write a program that will increase all the numbers that appear in a given document by a given percent chosen by the user. Test your program by increasing all the numbers in the following sentence by 12% and 15%. OLD MACDONALD'S 7 COWS GAVE 120 POUNDS OF MILK TODAY. THEY WILL COME HOME AT 4 P.M. All numbers must be rounded off to two decimal places. (Note that all numbers in the original documents can be assumed to be whole numbers.) Sample Run ENTER % INCREASE: 12% OLD MACDONALD'S 7,84 COWS GAVE 134.4 POUNDS OF MILK TODAY. THEY WILL COME HOME AT 4.48 P.M.
|