Practice Problem 1: Algorithms

Objective: To write detailed algorithms for common tasks

Here's an example of a pseudo-code algorithm to buy the textbooks for a class, using parameters for the course number and section number:

To buy the books for CS 111A Section 001, you would write:

BuyTextBooks(CourseNumber="CS 111A", SectionNumber="001");

To buy the books for English 1A Section 581, you would write:

BuyTextBooks(CourseNumber="ENGL 1A", SectionNumber="581");

Here is the generic algorithm to buy textbooks:

BuyTextBooks(CourseNumber, SectionNumber):

  1. Go to the college bookstore.
  2. Pick up a shopping basket.
  3. Find the section for textbooks.
  4. Locate the shelf labeled for CourseNumber and SectionNumber.
  5. Repeat for each required book for this course section:
    1. Determine the required book’s title and author.
    2. Pick up a copy of the required book and put it in your shopping basket.
  6. Repeat for each optional book for this course section:
    1. Determine the optional book’s title and author.
    2. Pick up a copy of the optional book.
    3. Look at optional book to decide if you want to buy it:
    4. If you want to buy the optional book:
      1. Put the optional book in your shopping basket.
    5. If you do not want to buy the optional book:
      1. Put the optional book back on the shelf where you found it.
  7. Go to the cash register.
  8. Pay for the book(s) in your shopping basket.
  9. Exit the bookstore with your books.
Using this example as a guide, your assignment is to write algorithms with 10-20 steps for each of the following tasks. You may write your algorithms using pseudo-code, logic diagrams, flow charts, or any method you wish. You can turn in your homework on paper, or upload it to Insight. (All future assignments must be uploaded to Insight.) Paper submissions may be slid under my office door (Batmale 462) if I'm not there.

Return to main CS 111A page