Home
Netbeans Eclipse Qt Java
Games
College of Engineering Aeronautics and Astronautics Agricultural and Biological Engineering Biomedical Engineering Chemical Engineering Civil Engineering Construction Engineering and Management Electrical and Computer Engineering Engineering Education Engineering Professional Education Environmental and Ecological Engineering Industrial Engineering Materials Engineering Mechanical Engineering Nuclear Engineering
EPICS (Engineering Projects In Community Service) First-Year Engineering Program First-Year Engineering Honors Program Global Engineering Program Minority Engineering Program Professional Practice (Co-Op) Program Women in Engineering Program
College Administration Schools Programs All Groups All People ECN Webmail
Purdue Home

ECE 264 Spring 2010

Individual Programming Assignment 2

Student Database

Notice: The programming assignments are graded by machines.  Your program will only be graded based on input and output.  No one will look into your code and give you partial credit.  If your output is incorrect for every test input, you will receive zero, no matter how minor the errors are.  Therefore, it is crucial that you read this specification very carefully and follow every rule.


Purpose:

You are keeping track of the students in a school by their last name and ID number.  Write a program that creates and manages a student database. In this programming assignment, you learn how to handle data using a structure (or structures) and handle unknown sizes using a linked list (or linked lists). You also learn how to distinguish different strings and extract information from the strings.  The input data comes from a file. Since this file can be very large, your program can read the file only once.

Input and Output

You can do three things with your database.  You can ADD, SEARCH, and REMOVE students in the database.  All inputs and outputs will use text through files.  Students may have the same name since you are only inputting last name.  ID numbers will be unique.

The input file may be arbitrarily long. Each line can have one of the five following formats:

  1. A ID_number Student_name
  2. S ID_number
  3. S Student_name
  4. R ID_number
  5. R Student_name

The first command adds a entry into the database.  The second command searches for a student based upon the ID number and returns the name of the student associated with the ID number.  The thrid command searches for a student based on the name and returns the ID number.  It is possible that multiple people have the same name, your program has to print EVERY ID number associated with that last name.   The ID's should be printed in order of when they were entered into the database.  The fourth command removes the student who has the ID number from the database.  The last command removes the student from the database who has the accompanying name.  Since multiple students may have the same name, your program has to remove ALL students with that name.  It is possible that a student leaves and comes back.  If that is the case, treat the student as a new student. 

 

Sample Input/Output

The list of commands

A 1 Hill
S 1
S Hill
A 2 Moon
S 3 
A 3 Moon
S Moon
S King

would give the output

Hill
1
ID not found
2
3
Name not found

Colors indicate input/output correspondence.

Code

A project has been created for you with a sample structure.  Please check out the code by using the following command on a UNIX shell:

svn checkout http://purdue-wl-ece264-assignment.googlecode.com/svn/trunk/2010/IPA2 purdue-wl-ece264-assignment-read-only

The project contains the following files:

  • ipa2.c  /* a C program that provides the structure of IPA2, please fill in the missing code */
  • student.c /* a C program that provides the structure of IPA2, please fill in the missing code */
  • student.h /* a C program that provides the structure of IPA2, please fill in the missing code */
  • Makefile  /* create executable and test the program, read the comments for the options */

You may change anything in the provided ipa2.c or write your own.

Assumptions and Requirements

  • The ID numbers are unique and are to be stored as strings. It is unnecessary to check duplicates.
  • A student's name is a single word with no whitespace or special character, for example, Thompson.
  • An ID contains only numbers [0-9]+; a name contains only letters [A-Z][a-z|A-Z]+.

[0-9] means we can choose a number between 0 and 9

[A-Z] means we can choose a letter between  'A' and 'Z'

+ means we can choose one or more (at least one)

[a-z|A-Z] means we can choose a letter between  'a' and 'z' or between 'A' and 'Z'

These are called regular expressions.

  • Each name and ID will be no longer than 20 characters.  Each line in the input file will be no longer than 50 characters.
  • If a student leaves the school, delete all information related to this student and release memory immediately.
  • Your program has to release all allocated memory before it terminates.
  • The main function takes one additional argument as the name of the input file. If this argument is not provided, print "Need file name.\n" and terminate the program with -1 as the return value.
  • If the input file cannot be open, print "Cannot open file.\n" and terminate the program with -1 as the return value.
  • The program must be able to distinguish the five types of inputs described above. If a line is not in one of the five types, ignore this line (this should not occur in the input file).
  • If a line wants to add a student, store the student's name and ID number.
  • If you search for a student's by name, be sure to print the ID number of every student who has that name.  
  • If you want to delete a student by name, be sure to delete all the students who have that name.
  • Your program can read the input file only once. It cannot read the whole file to determine the length of the file and then process the file. The program cannot call fopen twice nor use fseek. Neither can you use anything like ungetc.  If such attempts are detected in your program, you will receive zero automatically.
  • Your program must allocate and release memory while processing the file. The program cannot allocate a fixed-size memory at the beginning of execution.
  • You must use dynamic memory allocation.  Do not forget to free memory instantly when "R"(remove) input is encountered.  The grading test will run under limited amount of memory.  If you do not use memory efficiently, you may encounter "out of memory" failure and you might receive very low grade.

What to submit?

  • The source code (including all .c and .h needed to generate the final executable). You must use at least three files (one .h header file and two .c source files.)  You will receive zero if everything is in a single file. Of course, you cannot submit three files and two of them are empty.  You can have more files if necessary.
  • Makefile to create the executable. Name the executable as ipa2 (not IPA2, not pa2, not ipa2.exe, or anything else). You will receive zero if your submission has no Makefile. The file name must be Makefile (This is a widely accepted convention.); any other names will be rejected.
  • README to explain what you have done and how you do it. You need to explain how you store the activities, how to remove activities and how to find the answer for each question. The file name must be README, not readme, not Readme, not README.txt, not README.pdf, nor README.doc.
  • Do not include object files, executable files, sample input, or sample output.
  • You may upload the files as a zip package containing the necessary files (source files, header files and Makefile).  You can name the source files, header files and the zip package arbitrarily, but make sure that the target executable of the Makefile is named "ipa2" (all lower-case).  You will receive zero if there is no executable named "ipa2" after running "make".

Grading (total 6 points)

This programming assignment will be graded by another program. Make sure your program's output is exactly the same as specified. Any deviation from the specification will likely lose points.

  • 1: report errors for missing one argument or the file cannot be open.
  • 1: can read the input file line by line. If your program cannot store the activities nor answer the questions, print the input file. If your program can store the activities and answer questions, do not print the file.
  • 2.5: can add students into database and find students by both name and ID number and print the proper output
  • 1.5: can delete students by both name and ID number and removes them from the database properly
  • -0.5: for each warning message reported by -Wall -Wshadow.
  • -3: memory leak reported by valgrind. The program has to release allocated memory before the program terminates.
    • For self-checking:  You must receive "no leaks are possible" at the end of the valgrind report to pass the memory test.
    • You must also close all open files.
  • You will receive zero if your program contains one or multiple syntax errors during tests.
  • You will receive zero if your program cannot run on ecelinux##.ecn.purdue.edu.
  • You will receive zero if the program does not dynamically allocate or release memory. If you allocate a large array, regardless of its size, you will receive zero. You must use a dynamic structure (such as a linked list).
  • The lowest score is zero. You will not receive a negative score.

Notice: The programming assignments are graded by machines.  Therefore it will only be graded based on input and output.  No one will look into your code and give you partial credit.  If your output is incorrect for every test input, you will receive zero, no matter how minor the errors are.  Therefore, it is crucial that you read this specification very carefully and follow every rule.

No re-grade request will be accepted for programming assignments since the grade given by machine is deterministic.

Late Policy

Late Submissions

Each assignment is due at 10:59AM on the corresponding deadline.

  • Before the deadline, you can submit and resubmit as many times as you wish. You will receive the grading result soon after submission. If you submit multiple times, your score is the highest among all submissions.
  • The time is determined by the server's clock, not your watch.
  • You must submit early. Sometimes the Internet can be slow. If you wait until a few minutes before the deadline, it is very likely that you will miss the deadline. Another common mistake is submitting wrong files when the deadline is too close.
  • Do not send your assignment by email because it is late. Email submission is ignored.
  • Every assignment has a no-penalty extension of 5 hours. The extension is not a new deadline. The extension is provided to accommodate unexpected problems, such as slow network. The extension should be sufficient for you to come to school and submit an assignment, if your home computer breaks.
  • If Purdue cancels classes on a submission deadline, the deadline is extended to one day after classes resume.
  • If the server is down within 12 hours of the deadline, the deadline will be extended by 24 hours.
  Time Penalty
Deadline 10:59 AM D day -
Extension 3:59 PM D day -
Late Submission 3:59 PM D + 1 day 1 point
3:59 PM D + 2 day 2 points
3:59 PM D + 3 day 3 points
3:59 PM D + 4 day 4 points
after 3:59 PM D + 4 day 6 points

Q: Why is the submission deadline set to 10:59AM?  Some students are in lectures at that time.

A: If the grading server breaks, ECN may provide timely assistance to solve the problems. If you have a lecture, please submit earlier.

Q: I submit before the deadline and obtain 3 points.  I submit again the next day and obtain 5 points. What is my score?

A: Your second submission becomes 4 points due to the late penalty. Since it is higher than 3, your score is 4.

Q: If I am sick for a whole week, can I receive an extension?

A: If you provide appropriate documents showing that it is impossible to do the assignment, an extension may be granted.

Privacy and Grade Report

Purdue prohibits sending grades by email. Hence, we have to encrypt your grade report. At the beginning of the semester, you are asked to provide a passphrase to encrypt any reports sent to your Purdue mailbox.  The passphrase should be provided only once through Blackboard.

If you do not provide the passphrase, your grade is not affected but you will not receive a grade report by email. You have to wait for the teaching staff to record the grade in Blackboard.

Policy Handling Dishonest Behavior:

You will receive F in this class if you cheat. Your case will always be reported to ECE main office. There is no exception. If you help a student cheat (such as giving your code), you will also receive F. If you want to help a classmate, tell the person to talk to the instructor or the teaching assistants.   You are responsible protecting your assignments. Do not leave a computer unattended. Do not throw away the printout of your programs.

Do not copy code from your classmates or from the Internet.

You must understand that you cannot cheat forever. If you cheat, you will get caught, sooner or later.

You are allowed to use the code given to you by the instructor or generated snippets using the tools approved by the instructor. You are not allowed to download code from the Internet and claim the code as yours. If you discover useful code, you must (1) announce the code in Blackboad Discussion so that everyone in the class is aware of the code or (2) request the instructor's written approval or (3) describe with sufficient details where the code comes from and how you use it in your README file. You must request the code owner's permission to use the code and you must cite the source in your submission. You are not allowed to purchase code from, for example, getacoder.com.

There were cases when students claimed they "accidentally" submitted code from the Internet because these students were "studying" the code. In all these cases, the students were considered cheating and received appropriate penalty.  It is not possible to "accidentally" submit the code that is not written by you. If it is your code, you must have spent many hours writing the code. You will treat the code with the greatest care. You will check, double check, and check again before submission. If you have spent so much time on an assignment, you will not accidentally submit wrong code.  "Accidentally submitting wrong code" is an invalid defense and you will receive F in this class.

You should know that advanced tools are available checking programs' similarities. These tools can detect programs of similar structures, even if you rename variables or change for to while (or many other techniques to disguise). These tools have successfully detected many cheating cases.  The very fact that you consider to cheat indicates your lack of programming skills. Hence, you do not have sufficient knowledge to defeat these similarity checkers. If you need help, please talk to the instructor or the teaching assistants, or post your questions in Blackboard Discussion. Do not ask your classmate or anyone that took this course to give code to you.  The submissions from multiple semesters will be checked.

Performance

The score of your program is not determined by its performance. However, your program has to be "reasonably fast" so that it can be graded. If your program takes longer than 100 times of the sample solution, your program will not be graded and you will receive zero. The sample solution takes 50 milliseconds for an input file of 1500 lines. Your program cannot take more than 5 seconds for a similar input.

Do not use scanf or anything that requires inputs from keyboard.  This will cause timeout while your program is being graded and you will likely receive zero.

Hint

C provides a function sscanf to check whether a string has a particular format. Suppose oneLine is a string (char array) "A 1032034 Johnson". The following statement is true

char IDnumber[21];
char lastname[21];

if (sscanf(oneLine, "A %S %s",  IDnumber, lastname) == 2)
{

    ...

}

The function sscanf checks whether oneLine starts with A and followed by two additional strings (with no whitespaces).  If the two "placeholders" are matched successfully, the function returns 2, the number of matching placeholders.  You can use sscanf in a way similar to scanf to check other types of inputs.