CS 310 Qualifying Assignment
Szymon Jaroszewicz
Spring 2001

Due date section 1: Friday, Feb. 1st, morning
Due date section 2: Saturday, Feb. 2nd, morning
("morning" means you have to finish sometime the night before)

We have designed this assignment so that you and we can find out whether you are properly prepared for CS310.

YOU SHOULD BE ABLE TO SUCCESSFULLY COMPLETE THIS ASSIGNMENT ON TIME IF YOU WANT TO TAKE THIS COURSE.

If you cannot do this assignment easily do as much as you can, but DO NOT CHEAT, anybody caught cheating will have to drop the course.

A server keeps a log file containing the information about users logging in and out of the system. The file is organized in the following way: each line contains a word IN or OUT (indicating whether the user logs in or out) followed by a space and a user ID. For example the file log.txt contains:

IN sj
OUT sj
IN tom
IN roger
IN sj
OUT tom

Your task is to write a program loggedin that will read a file in the format described above from standard input, and print on standard output the list of users currently looged in the system. For the example above your program would print

  % loggedin < log.txt
  roger
  sj
Assume the following:
  1. The users can be printed in any order.
  2. User ID is a string of up to 30 characters, case is important.
  3. Before the first line of the log file was written no users were logged on to the system.
  4. Each user can be logged in the system only once, for example you should print an error message in a case like this
      % loggedin
      IN tom
      IN tom
      OUT tom
      ^D
      Error: user tom already logged in
    
  5. You DO HAVE to print an error message when a user who is not logged in logs out, e.g.
      % loggedin
      IN sj
      OUT SJ
      ^D
      Error: user SJ not logged in
    
  6. You DO HAVE to assume that the log file can be of any length, and there can be any number of users (your data strucutres have to grow dynamically)

Suggested solution

What is given below is just a suggestion, feel free to choose your own implementation.

A possible solution is to create a linked list, each node corresponding to a user logged in to the system. When an IN line is read, your program would check if the user is already on the list and if so print an error message. Otherwise the user would be added to the list. When an OUT line is read, your program would check if the user is on the list and if not print an error message. Otherwise the node corresponding to the user would be deleted from the list. After all of the log file is read you program would simply print the contents of every node of the list.

What you should do

Read the following steps carefully, as most of them applies to all homeworks:
  1. Apply for a cs310 account (use the apply command, ask the operator for help in case of problems). After you apply for the account a cs310 subdirectory will be created in your home directory (it may take a few hours).
    • DO NOT CREATE THIS DIRECTORY YOURSELF
    • DO NOT CHANGE ACCESS RIGHTS FOR THIS DIRECTORY

    If your cs310 directory is not created on time, please e-mail the source to your instructor.

  2. Fill in the questionnaire and e-mail it to your instructor.
  3. In your cs310 directory create a qual subdirectory and do all your work there.

    If you start on this project before that directory has been created for you, please protect your code from access by others.

    Name the directory exactly as stated (case matters). This is improtant because the qual. assignment (and most homeworks) will be collected electronically.

  4. Put the entire source code in a file loggedin.c. Name the file exactly as stated (see above).
  5. You should write the program in plain C (do not use any C++ features), it should compile without any errors or warnings. This assignment is PASS/FAIL, but in future homeworks you'll loose points for warnings during compilation.
  6. Make sure to test your program thoroughly (my log.txt is not enough), some test cases could include:
  7. Since the purpose of this exercise is to determine whether you are prepared for this course you should not discuss the material extensively with anyone else. (Later in the term we will encourage these discussions.) Brief conversations are OK, as long as you acknowledge them. Also acknowledge sources for code you borrow (the book, an old cs240 assignment of your own, ...).


Deliverables

Your qual directory should contain:
  1. Your well designed, well formatted loggedin.c. If your cs310 directory is not created on time, please e-mail the source to your instructor.
  2. The file typescript from a Unix script session showing that you tested your code.
  3. A file memo.txt A one page discussion of your experience writing this code. Which parts were easy? Which parts were hard? What problems did you encounter and how did you solve them? Be sure to acknowledge any sources for material you used in your program: what books or notes or friends or projects from another course helped you, and how?