Sie sind auf Seite 1von 2

// set up entity types and functions // primitive data types: string, char, real, boolean, integer declare person()

->> entity; declare cname(person) -> string; declare sname(person) -> string; declare sex(person) -> char; declare student() ->> person; declare matric(student) -> string; declare enrolled(student) -> boolean; declare lecturer() ->> person; declare officeNo(lecturer) -> string; declare declare declare declare declare module() ->> entity; code(module) -> string; title(module) -> string; level(module) -> integer; credits(module) -> integer;

// set up relationships declare lecturer(module) ->> lecturer; declare module(student) ->> module; // set up constraints // total: not null, fixed: unchangable after non-null value assigned constraint cu1 on matric(student) -> unique; constraint cu2 on matric(student) -> total; constraint cu3 on matric(student) -> fixed; constraint cu4 on code(module) -> unique; constraint cu5 on code(module) -> total; constraint cu6 on code(module) -> fixed; // load entities and relationships load "entities/lecturers.csv" into lecturer; load "entities/students.csv" into student; load "entities/modules.csv" into module; load "entities/student relationships.csv" into module(student); load "entities/lecturer relationships.csv" into lecturer(module); // add a new student for a new s in student let sname(s)="Walker" let cname(s)="Nicole" let sex(s)='m' let enrolled(s)=true let matric(s)="07005478" let module(s)={ the m in module such that title(m)="Internet Programming" }; // add a new module to nicole walker for the s in student such that sname(s)="Walker" include module(s)={ the m in module such that title(m)="Software Architecture" }; // remove the internet programming module from nicole walker for the s in student such that matric(s)="07005478" and cname(s)="Nicole" exclude module(s)={ the m in module such that code(m)="CO32018" }; // print for each for each for each students, modules and lecturers l in student print l; l in module print l; l in lecturer print l;

// print each student and the modules they are on

for each s in student for each m in module(s) print s, m; // print the name of any module which is not 20 credits // binary operators: and, or, not for each m in module such that not credits(m)=20 print m; // print each student and the number of credits being taken at level 10 // aggregate functions: sum, min, max, average, count for each s in student print s, sum(c in credits(m in module(s) such that level(m)=10)); // print the students who have more than 80 credits at level 10 // comparison operators: < <= > >= != for each s in student such that sum(c in credits(m in module(s) such that level(m)=10))>=80 print s; // print each student who enrolled and on the Internet Programming module // quantifiers: at least n, at most n, exactly n, all, no for each s in student such that some m in module(s) has title(m)="Internet Programming" and enrolled(s)=true print s; // print each student who is not enrolled on any modules for each s in student such that count(m in module(s))=0 print s;

Das könnte Ihnen auch gefallen