1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
siniylev [52]
3 years ago
14

Suppose you are implementing a relational employee database, where the database is a list of tuples formed by the names, the pho

ne numbers and the salaries of the employees. For example, a sample database may consist of the following list of tuples:
[("John", "x3456", 50.1) ; ("Jane", "x1234", 107.3) ; ("Joan", "unlisted", 12.7)]
Note that I have written parentheses around the tuples to make them more readable, but the precedences of different operators in OCaml make this unnecessary.

Define a function

find_salary : ((string * string * float) list) -> string -> float
that takes as input a list representing the database and the name of an employee and returns his/her corresponding salary. Think also of some graceful way to deal with the situation where the database does not contain an entry for that particular name, explain it, and implement this in your code.

Define a function

find_phno : ((string * string * float) list) -> string -> string
that is like find_salary, except that it returns the phone number instead.

What I have so far:

let rec find_salary li nm =
let rec helper name s =
match li with
| [] -> 0.0
| (n, p, s) :: t -> if (name = n) then s
else
helper t name
Engineering
1 answer:
m_a_m_a [10]3 years ago
7 0

Answer:

Explanation:

val db = ("John", "x3456", 50.1) :: ("Jane", "x1234", 107.3) ::

        ("Joan", "unlisted", 12.7) :: Nil

 

type listOfTuples = List[(String, String, Double)]

def find_salary(name: String) = {

 def search(t: listOfTuples): Double = t match {

   case (name_, _, salary) :: t if name == name_ => salary

   case _ :: t => search(t)

   case Nil    =>

     throw new Exception("Invalid Argument in find_salary")

 }

 search(db)

}

def select(pred: (String, String, Double) => Boolean) = {

 def search(found: listOfTuples): listOfTuples = found match {

   case (p1, p2, p3) :: t if pred(p1, p2, p3)  => (p1, p2, p3) :: search(t)

   case (p1, p2, p3) :: t if !pred(p1, p2, p3) => search(t)

   case Nil => Nil

   case _ => throw new Exception("Invalid Argument in select function")

 }

 search(db)

}

 

println("Searching the salary of 'Joan' at db: " + find_salary("Joan"))

println("")

 

val predicate = (_:String, _:String, salary:Double) => (salary < 100.0)

println("All employees that match with predicate 'salary < 100.0': ")

println("\t" + select(predicate) + "\n")

You might be interested in
I'll mark brainliest plz help
Citrus2011 [14]

Answer:

Explanation:

There are three points in time we need to consider.  At point 0, the mango begins to fall from the tree.  At point 1, the mango reaches the top of the window.  At point 2, the mango reaches the bottom of the window.

We are given the following information:

y₁ = 3 m

y₂ = 3 m − 2.4 m = 0.6 m

t₂ − t₁ = 0.4 s

a = -9.8 m/s²

t₀ = 0 s

v₀ = 0 m/s

We need to find y₀.

Use a constant acceleration equation:

y = y₀ + v₀ t + ½ at²

Evaluated at point 1:

3 = y₀ + (0) t₁ + ½ (-9.8) t₁²

3 = y₀ − 4.9 t₁²

Evaluated at point 2:

0.6 = y₀ + (0) t₂ + ½ (-9.8) t₂²

0.6 = y₀ − 4.9 t₂²

Solve for y₀ in the first equation and substitute into the second:

y₀ = 3 + 4.9 t₁²

0.6 = (3 + 4.9 t₁²) − 4.9 t₂²

0 = 2.4 + 4.9 (t₁² − t₂²)

We know t₂ = t₁ + 0.4:

0 = 2.4 + 4.9 (t₁² − (t₁ + 0.4)²)

0 = 2.4 + 4.9 (t₁² − (t₁² + 0.8 t₁ + 0.16))

0 = 2.4 + 4.9 (t₁² − t₁² − 0.8 t₁ − 0.16)

0 = 2.4 + 4.9 (-0.8 t₁ − 0.16)

0 = 2.4 − 3.92 t₁ − 0.784

0 = 1.616 − 3.92 t₁

t₁ = 0.412

Now we can plug this into the original equation and find y₀:

3 = y₀ − 4.9 t₁²

3 = y₀ − 4.9 (0.412)²

3 = y₀ − 0.83

y₀ = 3.83

Rounded to two significant figures, the height of the tree is 3.8 meters.

7 0
3 years ago
A controlled process is described by the closed-loop transfer function G(s).
MissTica

Answer:

The answer is "Option B".

Explanation:

Given equation:

G(s) =\frac{K(s + 1)}{2s^2 + (K-1)s + (K-1)}\\\\

if

\to 2s^2 + (K-1)s + (K-1)=0

Calculating by the Routh's Hurwitz table:

\to s^2  \ \ \ \ \    2  \ \ \ \ \ \  K-1 \\\\\to s^2  \ \ \ \ \    K-1  \ \ \ \ \ \   \\\\\to s^0 \ \  ( \frac{(K-1)(K-1)(-2) (0)}{K-1}  \\\\    \ \ \ \  = (K-1) )

Form the above table:

\to K-1 > 0 \\\\ \to K > 1

In the above, the value of k is greater than 1.

3 0
3 years ago
Bài 3: Cho cơ cấu culít (hình 3.5) với các kích thước động lAB = 0,5lAC = 0,1m. Khâu 3 chịu tác dụng của mô men M3 = 500 N. Cơ c
lesya [120]
??????????????????????
3 0
3 years ago
The correct name for a “shooting star” is a:
nirvana33 [79]

Answer:

There is no "correct" name, but the scientific name could be meteorite.

8 0
3 years ago
Read 2 more answers
A blown shaft seal on a hydraulic motor is usually the result of
torisob [31]
It is High system pressure
8 0
3 years ago
Read 2 more answers
Other questions:
  • How has drafting evolved in the 21st century
    10·1 answer
  • It has a piece of 1045 steel with the following dimensions, length of 80 cm, width of 30 cm, and a height of 15 cm. In this piec
    15·1 answer
  • Bob and Alice are solving practice problems for CSE 2320. They look at this code: for(i = 1; i &lt;= N; i = (i*2)+17 ) for(k = i
    6·2 answers
  • An ideal reheat Rankine cycle with water as the working fluid operates the boiler at 15,000 kPa, the reheater at 2000 kPa, and t
    13·1 answer
  • Anything you want to do in Hootsuite can be found in the ________, with the main workspace in the _________?
    15·1 answer
  • Does an electronic clock use electrical energy?​
    10·2 answers
  • Evaluate, please show work as I don't understand. thanks
    5·1 answer
  • Describe each occupation
    8·1 answer
  • Integrated circuits typically are mounted on ________, which are then plugged into the system board.
    6·1 answer
  • Technician A says that mechanical shifting controls can wear out over time. Technician B says that vacuum control rubber diaphra
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!