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

  Write a function that accepts a pointer to a string

Write a function that returns an Integer and accepts a pointer to a string as an argument. The function should count the number of characters in the string and return that number.

  Statement that declares and stores the elements

Write a statement that declares and stores the elements of the following array into a vector object:

  Create a program that reads in two integers

Create a program that reads in two integers and then has a pointer point to the first variable and then to the second variable.

  Create program definition with the templates and methods

This program will store in miniVector v a list of 15 random integers from 0 to 99, then it will output the vector, sort the vector, then output it again sorted.

  Solution to the quadratic equation

The program should allow the user to input the particular integer coefficients of the quadratic equation and properly output either real or complex number solutions for the roots of the equation

  Write a c function void print_triangle(int n)

Write a C function void print_triangle(int n) that prints a triangular pattern of asterisks of height n and width 2 * n + 1 with one asterisk in the first line, three in the second line, etc.,

  Object oriented app development

Object Oriented App development

  Dealerships are awarded the rebate

Dealerships are awarded the rebate on a quarter-by-quarter basis, only for quarters where their actual sales exceeded expected volumes for that quarter. Expected sales volumes for each quarter are as follows:

  Explain strings are an important part of programming

Strings are an important part of programming. They are used to transfer all sorts of data between the user and program, as well as from program to program. Humans communicate with streams because they are flexible enough to encode words and vari..

  Write a program that skip s leading whitespace character

a) Write a program that skip s leading whitespace character s in each line of the pro vided data file CPPHumor .txt . Save the results in a new file

  Write a program that allows a salesclerk to enter an item

Write a program in C++ that allows a salesclerk to enter an item's price and the quantity purchased by a customer.

  What is the 2''s complement of f

Both paging and segmentation are forms of contiguous storage allocation.

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