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
What is a chipping hammer used for? <br><br> State three things.
aleksley [76]

Answer:

i hope this helps.

Explanation:

they are used for breaking concrete, can be positioned to break vertical and overhead surfaces, allows precisely chip away only specific areas.

7 0
3 years ago
Read 2 more answers
Technician A says that the definition of torque is how far the crankshaft twists in degrees.Technician B says that torque can re
leonid [27]
Technician B is correct because torque is a force of an object.
6 0
1 year ago
A belt drive was designed to transmit the power of P=7.5 kW with the velocity v=10m/s. The tensile load of the tight side is twi
Leviafan [203]

Answer:

F₁ = 1500 N

F₂ = 750 N

F_{e} = 500 N

Explanation:

Given :

Power transmission, P = 7.5 kW

                                      = 7.5 x 1000 W

                                      = 7500 W

Belt velocity, V = 10 m/s

F₁ = 2 F₂

Now we know from power transmission equation

P = ( F₁ - F₂ ) x V

7500 = ( F₁ - F₂ ) x 10

750 =  F₁ - F₂

750 = 2 F₂ - F₂      ( ∵F₁ = 2 F₂ )

∴F₂  = 750 N

Now F₁ = 2 F₂

        F₁ = 2 x F₂

        F₁ = 2 x 750

        F₁ = 1500 N   ,   this is the maximum force.

Therefore we know,

F_{max} = 3 x F_{e}

where F_{e} is centrifugal force

 F_{e} = F_{max} / 3

                          = 1500 / 3

                         = 500 N

8 0
3 years ago
What does this work for
Anastaziya [24]

Answer:

it allows your dash board to light up you MPH RPM and all the other numbers on the spadomter

Explanat

8 0
3 years ago
Viscous effects are negligible outside of the hydrodynamic boundary layer. (3 points) a. True b. False
Valentin [98]

Answer:

I would say false but I am not for sure

8 0
3 years ago
Other questions:
  • Consider a unidirectional continuous fiber-reinforced composite with epoxy as the matrix with 55% by volume fiber.i. Calculate t
    10·1 answer
  • Design a stepped-impedance low-pass filter having a cutoff frequency of 3 GHz and a fifth-order 0.5 dB equal-ripple response. As
    9·1 answer
  • The water behind Hoover Dam is 206m higher than the Colorado river below it. At what rate must water pass through the hydraulic
    15·2 answers
  • A dc shunt motor rated at 240 V has a field winding resistance of 120 Ω and an armature resistance of 0.12 Ω. The motor is suppl
    14·1 answer
  • During a long run a very well-trained dog can use up to 1000 ‘cal’/hour (Note: Food calories differ by a factor of one thousand
    14·1 answer
  • A car generator turns at 400 rpm (revolutions per minute) when the engine is idling. It has a rectangular coil with 300 turns of
    7·1 answer
  • A beam of span L meters simply supported by the ends, carries a central load W. The beam section is shown in figure. If the maxi
    5·1 answer
  • Pointttttttttttttssssssssssss
    12·1 answer
  • Hi gospelgamer10 lol
    9·2 answers
  • Workers who work with what kind of chemicals chemicals may require regular medical checkups on a more frequent basis as a result
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!