CSC 160 Fall 2005 Homework 7
Assigned Dec 1, extended to SUNDAY Dec 18


Read Sections 6.3-6.5 of the textbook (pages 58-71).

Submitting this Assignment
--You may complete this assignment alone or in pairs. However you cannot use the same partner as any previous homework.
--If you do the assignment in pairs, include both last names in each file name.
--For each function, be sure to follow the design recipe.
--In the definitions window, write all the function purposes, contracts, at least three examples, skeletons, and function definitions.
--Submit one Definitions Window which includes all 4 questions. Save as hw7[LastName]Def.scm.
--Submit one Interactions Window which includes the tests for all 3 programs. Save as hw7[LastName]Test.scm.
--For questions 2-4, you can just use the template from Question 1 and change the function name. Therefore, the skeleton and template steps are not required for this assignment ONLY.

The Assignment
1. Recall the who-won function from HW 4. It has a serious disadvantage: since it has the names "Anne", "Bob", and "Charlie" hard-coded in, it'll need to be rewritten every time different candidates run for office. Design a structure to represent a candidate in an election. The structure should contain both the candidate's name and how many votes the candidate received. Click here for a hint.

2. To practice using the template for functions working on candidate structures, develop a function named: add-vote. It takes in a candidate structure and returns a candidate structure just like it, but with one more vote.

3. Now, again using the template for functions working on candidate structures, develop a function named: who-won. It takes in three candidate structures and returns the winning candidate structure. For now, you may assume that there are no ties. (Hint: You won't be able to re-use the old who-won function here, because the old function was specific to the names "Anne", "Bob", and "Charlie".)

4. Develop a function named: winner-name. It takes in three candidate structures and returns the name of the winner. (This can be done using the template, but there's a much easier way, by calling a previously defined function.)


Grading
Candidate Structure Data Definition Define-struct Contracts Example Template
Question 1 /5 /5 /5 /2 /8


Candidate Programs Purpose Contract Examples Definition Testing
Question 2 /2 /2 /3 /15 /3
Question 3 /2 /2 /3 /15 /3
Question 4 /2 /2 /3 /15 /3



Last Modified: 12/13/05