Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lists and Backtracking family(person( john, cohen, date(17,may,1990), unemployed), person( lily, cohen, date(9,may, 1990), unemployed), []). family(person( john, armstrong, date(7,may,1988), unemployed), person( lily, armstrong, date(29,may,1961), unemployed),
Lists and Backtracking
family(person( john, cohen, date(17,may,1990), unemployed), person( lily, cohen, date(9,may, 1990), unemployed), []). family(person( john, armstrong, date(7,may,1988), unemployed), person( lily, armstrong, date(29,may,1961), unemployed), []). family(person( eric, baily, date(7,may, 1963), works( bbc, 2200)), person( grace, baily, date(9,may,1965), works( ntu, 1000)), [person( louie, baily, date(25,may,1983), unemployed)]). family(person( eric, baily, date(7,may, 1963), works( acc, 21200)), person( grace, baily, date(9,may,1965), works( ntnu, 12000)), [person( louie, baily, date(25,may,1983), unemployed) ]). family(person( eric, fox, date(27,may, 1970), works( bbc, 25200)), person( grace, fox, date(9,may,1971), works( ntbu, 13000)), [person( louie, fox, date(5,may,1993), unemployed)]). family(person( tom, cohen, date(7,may,1960), works( bcd, 15200)), person( ann, cohen, date(29,may,1961), unemployed), (person( pat, cohen, date(5,may,1983), works( bcd, 15200)), person( jim, cohen, date(5,may,1983), works( bcd, 15200))]). family(person( bob, armstrong, date(12,oct, 1977), works( ntnu, 12000)), person( liz,armstrong, date(6,oct, 1975), unemployed), [person( bob, armstrong, date(6,oct, 1999), unemployed), person( sam,armstrong, date(8,oct, 1998), unemployed) ]). family(person( tony, oliver, date(7,may,1960), works( bbc, 35200)), person( anny, oliver, date(9,may,1961), unemployed), [person( patty, oliver, date(8,may,1984), unemployed), person( jimey, oliver, date(5,may,1983), unemployed) ]). family(person( jack, fox, date(27,may,1940), unemployed), person( jane, fox, date(9,aug, 1941), works( ntu, 13050)), [person( andy, fox, date(5,aug, 1967), works( com, 12000)), person( kai, fox, date(5,jul,1969), unemployed) ]). husband(X) :- family( X, -, _). wife(X):- family( _,X, _). child(X) :- family( -, -, Children), member(X, Children). exists(Persons) :- husband( Persons); wife( Persons); child( Persons). dateofbirth(person(_, _, Date, _), Date). salary(person(_, -, -, works(_, S)), S). salary(person(_, -, -, unemployed), 0). Consider the database from the previous question and answer the following 1) Write a prolog rule totalIncome/2 to compute the total income of a family. 2) Write a prolog query to print total income of each family. 3) Write a prolog query to print family details of each family that has income per family member less than 2000. 4) Write a prolog query to print family details of each family where children's total income is more than their parents. family(person( john, cohen, date(17,may,1990), unemployed), person( lily, cohen, date(9,may, 1990), unemployed), []). family(person( john, armstrong, date(7,may,1988), unemployed), person( lily, armstrong, date(29,may,1961), unemployed), []). family(person( eric, baily, date(7,may, 1963), works( bbc, 2200)), person( grace, baily, date(9,may,1965), works( ntu, 1000)), [person( louie, baily, date(25,may,1983), unemployed)]). family(person( eric, baily, date(7,may, 1963), works( acc, 21200)), person( grace, baily, date(9,may,1965), works( ntnu, 12000)), [person( louie, baily, date(25,may,1983), unemployed) ]). family(person( eric, fox, date(27,may, 1970), works( bbc, 25200)), person( grace, fox, date(9,may,1971), works( ntbu, 13000)), [person( louie, fox, date(5,may,1993), unemployed)]). family(person( tom, cohen, date(7,may,1960), works( bcd, 15200)), person( ann, cohen, date(29,may,1961), unemployed), (person( pat, cohen, date(5,may,1983), works( bcd, 15200)), person( jim, cohen, date(5,may,1983), works( bcd, 15200))]). family(person( bob, armstrong, date(12,oct, 1977), works( ntnu, 12000)), person( liz,armstrong, date(6,oct, 1975), unemployed), [person( bob, armstrong, date(6,oct, 1999), unemployed), person( sam,armstrong, date(8,oct, 1998), unemployed) ]). family(person( tony, oliver, date(7,may,1960), works( bbc, 35200)), person( anny, oliver, date(9,may,1961), unemployed), [person( patty, oliver, date(8,may,1984), unemployed), person( jimey, oliver, date(5,may,1983), unemployed) ]). family(person( jack, fox, date(27,may,1940), unemployed), person( jane, fox, date(9,aug, 1941), works( ntu, 13050)), [person( andy, fox, date(5,aug, 1967), works( com, 12000)), person( kai, fox, date(5,jul,1969), unemployed) ]). husband(X) :- family( X, -, _). wife(X):- family( _,X, _). child(X) :- family( -, -, Children), member(X, Children). exists(Persons) :- husband( Persons); wife( Persons); child( Persons). dateofbirth(person(_, _, Date, _), Date). salary(person(_, -, -, works(_, S)), S). salary(person(_, -, -, unemployed), 0). Consider the database from the previous question and answer the following 1) Write a prolog rule totalIncome/2 to compute the total income of a family. 2) Write a prolog query to print total income of each family. 3) Write a prolog query to print family details of each family that has income per family member less than 2000. 4) Write a prolog query to print family details of each family where children's total income is more than their parentsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started