CS136 Assignment 10

Due Monday, Dec. 3 at 11:59 am sharp. There are no late submissions for this assignment.

You may not use recursion in any of your solutions. If applicable, you may use the C implementation of an AVL tree provided for Assignment 7.

Assignment 10 Problem 1 [20 marks]. File scoreboard.c

Implement a scoreboard for a Simon game. Your scoreboard should read a sequence of commands from standard input, and produce output as specified by the command:

Your program must stop after processing 1000 valid commands, or at end of file, whichever occurs first. If a name (or any other symbol) in the input exceeds 20 characters, you must read the entire name, but consider only the first 20 characters (see Sample Input). You may not use any heap storage.

The following files will be available in the marmoset environment, should you choose to use them: readstring.h, readstring.c. You may wish to try out the provided function using test_readstring.c to get a feel for how it works.

Sample Input

score FredFlintstonefromBedrock 10
score Wilma 20
score FredFlintstonefromBe 20
highscore
score Betty 30
highscore
best FredFlintstonefromBedrock
score FredFlintstonefromBedrock 25
best FredFlintstonefromBeyond
best Barney

Output for Sample Input

highscore 20
highscore 30
best FredFlintstonefromBe 20
best FredFlintstonefromBe 25
best Barney ?

Assignment 10 Problem 2 [20 marks]. File: scoreboard.c

Augment your solution for problem 1 to implement the additional command

Sample Input

score Fred 10
score Wilma 20
score Fred 20
highscore
score Betty 30
highscore
best Fred
score Fred 25
best Fred
disqualify Betty
highscore
best Betty

Output for Sample Input

highscore 20
highscore 30
best Fred 20
best Fred 25
highscore 25
best Betty ?
Your program must stop after processing 2000 valid commands, or at end of file, whichever occurs first. You must treat names and symbols longer than 20 characters as described in problem 1. You may not use any heap storage. Again, the following files will be available in the marmoset environment, should you choose to use them: readstring.h, readstring.c.

Assignment 10 Problem 3 [20 marks]. File: scoreboard.c

Augment your solution for problem 2 to implement the additional command

Sample Input

score Fred 10
score Wilma 20
score Fred 20
leaders

Output for Sample Input

leaders Fred Wilma
Your program must stop after processing 3000 valid commands, or at end of file, whichever occurs first. You should treat names and symbols longer than 20 characters as described in problem 1. You may not use any heap storage. Again, the following files will be available in the marmoset environment, should you choose to use them: readstring.h, readstring.c.

Assignment 10 Problem 4 [20 marks]. File: scoreboard.c

Modify your program from Problem 3 so that there is no fixed limit on the size of a name in the input (contrast the Sample Input below with A10P1). The only limit should be the amount of available memory. You may use heap storage.

Sample Input

score FredFlintstonefromBedrock 10
score Wilma 20
score FredFlintstonefromBe 20
highscore
score Betty 30
highscore
best FredFlintstonefromBedrock
score FredFlintstonefromBedrock 25
best FredFlintstonefromBeyond
best Barney

Output for Sample Input

highscore 20
highscore 30
best FredFlintstonefromBedrock 10
best FredFlintstonefromBeyond ?
best Barney ?

Bonus: Assignment 10 Problem 5 [20 marks]. File: scoreboard.c

Make the following modifications to your program from Problem 4: You may use heap storage.

Bonus: Assignment 10 Problem 6 [10 marks]. File: scoreboard.c

Modify your solution to Problem 5 to satisfy the running time constraints given in assignment 8. You may use the C implementation of an AVL tree provided for Assignment 7. You may modify this code however you wish. Recursion is permitted for this question.