# JAC 444 Workshop 6 solution

\$30.00

Category:

## Description

The bean machine, also known as a quincunx or the Galton box, is a device for statistics
experiments named after English scientist Sir Francis Galton. It consists of an upright board with
evenly spaced nails (or pegs) in a triangular form, as shown in Figure.
Balls are dropped from the opening of the board. Every time a ball hits a nail, it has a 50%
chance of falling to the left or to the right. The piles of balls are accumulated in the slots at the
bottom of the board.
JAC – 444
Write a program that simulates the bean machine. Your program should prompt the user to
enter the number of the balls and the number of the slots in the machine.
Simulate the falling of each ball by printing its path. For example, the path for the ball in Figure
(b) is LLRRLLR and the path for the ball in Figure (c) is RLRRLRR. Display the final buildup of the
balls in the slots in a histogram. Here is a sample run of the program:
The popularity ranking of baby names from years 2001 to 2010 is downloaded from
www.ssa.gov/oact/babynames and stored in files named babynameranking2001.txt,
babynameranking2002.txt, . . . , babynameranking2010.txt. Each file contains one thousand
lines. Each line contains a ranking, a boy’s name, number for the boy’s name, a girl’s name, and
number for the girl’s name. For example, the first two lines in the file
babynameranking2010.txt are as follows:
1. Jacob 21,875 Isabella 22,731
2. Ethan 17,866 Sophia 20,477
So, the boy’s name Jacob and girl’s name Isabella are ranked #1 and the boy’s name Ethan and
girl’s name Sophia are ranked #2. 21,875 boys are named Jacob and 22,731 girls are named
Isabella.
Write a program that asks the user to enter the year, gender, and followed by a name, and
displays the ranking of the name for the year. Here is a sample run:
JAC – 444