Find the occupation and the score of each player

Assignment Help C/C++ Programming
Reference no: EM13976708

Question 1. Five golfers, named Jules, Gilles, Jean, Joe and Ghislain often play a round of golf together (use small caps for the players' names in your program). Their occupations are, not necessarily in this order, mason, plasterer, carpenter, tinsmith and roofer. They have played a round of golf but at the end their score cards don't match. Their results were even numbers between 64 and 84.

• Ghislain played par with 72, beating the roofer by 2 strokes.

• Gilles had a bad day, and has ended with 10 strokes above par, or 12 strokes more than the mason.

• The tinsmith has beaten Joe by 4 strokes and has won the round.

• Jules has beaten the carpenter by 8 strokes, but did not win overall.

Find the occupation and the score of each player.

a) Design a predicate to enumerate all possible combinations for players where N is the name of the player, O is the occupation and S is the score.

?- player(N,O,S).
N = jules,
O = carpenter,
S = 64;
N = jules,
O = carpenter,
S = 66
and so on.

b) Express the above bullet list as constraints, e.g., as below. You will have to fill-in the dots with the corresponding Prolog logic.
constraintRoofer(player(N,O,S)) :- ...
constraintMason(...
constraintTinsmith(...
constraintCarpenter(...
constraintWin(...

c) Finally, you will need to apply all the constraints, using the goal:

scores(player(jules,M1,P1), player(jean,M2,P2),
player(gilles,M3,P3), player(joe,M4,P4), player(ghislain,M5,P5)).

Question 2. We saw in class how to represent a binary search tree in Prolog. Write a predicate lca (K1, K2, T) which allows one to find the smallest common ancestor of K1 and K2 in the tree T. The predicate lca shall print the subtree T such that the root is the smallest common  ancestor of K1 and K2.

For example, given the tree
treeA (X):-X = t (73, t (31, t(5,nil,nil), nil), t (101, t (83, nil, t(97,nil,nil)), t(2016,nil,nil))).
We can issue the query

- treeA(X), lca(83,2016,X).
t(101,t(83,nil,t(97,nil,nil)),t(2016,nil,nil))
X = t(73, t(31, t(5, nil, nil), nil), t(101, t(83, nil, t(97, nil, nil)), t(2016, nil, nil))).

Reference no: EM13976708

Questions Cloud

How does media and sexual material influence a small child : What is CDA? Explain. What are the reasons behind the emergence of this act? Provide an analysis. How does media and sexual material influence a small child? Is transmitting sexual pictures or texting considered illegal? Why or why not
Assume that you just won the state lottery : Assume that you just won the state lottery. Your prize can be taken in the form of $40,000 at the end of each of the next 25 years or as a single amount of $500,000 paid immediately. If you expect to earn 7% annually on your investments over the next..
Using semi-annual compounding : Using semi-annual compounding, what is the price of a 5 percent coupon bond with 10 years left to maturity and a market interest rate of 7.2 percent? Assume that interest payments are paid semi-annually and that par value is $1000.
Expected return on the investment with a beta : The expected return on the S&P 500 is 10% and the risk-free rate is 3%. What is the expected return on the investment with a beta of (a) 0.2, (b) 0.5, and (c) 1.4?
Find the occupation and the score of each player : We saw in class how to represent a binary search tree in Prolog. Write a predicate lca (K1, K2, T) which allows one to find the smallest common ancestor of K1 and K2 in the tree T. The predicate lca shall print the subtree T such that the root is ..
Souvenir sheets cost the postal service : The postal service of St. Lucia, an island in the West Indies, obtains a significant portion of its revenues from sales of special souvenir sheets to stamp collectors.
Complete the pension work sheet : Using the above information for Marlin Corporation, complete the pension work sheet for 2015.
How much work does it take to bring them together : Two point charges Q1 = 3.9 μC and Q2 = 7.7 μC are initially very far apart. They are then brought together, with a final separation of 2.4 m. How much work does it take to bring them together?
Write function displayscorethat write score underneath : Write a function displayScorethat writes a score underneath the target. Give it suitable parameters. You can use turtle.write() to display information on the turtle canvas.

Reviews

Write a Review

 

C/C++ Programming Questions & Answers

  Calculate the cost of carrying additional luggage

The application used to calculate the cost of carrying additional luggage results in erroneous amount, if the weight of the luggage is a fractional number. Help the development team modify the code snippet so that the cost of carrying additional lu..

  Write a c++ program to sort a list of number using vectors

Write a C++ program to sort a list of number using vectors. Output the values when the elements are inserted into its correct position. Assume the first element in the list is sorted.

  Prepare a program to find out the perfect numbers

Write a program in C++ that outputs all perfect numbers and their factors from 1 to 1000 using your own created function - Prepare a program to find out the perfect numbers and it must compile with no errors and follow the directions.

  Write programs to play a card game

You will write two programs to play a card game ("clubs"). A separate document describing the rules of "clubs" will be provided.The first program (clubber) will listen on its stdin for information about the game and give its moves to stdout.

  The second argument to the function is the string

The function fnUserBinaryInputX has 2 input arguments, each is a string. The first string is the "prompt" string displayed to the user when asked to enter a string. The second argument to the function is the string to compare the user entered stri..

  Write a recursive void function

Write a recursive void function called rot at eLeft that rotates the first n integers in an array to the left. To rotate n items left, rotate the first n - 1 items left recursively, and then exchange the last two items. For example, to rotate the ..

  Write a function with the heading function range

Write a function with the heading: function Range ( var a : intarray ; n : natural ): natural whose value is that of the range of the elements of the array a , that is, the difference between the maximum and minimum elements.

  What is the xml editor

should C++ programming language be extended to include an XML editor and parser as is the case for the Java® programming language, or should this be built into the Integrated Development Environment (IDE) that supports the programming language

  A pattern detector has an input

A pattern detector has an input a 4 x 4 matrix whose elements take values a, b, c, or d. The output is 1 if the matrix contains one b surrounded by eight a's and 0 otherwise.

  Function that will merge the contents

Write a function that will merge the contents of two sorted(ascending order) arrays of type double values, storing the result in an array output parameter (still in ascending order).

  Design class for textbook-data field for grade level of book

Design a class named TextBook that is child class of Book. Include new data field for grade level of book. Create a displayTextBookInfo () method so that you can accommodate new grade-level field.

  Add 10 people to the line

Add 10 people to the line and process them. Each time you process someone, print out their ticket information. After all 10 have been serviced, print the average wait time. Below is an example of the time calls you will need and a wait function.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd