L-37 MCS 275 Wed 11 Apr 2001

Review Sheet for Exam II, Friday 13 April 2001

The aim of this sheet is to help you to prepare for the upcoming exam. While it contains some sample questions, the list of questions is by no means exhaustive.

The material covered are chapters 12 and 13 of the text book. Although no specific questions on materials of previous chapters will be asked, you must be familiar with recursion, since Chapter 12 deals with "recursive" data structures. In addition to the text book, look at

  1. The programs posted at the course web site.
  2. The solution of the quizzes. If you missed the handout, look at the course web site.
  3. Homework exercises, consult the notes of the discussion sessions.
  4. Project solutions. Although you will not be asked to write complete programs, some programming concepts worked out there are very valuable.
The questions below all concern the same data structure (for efficiency of this review), but the questions on the exam will feature separate structures for each question.

Chapter 12: Abstract Data Types

  1. Define a C struct to represent items in a store. An item is represent by its name (a string of <= 20 characters), its price (a float), and the quantity in stock (an integer).
  2. Define a linked list to represent a list of items, defined like above.
  3. Write a recursive/iterative implementation of a program to print the list of items, to count the number of items, to find the most/least expensive item in the list, to find the item with largest/smallest stock, etc...
  4. Give the C implementation of a function to insert a new item to the front of the list, to append a new item to the end of list, to delete the first element, to delete the whole list.
  5. Write a C function to modify the price/stock of an item in the list, given the name of an item and its new price/stock.

Chapter 13: Input/Output and Files

  1. Give the printf instruction to write an item it in the format: name left adjusted in field of width 20; price right adjusted, in field of width 8, precision 2; stock in field of 10 wide.
  2. Give the scanf command to read an item it as given in the format above.
  3. Write a graceful fopen for reading (retrial if file does not exist) and for writing (ask user for permission to overwrite if file already exists).
  4. Write a function to print the content on a file on screen.
  5. Write function to search for the name of an item, and to change its price, after printing its current price. Split this task into two separate functions.