Course roster management in prolog
Download
1 / 7

Course roster management in Prolog - PowerPoint PPT Presentation


  • 209 Views
  • Uploaded on

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]

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Course roster management in Prolog' - oriole


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
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]

      • In scheme, this data structure will be represented as a list:

        [[“001” “John Smith” 59], [“010” “Amy M. Sosa” 100], [“500” “Mike Harris” 80]]


Course roster management in scheme
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


How to maintain the roster
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).


Menu system
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.


Dealing with input
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


Load from file and store to file
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),


Order of software development
Order of software development

  • Do NOT write the whole program in one shot!!!!

    • One function at a time. Test before considering the next function.


ad