August 1999
CA208 : 'C' PROGRAMMING

QUESTION 2

Total Marks: 20 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 2

You are to implement a student record database system for an Information Technology course. The system stores one record per student per course. There are four different subjects on the course :   C programming (denoted by CA), Pascal Programming (denoted by AP), C++ programming (denoted by CPP) and Java programming (denoted by JPP).

 

(a) Define a suitable enumerated type type, subject_type, which takes on the value of any of the four subject types denoted.

 

[1]
(b) Declare a suitable data structure StudentRecord, for each student, which is capable of holding the following information:
  • The students name, called student_name, which has a maximum length of 50 characters;
  • The subject_type to which this record refers, called subject;
  • The mark the student achieved in the examination for this subject, called mark.
  • Pointers left and right, which will point to structures of this type to allow creation of a double linked list.

 

[5]
(c) Given the definition of the double linked list which you are to use for storing your records :

typedef struct {
   StudentRecord* leftmost;
   StudentRecord* rightmost;
   Double_linked_list;
}

Write a function
void add_candidate(double_linked_list* mylist, StudentRecord* candidate);
that takes in a StudentRecord, and adds it to the right of the list. You should assume the list being passed in is non-empty, and you should assume that since the candidate parameter being passed in is the same size as the list element being created, a memcpy will allow the structure to be copied once suitable space has been created.

 

[4]
(d) Write a function StudentRecord* remove_candidate(int mark); that will take in the value of a mark, and remove and return the first occurrence in the list that it finds of a candidate scoring that mark. If no candidate is found scoring that mark, the function will return NULL.

 

[6]
(e) Write a function sort_list, that takes a pointer to the list x, and a pointer to an empty list y, and, starting at the maximum mark of 60 and decreasing to the minimum mark of 0, will perform a sort. Each element matching the current mark should be removed from the original list, and added to the new list. The result will be that the list y will contain all of the records which were in x, but in decreasing order of marks.

 

[4]