home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l210 / 1.ddi / ANSWERS.ARC / ANS_143.PRO < prev    next >
Encoding:
Prolog Source  |  1988-06-21  |  2.9 KB  |  86 lines

  1. /*
  2.    Turbo Prolog 2.0, Answer to Exercise on page 143.
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5. */
  6.    
  7. Domains
  8.    name = person(symbol, symbol)  
  9.              /* (First,   Last) */
  10.              
  11.    birthday = b_date(symbol, integer, integer)  
  12.                  /* (Month,   Day,     Year) */
  13.  
  14. Predicates
  15.    check_birthday_month(integer, birthday)
  16.    determ convert_month(symbol, integer)
  17.    get_months_birthdays
  18.    phone_list(name, symbol, birthday)
  19.    write_person(name, symbol, birthday)
  20.  
  21. Clauses
  22.    phone_list(person(ed, willis), "767-8463", 
  23.               b_date(jan, 3, 1955)).
  24.    phone_list(person(benjamin, thomas), "438-8400", 
  25.               b_date(feb, 5, 1985)).
  26.    phone_list(person(ray, william), "555-5653", 
  27.               b_date(mar, 3, 1935)).
  28.    phone_list(person(thomas, alfred), "767-2223", 
  29.               b_date(apr, 29, 1951)).
  30.    phone_list(person(chris, grahm), "555-1212", 
  31.               b_date(may, 12, 1962)).
  32.    phone_list(person(dustin, robert), "438-8400", 
  33.               b_date(jun, 17, 1980)).
  34.    phone_list(person(anna, friend), "767-8463", 
  35.               b_date(jun, 20, 1986)).
  36.    phone_list(person(brandy, rae), "555-5653", 
  37.               b_date(jul, 16, 1981)).
  38.    phone_list(person(naomi, friend), "767-2223", 
  39.               b_date(aug, 10, 1981)).
  40.    phone_list(person(christina, lynn), "438-8400", 
  41.               b_date(sep, 25, 1981)).
  42.    phone_list(person(kathy, ann), "438-8400", 
  43.               b_date(oct, 20, 1952)).
  44.    phone_list(person(elizabeth, ann), "555-1212", 
  45.               b_date(nov, 9, 1984)).
  46.    phone_list(person(aaron, friend), "767-2223", 
  47.               b_date(nov, 15, 1987)).
  48.    phone_list(person(jennifer, caitlin), "438-8400", 
  49.               b_date(dec, 31, 1981)).
  50.  
  51.    get_months_birthdays :-
  52.       write(" First name\t Last Name \t Phone  \t Birth Day\n",
  53.             " ==========\t===========\t========\t===========\n\n"),
  54.       date(_, This_month, _),       % Get month from system clock 
  55.       phone_list(Person, Phone, Date),
  56.       check_birthday_month(This_month, Date),
  57.       write_person(Person, Phone, Date) ,
  58.       fail.                    % fail to get all birthdays
  59.    get_months_birthdays.
  60.  
  61.    write_person( person(First, Last), Phone, b_date(Mon,Day,Year) ) :-
  62.       writef("  %-10\t %-10\t%-7\t%/%/%\n" ,
  63.              First, Last, Phone, Mon, Day, Year).
  64.  
  65.    check_birthday_month(Mon, b_date(Month, _, _)) :-
  66.       convert_month(Month, Month1),
  67.       Mon = Month1.
  68.  
  69.    convert_month(jan, 1).
  70.    convert_month(feb, 2).
  71.    convert_month(mar, 3).
  72.    convert_month(apr, 4).
  73.    convert_month(may, 5).
  74.    convert_month(jun, 6).
  75.    convert_month(jul, 7).
  76.    convert_month(aug, 8).
  77.    convert_month(sep, 9).
  78.    convert_month(oct, 10).
  79.    convert_month(nov, 11).
  80.    convert_month(dec, 12).
  81.  
  82. Goal
  83.   makewindow(1,2,3," This Month's Birthday List ",0,0,25,80),
  84.   get_months_birthdays ,
  85.   nl.
  86.