CS代考 Question 1 Prolog

Question 1 Prolog
Please note:
• You must comment your code.
a) Occurrence

Copyright By PowCoder代写 加微信 powcoder

Write a predicate numOccur in Prolog which is true if the number
E occurs R times in the list. For example:
?- numOccur (4,
numccur (4, 11, 7, 5, 0, 8, 1, 8, 61, R).
numOccur (4, [ 1, R)
b) Flipping
Write a predicate flip. Flip is to exchange the order of pairs itself and
in the list
?- flip( [ (a, b), ( c, d)], I ‘
= ¡ (d, c), (b, a)
flip( [ (a, b), ( c, d), (e, f), (g, h),
= ((2, 1), (h, g), (f, e), (d, c), (b, a) l
flip( U, I ).
?- flip( | 11,2)1, L

Ouestion 2 Scheme
Please note:
• You are not allowed to use set! in answering this question
• You must comment your code
a) Occurrence
Write a function numOccur in Scheme which has arguments a
number E and a list L and returns how many times the number E
occurs in the list L. For example:
(numOccur 4 ” (1 7 5 0 4 1 4 6))
(numoccur 4 ” (1 7 5 0 8 1 8 6))
b) Frequency
Write a Scheme function that accepts a list of numbers L and
returns the frequency (number of times) of each number occurs in
the list. The frequency is to be returned in a list of lists where each
list contains the number as car and its frequency as the second
element in the list as in the following examples:
(frequency
(frequency
(2 1) (4 1) (5 1) (6 2) (7 1))
(frequency
= ( (-1 1) (1 1) (5 1)
(7 1) (9 1) )

Question 3 Go
a) Methods
Complete the following program (also available as source file) by
supplying the function printMeal and completing the main
routine to produce the output (exactly as shown):
Main: Schnitzel at 15.50
Desert: Pumpkin Pie at 5.60
Total: 21.10
Note: Do not fill the gaps below but submit your solution as
golang source file.
package main
type Desert struct
type MainCourse struct
Name string
Price float32
type Meal struct
MainCourse
Total float32
func main f
// Calculate the total price of the main
course plus desert
m.printMeal

b) Go Routines and Channels
Complete the go routine in the lambda below. The go routine is to
send the numbers in the array on the channel and then close the
package main
func main ()
numbers := [lint(216, 218, 221, 260}
ch := make (chan int)
/ Your solution
/ You will need to insert code in the
source file and not
if num, ok :=
fmt. Println ( “Channel closed”)
fmt. Printin (num)

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com