cs3157
spring 2003
homework #2
due monday march 10, by 6am (electronically)

goal.
The goal of this assignment is to solidify your command of C, including advanced topics such as file I/O, structs and typedefs.

This assignment is worth 10 points. Distribution of points is indicated below.

One component of the educational game you are building will involve data collection. This means things like a username and password for each user of your game, usage data (i.e., which portions of the knowledge domain they've touched) and performance data (i.e., an indication of their grasp of the knowledge they've been exposed to). Taken together, this is called a student profile.

In my flashcard example from hw#1, the knowledge domain is the US states and capitals. So the usage data for each user would be those state/capital pairs which the user has been quizzed on. The user's performance data could be a simple statistic: for each state, the percentage of times s/he has correctly named the capital; and for each capital, the percentage of times s/he has correctly named the state. You'll also need an initial value (maybe -1 in this case) to indicate that the user has not yet been quizzed about a given state/capital or capital/state.

Your job for hw#2 is to write, in C, the code necessary for maintaining three data files:

  1. one which contains the domain knowledge (call it "domain.dat"),
  2. one which contains a list of users and their passwords (call it "users.dat") and
  3. one which contains the student profiles data for an individual user (call it "<username>.dat", e.g., "sklar.dat").

In the "domain.dat" file, for each element of your knowledge domain you will need to store the following (for example):

This is just a suggestion, but what you do need to have is a way of storing the domain knowledge so that you can keep track of which portions of the domain the user has been exposed to, as described below.

In the "users.dat" file, for each user, you need to store the following:

In the individual student profile files (one for each user in "users.dat"), you will need to store the following (for example):

FIRST: print out the timesheet and keep track of how much time you spend doing the tasks outlined below.

1. design.(2 points)
You need to begin with a design document. Include in the design document a description of the domain knowledge data you are going to store and how you are going to store it (1 point) and a description of the user data you are going to store and how you are going to store it (1 point).
If you make any changes to the game as described in your first homework, you must document these changes here.
This documentation should be 1-2 pages, 10-point font. It must be complete -- so you need to be CLEAR and CONCISE. You MUST print out the documentation and bring it to class on the due date.

2. define your data structures.(2 points)
You must define two data structures: one to store the domain knowledge (1 point) and one to store the student profile (1 point). Hint: use typedef and struct. You must have a way to store profiles for multiple students (hint: use an array). Create these definitions in a header file (i.e., a .h file, e.g., sklar.h).

3. build the program. (6 points total)
You need to write a program in C that does the following:

  1. Write a login function that prompts the user for her username and password, reads her username and password and validates them by checking the "users.dat" data file for a match with her username and password. You can translate into C any pertinent aspects of the Java code you wrote to do this in your first lab. You should be able to handle new users. This function should be called by the main() and should return an indication of whether the login was successful or not. (1 point)
  2. Write a function that takes a username as an argument and returns a pointer to a structure that contains the user's student profile data. The function should open the user's student profile data file and load the data from the file into the structure, and then return a pointer to the structure. The program should behave sensibly for new users (in case a student profile data file does not exist for the user). (1 point)
  3. Write a function that reads the contents of the domain knowledge data file and returns a pointer to a structure that contains the domain knowledge. Your program should do something sensible (like quit) if it can't find the domain knowledge data file. (1 point)
  4. Write a function that prints the contents of the student profile data structure on the screen. Note that this won't be used during the actual game, but it will be really useful for debugging. (1 point)
  5. Write a function that prints the contents of the domain knowledge data structure on the screen. Again, this won't be used during the actual game, but it will be really useful for debugging. (1 point)
  6. Write a main() controlling program that calls the login function and subsequently the function to read in the user's student profile data and the domain knowledge data (if the login is successful). The main should then call the functions that write the contents of the student profile data structure and the domain knowledge data structures to the screen. (1 point)

Name your program with the main() in it: hw2<your-cs-username>.c, so for example, mine is called hw2sklar.c.

4. submit.
You need to submit your program in two ways: electronically and hard copy.

  1. electronically
    Follow the submission instructions.
  2. hardcopy.
    (1) Print out the homework template cover page and fill it out.
    (2) Print out the timesheet and fill it out.
    (3) STAPLE the cover page, timesheet and hardcopy of your documentation together.
    (4) Make sure your name and CUNIX ID are on all the papers you hand in!
    (5) Bring all this to class on the day the assignment is due and deposit it in the homework box at the front of the classroom within the first 5 minutes of the class (by 1.15pm).