This problem set covers Chapter 4.

Hand Shakes (5 points)

(Exercises #11, Page 249) Suppose we attend a party. To be sociable, when we arrive, we will shake hands with everyone who is already at the party. Write a program that prompts the user for the total number of guests at the party. Using the for statement, your program will compute, and display, the number of handshakes that occur as each guest arrives. Your program should also compute and display the total number of handshakes that occur after all guests have arrived.(Hint Upon arrival, each person shakes hands with everyone that is already there. You can assume that there is only one host for the party).

Name this program HandShakes

Coin Tosses (5 points)

(Exercises #10, Page 249) Write a program that will compute stastics for eight coin tosses. The user will enter either an h for heads or a t for tails for the eight tosses. The program will then display to total number and percentages of heads and tails. Use the increment operator to count each h or t that is entered. For example, a possible sample dialogue between the program and the user might be:

For each coin toss enter either h for heads or t for tails.
First toss: h
Second toss: t
Third toss: t
Fourth toss: h
Fifth toss: t
Sixth toss: h
Seventh toss: t
Eighth toss: t
Number of heads: 3
Number of tails: 5
Percent heads: 37.5
Percent tails: 62.5

Hint: You can use the switch statement to generate the desired output.

Name this program CoinTosses

Exam Scores (5 points)

(Programming Projects #6, Page 251) Write a program that prompts the user for a list of exam scores each in the range 0 to 100. Your program will display the total number of scores entered and the number of grades in each letter-grade category as follows: 90 to 100 is an A, 80 to 89 is a B, 70 to 79 is a C, 60 to 69 is a D, and 0 to 59 is an F. Use a negative score as a sentinel value to indicate the end of the input. (The negative value is used only to end the loop reading scores, so do not use it in the calculations.) For example, if the input is:

98 87 86 85 85 78 73 72 72 72 70 66 63 50 -1

The output would be

Total number of grades = 14
Number of A's = 1
Number of B's = 4
Number of C's = 6
Number of D's = 2
Number of F's = 1

Name this program ExamScores

Asterisks Triangle (5 points)

(Programming Projects #13, Page 253) Write a program that asks the user to enter the size of a triangle (an interger from 1 to 50). Display the triangle by writing lines as asterisks. The first line will have one asterisk, the next line will have 2 asterisks, and so on, with each line having one more asterisk than the previous line, up to the number entered by the user. One the next line, write one less asterisk and continue by decreasing the number of asterisks by one for each successive line until only one asterisk is displayed. For example if the user enters 5, the output would be:

*
**
***
****
*****
****
***
**
*

Hint: Use nested for loops; the outside loop controls the number of lines to write, and the inside loop controls the number of asterisks to display on the line.

Name this program AsterisksTriangle