1 / 7

Course roster management in Prolog

Course roster management in Prolog. Data to be managed A class roster is list of student entries of the form [ ID , name, grade] Example [ “ 001”, “John Smith”, 59] [ “ 010”, “Amy M. Sosa”, 100] [ “ 500”, “Mike Harris”, 80]

oriole
Télécharger la présentation

Course roster management in Prolog

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Course roster management in Prolog • Data to be managed • A class roster is list of student entries of the form [ID, name, grade] • Example [“001”, “John Smith”, 59] [“010”, “Amy M. Sosa”, 100] [“500”, “Mike Harris”, 80] • In scheme, this data structure will be represented as a list: [[“001” “John Smith” 59], [“010” “Amy M. Sosa” 100], [“500” “Mike Harris” 80]]

  2. Course roster management in scheme • The roster management system supports the following functions (in the menu): 0. Reset roster 1. Load roster from file 2. Store roster to file 3. Display roster sorted by ID 4. Display roster sorted by name 5. Display roster sorted by grade 6. Display student info 7. Add a student to roster 8. Remove a student from roster 9. Exit

  3. How to maintain the roster? • Similar to Scheme, variables in Prolog have limited use (but better than Scheme). • Critical data structure is still passing from one function to another. • Functions in Prolog do not return anything, everything is in the function arguments. • The function to print a menu needs to have an argument for the roster. • Menu (roster).

  4. Menu system • Display the menu • Read input from user • can at least remember the input in Prolog. • Perform some operation on the roster and continue. • Do this in Prolog? See t1.pl.txt • Need to have a ‘.’ after each input. • Use “…” for multiple word strings.

  5. Dealing with input • Read 2 items (id and grade) and return the list of just two items just read? read_student_info([A, B]) :- write('\tStudent ID: '), read(A), write('\tStudent Name: '), read(B). See t2.pl.txt

  6. Load from file and store to file • Remember to close the file when it is done. • Like Scheme one write(X) writes the whole data structure, and one read(X) reads the whole data structure out. • Need to put a ‘.’ after the write(X) in order for this to work correctly. telling(Old), tell(File), write(X), write('.'), told, tell(Old),

  7. Order of software development • Do NOT write the whole program in one shot!!!! • One function at a time. Test before considering the next function.

More Related