UMBC CS 201, Spring 03
UMBC CMSC 201 Spring '03 CSEE | 201 | 201 S'03 | lectures | news | help

CMSC 201
Programming Project Five

Karaoke Revisited

Out: Monday 4/28/03
Due: before Midnight, Tuesday 5/13/03

The design document for this project, design5.txt ,
is due: Before Midnight, Monday 5/5/03

Added newline to the end of events.dat data file -- You should copy the file again. Thur 5/8 5:15 PM

Extra credit section added Wed 5/7 6:45 PM

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 would sing a song that someone else had already sung. 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 disk number on the next line. The next line will be his/her next song title and the following line will be a disk 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 in 5 minute intervals. 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.

When a singer arrives, s/he is to be removed from the linked list of singers and added to a linked list called rotation. You will no longer have to have a member in the singer structure to keep track of his place in the rotation. His position in the rotation is his position in the linked list of singers. As new singers enter they will be removed from the list of singers and added to the end of the rotation linked list and as they leave they should be removed from the rotation 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. Store only the address of the array and malloc the space for it. You'll need a member that contains the number of songs now. 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/s/b/sbogar1/pub/p5karaoke.dat .

cp /afs/umbc.edu/users/s/b/sbogar1/pub/events.dat .

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

Sample Output

Your greeting goes here Prompting the user for the seed goes here 8:00 - Karaoke Jim arrives 8:00 - Chrissy arrives 8:00 - Kat arrives 8:00 - Karen arrives 8:00 - Karaoke Jim sings "Something like that" 8:05 - Chrissy sings "Little Drummer Boy" 8:10 - Kat sings "Come to my window" 8:15 - Trashman arrives 8:15 - Karen sings "This kiss" 8:20 - Trashman sings "Ring Of Fire" 8:25 - Karaoke Jim sings "Ain't no sunshine" 8:30 - Ben arrives 8:30 - Sue arrives 8:30 - Chrissy sings "Blessed" 8:35 - Kat sings "Blue bayou" 8:40 - Karen sings "Blue" 8:45 - Trashman sings "Magic Moment" 8:50 - Ben sings "Statue of a fool" 8:55 - Sue sings "I Got You Babe" 9:00 - Karaoke Jim sings "Does anyone know" 9:05 - Chrissy sings "Why They Call It Falling" 9:10 - The Breeze arrives 9:10 - Kat sings "Total eclipse of the heart" 9:15 - Karen sings "I just fall in love again" 9:20 - Holly arrives 9:20 - Trashman sings "All In The Game" 9:25 - Ben sings "He stopped loving her today" 9:30 - Jay arrives 9:30 - Sue sings "Imagine" 9:35 - The Breeze sings "Hillbilly Shoes" 9:40 - Dave T arrives 9:40 - Holly sings "Born To Fly" 9:45 - Jay sings "Rope The Moon" 9:50 - Dave T sings "Lost In The 50's Tonight" 9:55 - Karaoke Jim sings "Write this down" 10:00 - Chrissy sings "On A Night Like This" 10:05 - Karen leaves 10:05 - Kat sings "You're still the one" 10:10 - Trashman sings "Town Without Pity" 10:15 - Ben sings "All I have to offer you is me" 10:20 - JimA arrives 10:20 - Sue sings "Strawberry Fields" 10:25 - The Breeze sings "Almost Like A Song" 10:30 - Holly sings "I'll Be" 10:35 - Jay sings "To Love Somebody" 10:40 - Dave T sings "Right Where I Need To Be" 10:45 - Jay leaves 10:45 - JimA sings "No Place Like Home" 10:50 - Karaoke Jim sings "The way" 10:55 - Chrissy sings "You Were Mine" 11:00 - Kat sings "Love is a battlefield" 11:05 - Trashman sings "Oh Boy" 11:10 - Ben sings "Could I have this dance" 11:15 - Sue sings "Frosty The Snowman" 11:20 - The Breeze sings "Hello Dolly" 11:25 - Holly sings "I Will Always Love You" 11:30 - Dave T sings "Alibis" 11:35 - JimA sings "Pop A Top" 11:40 - Karaoke Jim sings "Mack the Knife" 11:45 - Chrissy sings "Right Kind Of Wrong" 11:50 - Kat sings "Do that to me one more time" 11:55 - Trashman sings "I Want You" 12:00 - Ben sings "Make the world go away" 12:05 - Sue sings "Let Me Be There" 12:10 - The Breeze sings "Tennessee River" 12:15 - Holly sings "Magic Man" 12:20 - Chrissy leaves 12:20 - Dave T sings "Don't Let The Sun Go Down On Me" 12:25 - Holly leaves 12:25 - JimA sings "Ain't That A Shame" 12:30 - Ben leaves 12:30 - Sue leaves 12:30 - Karaoke Jim sings "Living & living well" 12:35 - Kat sings "It's raining men" 12:40 - Kat leaves 12:40 - Trashman sings "Mrs. Brown" 12:45 - The Breeze sings "Everything I Do I Do It For You" 12:50 - Dave T sings "You Never Even Called Me..." 12:55 - JimA sings "Release Me" 1:00 - Karaoke Jim sings "I melt with you" 1:05 - Trashman sings "Everybody Loves My Body" 1:10 - The Breeze sings "Love In The First Degree" 1:15 - Dave T sings "Change The" 1:20 - JimA sings "Who's Cheatin' Who" 1:25 - Karaoke Jim sings "Trouble with never"

Sample Compilation & Program Run

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 Although your output may look different than mine, you should print out the same information.

Further Help

I will provide a sample output file that shows the seed and the corresponding correct output for that seed on linux.gl later in the week. Your ordering of events and songs sung should match those shown in that file when you use the same seed.

New Sample Output

linux3[1]% a.out p5karaoke.dat events.dat Your greeting goes here Please enter a positive integer you would like to use as the seed: 6 8:00 - Karaoke Jim arrives 8:00 - Chrissy arrives 8:00 - Kat arrives 8:00 - Karen arrives 8:00 - Karaoke Jim sings "I'm gonna love you forever" 8:05 - Chrissy sings "Words Get In The Way" 8:10 - Kat sings "You're still the one" 8:15 - Trashman arrives 8:15 - Karen sings "This kiss" 8:20 - Trashman sings "Folsom Prison" 8:25 - Karaoke Jim sings "Ain't no sunshine" 8:30 - Ben arrives 8:30 - Sue arrives 8:30 - Chrissy sings "Little Drummer Boy" 8:35 - Kat sings "Love is a battlefield" 8:40 - Karen sings "Crazy" 8:45 - Trashman sings "Cathy's Clown" 8:50 - Ben sings "All I have to offer you is me" 8:55 - Sue sings "Nobody Does It Better" 9:00 - Karaoke Jim sings "Something like that" 9:05 - Chrissy sings "Complicated" 9:10 - The Breeze arrives 9:10 - Kat sings "Total eclipse of the heart" 9:15 - Karen sings "I just fall in love again" 9:20 - Holly arrives 9:20 - Trashman sings "Battle of New Orleans" 9:25 - Ben sings "Love me tender" 9:30 - Jay arrives 9:30 - Sue sings "White Room" 9:35 - The Breeze sings "When I Say I Do" 9:40 - Dave T arrives 9:40 - Holly sings "Ironic" 9:45 - Jay sings "Who's Cheatin' Who" 9:50 - Dave T sings "You Won't Ever Be Lonely" 9:55 - Karaoke Jim sings "Mack the Knife" 10:00 - Chrissy sings "Except For Monday" 10:05 - Karen leaves 10:05 - Kat sings "Come to my window" 10:10 - Trashman sings "Tie A Yellow Ribbon" 10:15 - Ben sings "Welcome to my world" 10:20 - JimA arrives 10:20 - Sue sings "I Will Always Love You" 10:25 - The Breeze sings "Celebration" 10:30 - Holly sings "How Do I Live" 10:35 - Jay sings "On The Other Hand" 10:40 - Dave T sings "T-R-O-U-B-L-E" 10:45 - Jay leaves 10:45 - JimA sings "Please Remember Me" 10:50 - Karaoke Jim sings "The way" 10:55 - Chrissy sings "Take It Like A Man" 11:00 - Kat sings "It's raining men" 11:05 - Trashman sings "Come Go With Me" 11:10 - Ben sings "Please help me I'm falling" 11:15 - Sue sings "House Of The Rising Sun" 11:20 - The Breeze sings "Write This Down" 11:25 - Holly sings "Remember Me This Way" 11:30 - Dave T sings "Wish You Were Here" 11:35 - JimA sings "Behind Closed Doors" 11:40 - Karaoke Jim sings "Living & living well" 11:45 - Chrissy sings "Release Me " 11:50 - Kat sings "Never" 11:55 - Trashman sings "Hundred Pounds of Clay" 12:00 - Ben sings "What's he doing in my world" 12:05 - Sue sings "I Got You Babe" 12:10 - The Breeze sings "Hello Dolly" 12:15 - Holly sings "Listen To Your Heart" 12:20 - Chrissy leaves 12:20 - Dave T sings "Takin' Care Of Business" 12:25 - Holly leaves 12:25 - JimA sings "I Want To Walk You Home" 12:30 - Ben leaves 12:30 - Sue leaves 12:30 - Karaoke Jim sings "Trouble with never" 12:35 - Kat sings "Blue bayou" 12:40 - Kat leaves 12:40 - Trashman sings "You Are My Destiny" 12:45 - The Breeze sings "Most Beautiful Girl" 12:50 - Dave T sings "Keeper Of The Stars" 12:55 - JimA sings "Diggin Up Bones" 1:00 - Karaoke Jim sings "I melt with you" 1:05 - Trashman sings "Hello Darlin" 1:10 - The Breeze sings "Daddy Won't Sell The Farm" 1:15 - Dave T sings "Beth" 1:20 - JimA sings "Ain't That A Shame" 1:25 - Karaoke Jim sings "Write this down" linux3[2]%

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.

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'll probably want to add at least one more function to it. You may use my linked list code and it will work with only minor modification.

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