CS1321
Practice Quiz 1


NOTES


Problem 1

  1. Define a structure called buzzcard containing a person's first name, gt number, number of meals remaining, and balance left on their buzz account. Include appropriate Data Definition and Analysis comments.












  2. Construct a buzzcard for Elvis Presley: his gt number is gtuhhuh and he has eaten all of his meals, but he does have $500 left in his account.


  3. Write the template for processing this structure in a function.








  4. How would you determine whether the actual parameter passed into a function is in fact a buzzcard?



Problem 2

You are an agent working at a real estate agency, and you are given the task of making a structure to hold information about houses in your selling district. Your
agency only cares about a few details regarding the houses: the number of acres, the color of the house, if it has a garage or not, and the number of bedrooms.

  1. Create a structure in scheme that will hold all this information.
    [You do not need the data analysis and definition comments]




  2. Now that you have defined your structure in scheme, you need to create two instances of this house structure, filling in the proper information. Any number of acres, any color, true or false for the garage, and any number of bedrooms will do fine.








Problem 3

In an effort to evade the "freshman 15" John created the following structure used to store the number of grams of each energy nutrient in a food:

(define-struct food (carbohydrates protein fat))

  1. Write the template to process this structure.








  2. Now that John has the data, he has asked you to help him figure out a way to maintain his weight. Write a function called called miles-to-run that will determine the number of miles that he needs to run in order to burn off the calories from one serving of a food (carbohydrates and protein have 4 calories per gram while fat has 9). Assume John burns 100 calories for every mile that he runs. Include a formal contract and purpose. Be sure to use good abstraction.



















Problem 4

Write a function which will determine whether a number is even or odd without using the built in divide or remainder function. If the number is even, then function should return the symbol 'even, and if it is odd, return the symbol 'odd. Include the contract and purpose of this function. You may assume the number passed in is a non-negative integer.



















Last Modified: Wednesday, January 30, 2002 8:27 PM by CS1321WWW