Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, Chegg Expert PLEASE DO AS SOON AS POSSIBLE, REALLY URGENT. All the information is provided before, clicking on NEED MORE INFORMATION, FIRST READ,THANKS. Question

Hi, Chegg Expert PLEASE DO AS SOON AS POSSIBLE, REALLY URGENT. All the information is provided before, clicking on NEED MORE INFORMATION, FIRST READ,THANKS.

Question (See Below) - NEEDS TO BE DONE IN PROLOG:

image text in transcribed

To be Done in Prolog (See Below Example):

image text in transcribed

image text in transcribed

1. A database of Prolog facts for a group of people contains the following two types of facts: name([, , ...)). E.g., male([alex, tom, vic, ...]). female([, ,...)). E.g., female([ann, sara, ella, ...]). age(, ) E.g. age(ann, 66). For these facts write the following rules (you may use Prolog library functions): person(, ). Find the number of female in the database gender(, gender>). Find the name and the gender (male or female) youngest(, ,). Find the name/age/gender of the youngest person meanAge(). Find the mean age of all people in the database The following sample data been added to the database. 1 2 3 4 5 6 AN male(tom, 25). %add data to the database male(tim, 26) male(jerry,24). female(tony, 18) female(lily, 19) female(lisa, 20). The rules have been written for the asked questions male(ton,25) add data to the database naletim, 26) male(erry,24) female(tony, 18) female(lity, 19) female(lisa, 20) person(Name, Age) - male(Name, Age); female(Name, Age) find name and age of person ncount(Count) - indall(x,malel X).L). Length(L.Count) find the count of male using Tindall function fcount(Count) - findall(x, female X).L). Length(.Count) find the count of male using findall function listal(L) - Tindall (X. (malel X) ; female(x)),L) find list of all ages.using find all count_elems([HIT). N. Acc. Count) :- H>N. count this person if he is older than N Accl is ACC + 1. increment the accumulator count elems(T. N. Acci, Count) check the rest of the list count elems([HIT). N. Acc. Count): Ha N. don't count this person if he is younger than N count clems (T. N. Acc, Count) check rest of list without incrementing acc) count elems(1). Count. Count) At the end, instantiate total with accumulator older (Age. Count) - ListAll().count_elens(L.Age, 0. Count) first find ist of all ages and then count function to find the saximum of list: maxlist(1, R. R) Send maxlist([xlxs). Ca. R)- X > Ca, maxlist(xs. X. R) > Co and X will be the max until here maxlist(XIXS]. Co, R) - X Ca, maxlist(Xs. Ca. R) X

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

More Books

Students also viewed these Databases questions