4 Data Representation: Tuples and List of Tuples

A course can be represented by a pair consisting of a course name and a class. Try:
type string == list(char);

type student == string X string;

type class == list(student X num);


c <= [(("Fred","Jones"),66),(("Ali","Mohamed"),76),(("Mary","Ward"),92),(("Colin","Gold"),31)];


type course == string X class;

c1: course;

c1 <=("CS1", c);

c2: course;

c2 <=("Maths", [(("Fred","Jones"),36),(("Ali","Mohamed"),56),(("Mary","Ward"),45),(("Colin","Gold"),71)]);

type degreeprogramme == list(course);

cs <= [c1,c2];


  1. Write a function which returns the number of courses on a degree programme.
  2. Write a function allStudentsInClass:class -> list(student) which returns all students in a class.
  3. Write a function allStudentsOnCourse:course -> list(student) which returns all students on a course.
  4. Write a function allStudentsOnDegreeProgramme:degreeprogramme -> list(student) which returns all students on a degree programme. The easiest way to do it is to append the list of students on each course together and then remove duplicates.
  5. Write a function bestStudentInClass:class -> student which returns the best student in a class. For example bestStudentInClass(c) should return ("Ali","Mohamed").

  6. Write a function bestStudentInCourse:course -> student which returns the best student on a course. For example bestStudentInCourse(c1) should return ("Ali","Mohamed").

  7. Write a function bestStudents:degreeprogramme -> list(string X student) which returns a list of the best students on each course in a a degree programme. For example bestStudents(cs) should return [("CS1",("Ali","Mohamed")),("Maths",("Colin","Gold"))].
  8. Write a function average1:degreeprogramme -> list(string X num) which returns a list of the average marks for each course. For example average1(cs) should return [("CS1",65.25),("Maths",52)].
  9. Write a function average1:degreeprogramme -> list(student X num) that list all students together with there average mark on a degree programme. This function should be sorted in descending order of average mark.

  10. Write a function which works out the number of students on each degree classification.

Sebastian Danicic BSc MSc PhD (Reader in Computer Science)
Dept of Computing, Goldsmiths, University of London, London SE14 6NW
Last updated 2011-03-15