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 sjAssume the following:
% loggedin IN tom IN tom OUT tom ^D Error: user tom already logged in
% loggedin IN sj OUT SJ ^D Error: user SJ not logged in
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.
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).
If your cs310 directory is not created on time, please
e-mail the source to your instructor.
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.
loggedin.c.
Name the file exactly as stated (see above).
log.txt
is not enough), some test cases could include:
qual directory should contain:
loggedin.c. If your
cs310 directory is not created on time, please e-mail the
source to your instructor.
typescript from a Unix script
session showing that you tested your code.
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?