CS 35
Program 4
due by midnight Tuesday 20 February
The files g88 and b88 in /home/cfk/pub/cs35/week4/new contain the
1000 most popular girls and boys names based on applications for
social security numbers in 1988. Assume that these are
all the names for 1988.
Your task is to read in either the file b88 or g88 and be able to
supply the user with the m most popular names in
descending order, the names in alphabetical order
with their rank attached. For each first letter,
compute how many names begin with that first letter
and be able to list the letters in descending order
of popularity of names that begin with that first letter
and the percentage of names that begin with that letter.
I want you to provide your own sort (you may use stuff from
class or my pub directories). It should be an order nlogn sort.
I want you to do this in Java. But I have an
old C program that does it.
Here are two sample runs of my C program.
You do not have to make yours interactive,
but it is a nice touch.
dill% a.out
This program will read a file of names and
number of occurences. It will assume that the
input file starts with an integer specifying how
many subsequent lines are in the file. Each
subsequent line will consist of a first name
white-space and the number of times that name
was used in the period represented by the file.
There is no assumption made on the intial ordering
of lines in the input file. This program will
compute the rank (1 most popular, 2 second most
popular, etc.) of each name. It will make a
similar computation for the most popular first
initials. The program will then allow the user
to interactively request a display of rank, names,
and frequency in rank order or alphabetical order.
Similar requests may be made for initials.
input file name: pop10
I can output lines consisting of
rank, name, frequency in alphabetical
order or rank order. Similar functions
are available for first initials. Please
enter:
a -- for names in alphabetical order
r -- for names in rank order
i -- for initials in alphabetical order
j -- for intitials in rank order
m -- for a repeat of this menu
q -- to quit this program
please input an a,r,i,j, m(menu), or q (quit): r
Rank Name or Frequency
Initial
1 Michael 64045
2 Christopher 53108
3 Matthew 45822
4 Joshua 42626
5 Andrew 35686
6 David 35246
7 Justin 35008
8 Daniel 34642
9 James 32473
10 Robert 30284
please input an a, r, m(menu), or q (quit): j
Rank Name or Frequency
Initial
1 J 110107
2 M 109867
3 D 69888
4 C 53108
5 A 35686
6 R 30284
7 B 0
8 E 0
9 F 0
10 G 0
11 H 0
12 I 0
13 K 0
14 L 0
15 N 0
16 O 0
17 P 0
18 Q 0
19 S 0
20 T 0
21 U 0
22 V 0
23 W 0
24 X 0
25 Y 0
26 Z 0
please input an a, r, m(menu), or q (quit): a
Rank Name or Frequency
Initial
5 Andrew 35686
2 Christopher 53108
8 Daniel 34642
6 David 35246
9 James 32473
4 Joshua 42626
7 Justin 35008
3 Matthew 45822
1 Michael 64045
10 Robert 30284
please input an a, r, m(menu), or q (quit): q
dill% a.out
This program will read a file of names and
number of occurences. It will assume that the
input file starts with an integer specifying how
many subsequent lines are in the file. Each
subsequent line will consist of a first name
white-space and the number of times that name
was used in the period represented by the file.
There is no assumption made on the intial ordering
of lines in the input file. This program will
compute the rank (1 most popular, 2 second most
popular, etc.) of each name. It will make a
similar computation for the most popular first
initials. The program will then allow the user
to interactively request a display of rank, names,
and frequency in rank order or alphabetical order.
Similar requests may be made for initials.
input file name: b88
I can output lines consisting of
rank, name, frequency in alphabetical
order or rank order. Similar functions
are available for first initials. Please
enter:
a -- for names in alphabetical order
r -- for names in rank order
i -- for initials in alphabetical order
j -- for intitials in rank order
m -- for a repeat of this menu
q -- to quit this program
please input an a,r,i,j, m(menu), or q (quit): j
Rank Name or Frequency
Initial
1 J 349491
2 M 167958
3 A 157540
4 C 153962
5 D 145728
6 R 121734
7 B 108500
8 T 93998
9 S 93550
10 K 69429
11 E 54595
12 N 48338
13 P 39470
14 W 36415
15 G 36376
16 L 33980
17 Z 18799
18 F 14121
19 I 11387
20 H 11257
21 V 9124
22 O 5382
23 Q 2111
24 X 1225
25 U 318
26 Y 0
please input an a, r, m(menu), or q (quit): r
There will be more than 30 lines of output.
Would you like to write to a file (y or n)? : y
output file name: boyout
The file has been generated.
please input an a, r, m(menu), or q (quit): q
dill%
Please mark your calendars now. The registrar has
scheduled the Comprehensive Final Exam for CS35 on
May 14. 9:00am - 12:00n, room TBA.
Plan to attend.