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 the built-in pollution control system in an incinerator called
Kobotan [32]

Explanation:

hbyndbnn☝️

7 0
2 years ago
Are designed to make it easier for employees to get health and safety Information about
iren [92.7K]

Answer:

what the options

Explanation:

4 0
3 years ago
A 75- kw, 3-, Y- connected, 50-Hz 440- V cylindrical synchronous motor operates at rated condition with 0.8 p.f leading. the mot
Thepotemich [5.8K]

78950W the answer

Explanation:

A 75- kw, 3-, Y- connected, 50-Hz 440- V cylindrical synchronous motor operates at rated condition with 0.8 p.f leading. the motor efficiency excluding field and stator losses, is 95%and X=2.5ohms. calculate the mechanical power developed, the Armature current, back e.m.f, power angle and maximum or pull out torque of the motor

A 75- kw, 3-, Y- connected, 50-Hz 440- V cylindrical synchronous motor operates at rated condition with 0.8 p.f leading. the motor efficiency excluding field and stator losses, is 95%and X=2.5ohms. calculate the mechanical power developed, the Armature current, back e.m.f, power angle and maximum or pull out torque of the motor

5 0
2 years ago
Select the correct answer. Which existing technology did engineers use to enhance the speed of propeller-driven airplanes
Musya8 [376]

metallurgy:

Explanation:

7 0
2 years ago
A thick steel slab (rho= 7800 kg/m3 , cp= 480 J/kg K, k= 50 W/m K) is initially at 300 °C and is cooled by water jets impinging
dimaraw [331]

Answer:

t = 2244.3 sec

Explanation:

calculate the thermal diffusivity

\alpha = \frac{k}{\rho c}

           = \frac{50}{7800\times 480} = 1.34 \times 10^{-5} m^2/s

                   

Temperature at 28 mm distance after t time  = =  50 degree C

we know that

\frac[ T_{28} - T_s}{T_i -T_s} = erf(\frac{x}{2\sqrt{at}})

\frac{ 50 -25}{300-25} = erf [\frac{28\times 10^{-3}}{2\sqrt{1.34\times 10^{-5}\times t}}]

0.909 = erf{\frac{3.8245}{\sqrt{t}}}

from gaussian error function table , similarity variable w calculated as

erf w = 0.909

it is lie between erf w = 0.9008  and erf w = 0.11246 so by interpolation we have

w = 0.08073

erf 0.08073 = erf[\frac{3.8245}{\sqrt{t}}]

0.08073 = \frac{3.8245}{\sqrt{t}}

solving fot t we get

t = 2244.3 sec

3 0
2 years ago
Other questions:
  • A meter stick can be read to the nearest millimeter and a travelling microscope can be read to the nearest 0.1 mm. Suppose you w
    11·1 answer
  • It is known that the connecting rod AB exerts on the crank BCa 2.5-kN force directed down andto the left along the centerline of
    12·1 answer
  • As Becky was driving "Old Betsy," the family station wagon, the engine finally quit, being worn out after 171,000 miles. It can
    12·1 answer
  • Students are expected to respond to one of the two questions described below. Students should provide examples to clarify their
    12·1 answer
  • Suppose you are implementing a relational employee database, where the database is a list of tuples formed by the names, the pho
    14·1 answer
  • Automotive service P2 Wastewater Management and Handling Spins
    9·1 answer
  • A 0.50 m3 drum was filled with 0.49 m3 of liquid water at 25oC and the remaining volume was water vapor without any air. The dru
    15·1 answer
  • Acoke can with inner diameter(di) of 75 mm, and wall thickness (t) of 0.1 mm, has internal pressure (pi) of 150 KPa and is suffe
    9·1 answer
  • 4.7 If the maximum tensile force in any of the truss members must be limited to 22 kN, and the maximum compressive force must be
    9·1 answer
  • Work to be performed can come from the work package level of the work breakdown structure as well as other sources. Which of the
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!