CMSC 201
Programming Project Five

Karaoke Revisited

Out: Monday 4/30/07
Due: before Midnight, Sunday 5/13/07

The design document for this project, design5.txt ,
is due: Before Midnight, Sunday 5/6/07

The Objective

This project will give you practice using good design techniques, separate compilation, command-line arguments, file handling, linked lists and arrays of strings.

The Background

Reread the background section for Project 3. This project builds on that past project.

We used a very simplistic (and unrealistic) approach to the problem of singing karaoke in project 3. In that project we had 10 singers and each singer had 10 songs. All of the singers were present at the beginning of the night and stayed until closing and were taken in the order they appeared in the data file. The data files were also set up so that no singer could sing a song that someone else had already sung, since no song titles were repeated. We all know that it doesn't happen this way.

This project will simulate karaoke in a much more realistic manner. Singers can come in at any time during the evening and be added to the rotation at that time. Singers may also leave at any time and should be removed from the rotation at that time. It is possible that several singers might have the same song in their song list. In reality, the karaoke host will not let a singer sing a song that someone else has already sung that evening.

The Task

Your task is to simulate an evening of karaoke at the Karaoke House by using the data provided in the data files called p5karaoke.dat and events.dat. p5karaoke.dat contains all of the singers that have ever come to the Karaoke House (not really, but you can pretend) and all of the songs they've ever sung there (that part is true). If you look at the file you will see that the format is a singer's name on one line, followed by the number of songs he has done on the next line, and then a song title on the next line and the song number on the next line. The next line will be his/her next song title and the following line will be a song number. This continues until all of his/her songs are listed. The next singer's name then appears followed by the number of songs s/he has and the list of songs and disk numbers, etc. Your program has no way of knowing how many singers there are. Just read until you encounter EOF. For this project, you will be storing the singers' information in a linked list (hopefully called singers). So the first thing you want to do is read from the p5karaoke.dat file and fill up your linked list of singers.

Then you will read from the events.dat file and store the information in an array of EVENTS called events. The events are in order by the time they occur and consist of the time, a singer's name, and whether the singer is ENTERing or EXITing. The first number in the file is the number of events in the file.

Although it might be nice to print out all of the singers slips when s/he first arrives, we'll assume that has already been done to shorten your output.

To simulate the evening, you must keep track of the time. We will be working in intervals of 5 minutes, as before, and assume that a person can sing a song in 5 minutes. The evening of karaoke will be from 8:00 PM until 1:30 AM. All times given in the events file are guaranteed to be on a 5 minute interval. Several events can happen at the same time. You should handle all of the events in the events array for the current time and then let a singer sing in that time interval as well. (See sample output)

A singer is to randomly choose a song from his list of songs but cannot sing the same song again that evening. A singer also may not choose a song from his list that has been sung by someone else that evening. You must have an array of strings of sungSongs that can be checked for the song title to avoid repeats. You must use the song title for this, not the song number, since more than one artist might have recorded a song and those different renditions are considered to be the same song even though they would have different song numbers. If the randomly-chosen song is a song that has already been sung, randomly chose another song.

As new singers arrive (ENTER), they are to be removed from the list of singers and added to the end of the rotation linked list and as they leave (EXIT), they should be removed from the rotation list and put back into the list of singers.

As always, you should have several debugging functions that you can call during the implementation stage of programming to make sure that each list contains what it should, that you managed to read properly from the files, etc.

Since singers now have different numbers of slips, you can no longer just have an array of SLIPs of size 10 in the SINGER structure. You should have a member that contains the number of slips and you'll need to dynamically allocate the space needed to store that many SLIPs. This memory's address should be stored in the structure and can be used as an array. Some of the songs now have longer titles, so the size of a title should now be 40.

More details

The data files

The name of the data files are p5karaoke.dat and events.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 commands exactly :

cp /afs/umbc.edu/users/b/o/bogar/pub/p5karaoke.dat .

cp /afs/umbc.edu/users/b/o/bogar/pub/events.dat .

The space and the . (dot) at the end of the command are necessary and a part of the command.

Sample Compilation

linux1[101] gcc -c -Wall -ansi proj5.c linux1[102] gcc -c -Wall -ansi karaoke.c linux1[103] gcc -c -Wall -ansi util.c linux1[104] gcc -c -Wall -ansi ll.c linux1[105] gcc proj5.o karaoke.o util.o ll.o linux1[106] a.out p5karaoke.dat events.dat

Sample Output

Although your output may be formatted to look different than this sample, your program must print out the same information for the same seed. Here is the output when using the data files p5karaoke.dat and events.dat, and using a seed of 5. linux3[72] % a.out p5karaoke.dat events.dat 5 Your greeting goes here 8:00 - Karaoke Jim arrives 8:00 - Chrissy arrives 8:00 - Kat arrives 8:00 - Karen arrives 8:00 - Karaoke Jim sings "Ain't no sunshine" 8:05 - Chrissy sings "Trainwreck Of Emotion" 8:10 - Kat sings "My heart will go on" 8:15 - Trashman arrives 8:15 - Karen sings "Crazy" 8:20 - Trashman sings "Folsom Prison" 8:25 - Karaoke Jim sings "Write this down" 8:30 - Ben arrives 8:30 - Sue arrives 8:30 - Chrissy sings "Can't Fight The Moonlight" 8:35 - Kat sings "Blue bayou" 8:40 - Karen sings "Breathe" 8:45 - Trashman sings "You Are My Destiny" 8:50 - Ben sings "Make the world go away" 8:55 - Sue sings "I Will Always Love You" 9:00 - Karaoke Jim sings "Mack the Knife" 9:05 - Chrissy sings "But I Do Love You" 9:10 - The Breeze arrives 9:10 - Kat sings "Total eclipse of the heart" 9:15 - Karen sings "I love rock & roll" 9:20 - Holly arrives 9:20 - Trashman sings "For The Good Times" 9:25 - Ben sings "Please help me I'm falling" 9:30 - Jay arrives 9:30 - Sue sings "White Rabbit" 9:35 - The Breeze sings "What Do You Say To That" 9:40 - Dave T arrives 9:40 - Holly sings "Gypsys Tramps & Thieves" 9:45 - Jay sings "Love Of My Life" 9:50 - Dave T sings "You Are So Beautiful" 9:55 - Karaoke Jim sings "Something like that" 10:00 - Chrissy sings "What's Up" 10:05 - Karen leaves 10:05 - Kat sings "You're still the one" 10:10 - Trashman sings "Good Luck Charm" 10:15 - Ben sings "Statue of a fool" 10:20 - JimA arrives 10:20 - Sue sings "Baby One More Time" 10:25 - The Breeze sings "Everything I Do I Do It For You" 10:30 - Holly sings "I Will But" 10:35 - Jay sings "www.Memory" 10:40 - Dave T sings "Takin' Care Of Business" 10:45 - Jay leaves 10:45 - JimA sings "No Place Like Home" 10:50 - Karaoke Jim sings "I melt with you" 10:55 - Chrissy sings "Right Kind Of Wrong" 11:00 - Kat sings "It's raining men" 11:05 - Trashman sings "Running Bear" 11:10 - Ben sings "Love me tender" 11:15 - Sue sings "Teach Your Children" 11:20 - The Breeze sings "Water Melon Crawl" 11:25 - Holly sings "Take My Breath Away" 11:30 - Dave T sings "That's Why I'm Here" 11:35 - JimA sings "Stagger Lee" 11:40 - Karaoke Jim sings "Trouble with never" 11:45 - Chrissy sings "Genie In A Bottle" 11:50 - Kat sings "Love is a battlefield" 11:55 - Trashman sings "Wonder Of You" 12:00 - Ben sings "Could I have this dance" 12:05 - Sue sings "I Will Survive" 12:10 - The Breeze sings "Soul Man" 12:15 - Holly sings "Without You" 12:20 - Chrissy leaves 12:20 - Dave T sings "Prop Me Up Beside The Jukebox" 12:25 - Holly leaves 12:25 - JimA sings "Blueberry Hill" 12:30 - Ben leaves 12:30 - Sue leaves 12:30 - Karaoke Jim sings "Does anyone know" 12:35 - Kat sings "Never" 12:40 - Kat leaves 12:40 - Trashman sings "My Prayer" 12:45 - The Breeze sings "Shake Shake Shake" 12:50 - Dave T sings "You Never Even Called Me..." 12:55 - JimA sings "Behind Closed Doors" 1:00 - Karaoke Jim sings "Living & living well" 1:05 - Trashman sings "Charlie Brown" 1:10 - The Breeze sings "Two Tickts To Paradise" 1:15 - Dave T sings "Me Too" 1:20 - JimA sings "Diggin Up Bones" 1:25 - Karaoke Jim sings "The way" linux3[73] %

Extra Credit

For 5 points of extra credit, sort the array of sung songs and use binary search (rather than linear search) to determine if a song is in the array or not. Submit a file called README that tells the grader that you implemented the extra credit portion.

What to Turn In

You must use separate compilation for this project and should have a file, called proj5.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 either in your karaoke.c file or in your util.c file. Many of you will be able to reuse the util.c and util.h files. You may use the linked list code from the lectures and it will work with only minor modifications.

Submit as in previous projects. Don't forget your .h files.