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

  Design, implement, test, and debug a simple visual basic

Design, implement, test, and debug a simple Visual Basic® program. Requirements The GUI program will have a button that creates a new window with the word Hello. Enhance the display by making the word change color, move, or change to another lang..

  Compare and contrast the object-oriented approach to design

compare and contrast the object-oriented approach to design and the traditional approach.do you believe that there are

  Find maximum velocity and maximum acceleration

Find maximum velocity and maximum acceleration - Write a general function that can be used to find the maximum of any array. Call this function twice in order to find maximum velocity and maximum acceleration.

  Write a c program to calculate

Write a C program to calculate the following Sum: Sum=1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10! */

  Counts all occurrences of a given string from such a bag

Write a C++ function that removes and counts all occurrences of a given string from such a bag.

  A list of toppings should be shown on the screen as a menu

Write a menu-driven C++ program that allows a user to select from the following items: Pizza, Cheeseburger, and Hot Dog. Pizza should be represented by the integer value 1. Cheeseburger should be represented by the integer value 2.

  Stored in the array points before line seven

Questions (i) to (vii) relate to the following code. A class called Point is defined and the code fragments that are called from main() are given line numbers 1 to 7.

  Write a program to simulate lines in a grocery store

Write a program to simulate lines in a grocery store. We want to determine what line configuration is best

  Determining the total number of employees

Write a computer program to print a report with employee name and total salary for those employees whose total salary is more than 10,000. Total Salary = BASIC + HRA. At the end, the program should also print the total number of employees whose to..

  How many times will the inner loops s be executed

How many times will the inner loop's S be executed? Show HOW you got that answer.

  User that will be asked to input the time

Write a code for the following C++ problem. We will have a user that will be asked to input the time of a train traveling in terms of minutes and this minutes is a non-negative integer.

  What are advantages of cout and cin over printf and scanf

What are advantages of cout and cin over printf() and scanf(). Write the program to enter the name of student, his three subject marks using cout and cin and display the student name and marks? What is the advantages of referencing?

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