CMSC 201
Programming Project Three
Karaoke
Out: Monday 4/2/07
Due: before Midnight, Sunday 4/15/07
The design document for this project, design3.txt ,
is due: Before Midnight, Sunday 4/8/07
|
The Objective
This project will give you practice using good design techniques, separate
compilation, random numbers, Unix redirection, nested structures, and arrays
of structures.
The Background
Mrs. Evans and Ms. Block have enjoyed going to karaoke every week for quite a
few years now. They always have a good time and have made many friends. To
quote one friend, Stan the (Trash)Man, "You need two kinds of people for
karaoke: singers and clappers." As you'll see from the data file given for
this project, Mrs. Evans is a singer and Ms. Block still refuses to do so.
She is, however, an enthusiastic listener and an avid clapper.
For those of you who are not familiar with karaoke, here is an explanation.
There are karaoke hosts, similar to D.J.s, who can be hired for entertainment.
A karaoke host has all of his own sound equipment, microphones, and a TV
monitor. He buys special karaoke disks that have the music for popular songs,
as recorded by a particular artist with the artists voice track removed, and
the words to be sung added. So when a karaoke disk is played, you hear the
music while the words that are to be sung appear on a TV monitor. As you
progress through the song, the words change color so the singer doesn't lose
his place.
A good karaoke host will have hundreds of disks, indicated by a thick song
book. The song book typically has two sections. The first section has all
the songs available sorted by song title and the second section has all the
songs available sorted by artist. Each line in the book lists the song's
title, artist, and the disk number and track on which it's found.
If you want to sing a song, you must fill out a song slip and give it to the
karaoke host. The slip must contain your name, the song title, and the song
number (which is the combination of the disk name and track number). The
karaoke host keeps the slips in the order he receives them from the singers,
establishing what is known as a "rotation". If a new singer comes in, s/he
is added to the end of the rotation, not into the current position in the
rotation. For example: The original rotation is Karaoke_Jim, Sue, Ben and
Trashman. These 4 singers may have sung many songs each when a new singer,
Dave_T, hands the host a slip while Sue is singing. Dave_T does NOT get to
sing after Sue, but is added to the end of the rotation, making the new
rotation Karaoke_Jim, Sue, Ben, Trashman and Dave_T. Singers get extremely
aggravated by karaoke hosts who do not handle their rotations properly.
Our karaoke host is Karaoke_Jim of KJ Music Factory. He runs karaoke at the
Karaoke House 5 nights a week. He has established himself there as a good
host by providing a large song book, having a fair rotation practice and by
providing his customers with some additional services. Since most singers have
favorite songs that they've practiced and "perfected", a singer will find
themselves filling out song slips for the same songs over and over again, week
after week. Karaoke_Jim pampers us by keeping a database of each of his
regular singers' songs and providing us with individualized pre-printed song
slips.
The Task
Your task is to simulate an evening of karaoke at the Karaoke House by using
the data provided in the data file called karaoke.dat. You must use
Unix redirection to read the contents of this file into your program. Since
the output from your program will be quite large, I suggest that you also use
Unix redirection to capture the output into a file, which can then be viewed
using the Unix command more.
Since you are Jim's helper, your program will have to print out slips for the
singers before the evening begins.
To simulate the evening, you'll print out each singer's name, what song s/he
sang and its song number in the order that they were sung. A singer is to
randomly choose a song from his list of songs but cannot sing the same song
again that evening.
In order to make sure you are reading from the file properly and to later make
sure that your program has kept track of the number of times sung, etc., you
should have a function that prints out all of the information for each singer
and each of his/her songs. See the sample output file for details.
More details
- You must use the following structure definitions :
typedef struct slip
{
char singer[SINGER_NAME_SIZE];
char title[TITLE_SIZE];
char songNumber[SONG_NUMBER_SIZE];
int sung;
} SLIP;
typedef struct singer
{
SLIP slips[NUM_SLIPS];
int timesSung;
} SINGER;
where,
- SINGER_NAME_SIZE needs to be #defined to be 15,
- TITLE_SIZE needs to be #defined to be 30,
- the member songNumber is string that is comprised of the
disk name, a dash, and the track number (i.e. DK046-15, where
DK046 is the disk name and 15 is the track number),
- SONG_NUMBER_SIZE needs to be #defined to be 12,
- sung is a boolean, holding 0 for not sung yet this evening
and a 1 for has been sung this evening,
- NUM_SLIPS needs to be #defined to be 10 for this data file.
- and timesSung should be set to 0 originally and incremented
every time the singer sings a song.
- There are 10 singers in the data file and each singer has 10 slips.
Although each line of the data file contains the singer's name, a song
title, and a song number, it does NOT contain the 0 indicating that the
song has not been sung yet that evening. Your program must initialize
this member for each slip. Similarly, your program needs to initialize
the timesSung members of all the structures of type SINGER.
- After reading the information from the data file into your array of
SINGERs and initializing the other members as mentioned in item
#2, your program must print out all of the information. See the sample
output file.
- Next your program must simulate the printing out all of the slips for
each singer. Since there are 10 singers and each singer has 10 songs,
your program will print out 100 slips. Your slips must be printed so
that 2 slips fit side-by-side on an 80-wide screen. This is the most
tedious part of the program and requires significant problem-solving
thought on your part. Therefore, printing of the slips in any other
format will receive NO CREDIT for that part of the correctness section.
Please examine the sample output file,
karaoke.out for the correct format. Your slips should be almost
identical to the sample.
- Next your program should simulate the evening of singing songs.
- Since each singer is to randomly choose from amongst their own songs,
you'll need to use the random number generator. You must seed the
random number generator with a call to time() before
beginning. You should only seed the randon number generator once.
- Since we will be simulating a Friday evening, Karaoke will begin at
8:00 PM and last until 1:30 AM. Since it is always crowded on Friday
nights, we will say that it takes each singer an average of 5 minutes
to make it to the mike, sing their song, and get their applause.
Both the number of hours karaoke lasts and the rate of singers
per hour should be #defined, since they change for other nights.
Using these figures, your program must calculate the number of songs
that will be sung this evening.
- You should assume the rotation is in the order that the singers
appear in the data file.
- Your program should simulate the singer choosing a song randomly
from his/her songs as it becomes his turn to sing. Remember that
songs cannot be repeated in the same evening.
- Your program should then print (in a numbered list ... see output),
the singer, the song s/he is singing and the song number.
- Your program should do whatever bookkeeping is necessary as the song
is sung. (Mark song as sung, increment timesSung, etc.)
- This process should continue allowing the singers to each sing one
song each per rotation in their turn until Karaoke ends for the
evening.
- After the singing is done, you must again print out all of the
information about each singer and each of his songs to make sure that
your bookkeeping was accurate. Again see the sample output file for
an example.
- Be aware that since we are all using a call to time() to seed the
random number generator, your program will produce the singing of the
songs in a different order than the sample and in fact will have a
different order of songs sung for each time you run your program.
The data file
The name of the data file is karaoke.dat
and can be viewed from this link. You should NOT view it and save it
into a file or cut and paste it from the browser into a file. Either of these
methods of obtaining the file may cause there to be extraneous characters in
the file that your program will try to read and disrupt the input of your data.
Instead you must copy the file from my directory into the directory that you'll
be using to work on this project.
Go to that directory and then issue the following command exactly :
cp /afs/umbc.edu/users/b/o/bogar/pub/karaoke.dat .
The space and the . (dot) at the end of the command are necessary and a part
of the command.
Sample Output
Since the output file is enormous, instead of showing the output here, here's
a link to the sample output file, karaoke.out
Sample Compilation & Program Run
linux1[101] gcc -c -Wall -ansi proj3.c
linux1[102] gcc -c -Wall -ansi karaoke.c
linux1[103] gcc -c -Wall -ansi util.c
linux1[104] gcc proj3.o karaoke.o util.o -lm
linux1[105] a.out < karaoke.dat > karaoke.out
linux1[106]
Although your output may look different than the sample output, you should
print out all of the same information.
What to Turn In
You must use separate compilation for this project and should have a
file, called proj3.c, that contains only the function main(). You
should also have karaoke.c and karaoke.h, that contain functions
related karaoke and the prototypes for those functions, respectively. You may,
of course, have other .c and .h files, as you see fit. You should realize that
you will be reusing some functions that you wrote for previous projects and
they should have been in your util.c file. You will be able to reuse the
util.c and util.h files you created without any modification.
Of course, you may always add new modules to util.c if you want.
Submit as follows:
submit cs201 Proj3 proj3.c karaoke.c karaoke.h util.c util.h
The order in which the files are listed doesn't matter. However, you must
make sure that all files necessary to compile your project are listed.
You can check your submittal by using submitls:
submitls cs201 Proj3