Bookmark and Share

Liens sponsorisés

Seniors Level 6 Print E-mail
Written by Administrator   
Saturday, 09 May 2009 23:39

1. TRIANGLES 

Write a program that prints a triangle with sides containing 10 symbols using characters entered by the user. Have the program ask the user for a string of three characters and print out a triangle, similar to the one below, using one character for each side.

 

Test your program with the strings "ABC" and "XYZ"

 

Sample Run

 

ENTER A STRING? ABC

 

C

AC

A C

A  C

A   C

A    C

A     C

A      C

A       C

ABBBBBBBBB

 


 

2. WINNING FORM 

When you flip a coin you win every time it comes up heads and lose if it comes up tails. Assume the first toss is always a head and after four more tosses you note whether you are ahead (more wins than loses). If you begin with a win and end up ahead you are in WINNING FORM.

 

What are the chances that when you toss a coin 5 times and win on the first toss that you are in WINNING FORM?

 

Write a program that will simulate the experiment of tossing a fair coin four times after the first head and checking if you are in WINNING FORM. Remember to begin with a win. To estimate your chances of this happening, repeat the experiment 1000 times and report the number of times you are in WINNING FORM.

 

Sample Run

Beginning with 1000 wins on the first toss, you are in WINNING FORM a total of 688 times.

 


 

3. MAKING CHANGE 

There are many ways you can receive change for a given amount of money. Write a program that will display the number of different ways you can make change totaling a given amount of money. The money system consists of: pennies, nickels, and dimes.

 

                        5 pennies  = 1 nickel

                        2 nickels  = 1 dime

 

All money is expressed in terms of pennies. Thus 23 in this system means 23 pennies. Print your results as shown in the sample run.

 

Test your program with 23 and 36.

 

Sample Run

 

Enter an amount in pennies? 23

 

 #    Pennies Nickels  Dimes

 1     23      0        0    

 2     18      1        0    

 3     13      2        0    

 4     8       3        0

 5     3       4        0    

 6     13      0        1    

 7     8       1        1    

 8     3       2        1    

 9     3       0        2

 

There are 9 ways to make change totaling 23 pennies using pennies, nickels and dimes.

 

 

 

4 FRIDAY THE 13TH

When will Friday the 13th occur in 1990? Write a program that will find all months in 1990 in which the 13th falls on a Friday.

 

You need to know the following.

 

1. January 1, 1990 was on a Monday.

   2. Thirty days has September, April, June, and November, all the rest have 31 except for February which has 28 except in leap years when it has 29.

3. 1990 is not a leap year.

 

Note: To make it fair for everyone, you may not use any built-in date functions from your computer language.

 

Sample Run

In 1990, Friday the 13th occurs in the months:

APRIL

?

?

 

 

 

5. WORD CHAIN 

A Word Chain is a sequence of words which differ by one letter. The set of words {MOM, TIP, TAP, SIP, MAP, MOP} contains the word chain 

 

MOM MOP MAP TAP TIP SIP

 

where each adjacent pair of words differ by exactly one letter. Write a program that finds a word chain in a set of words beginning with the first word in the set. 

 

 

Find the word chain in the set {HEAL, DEAD, DEER, HEAD, BEER, DEED}

 

[You may enter your words in the program in DATA statements or place then in an array but you must enter them in the same sequence they are given. The program must find the word chain. You may assume that exactly one word chain exits for a set of words.]

 

Sample Run

 

MOM MOP MAP TAP TIP SIP

is the word chain.

 

 

Liens sponsorisés