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
The air velocity in the duct of a heating system is to be measured by a Pitot-static probe inserted into the duct parallel to th
Ilia_Sergeevich [38]

Answer:

Flow velocity

50.48m/s

Pressure change at probe tip

1236.06Pa

Explanation:

Question is incomplete

The air velocity in the duct of a heating system is to be measured by a Pitot-static probe inserted into the duct parallel to the flow. If the differential height between the water columns connected to the two outlets of the probe is 0.126m, determine (a) the flow velocity and (b) the pressure rise at the tip of the probe. The air temperature and pressure in the duct are 352k and 98 kPa, respectively

solution

In this question, we are asked to calculate the flow velocity and the pressure rise at the tip of probe

please check attachment for complete solution and step by step explanation

8 0
3 years ago
Helium gas expands in a piston-cylinder in a polytropic process with n=1.67. Is the work positive, negative or zero?
IRINA_888 [86]

Answer:

work will be positive when it is under polytropic expansion process

Explanation:

It states a polytropic  process with n equal to 1.67. there is a polytropic expansion that mean work is positive and if it was polytropic compression then it would   be negative

PV^n = const

P_1V_1 = P_2V_2

Also work during the process of polytropic is given as

W_{1-2} =\frac{P_1V_1 -P_2V_2}{n-1}

the work will be positive when it is under the polytropic expansion process

3 0
2 years ago
Find the resolving power of a Fabry-Perot interferometer in which two silver coated plates have reflectance of ???? = 0.9, if th
pochemuha

Answer:

Resolving Power=625000

Explanation:

See attached picture.

7 0
3 years ago
(Blank) welding involves manual welding with equipment anomalously controls one or more of the windy conditions while (blank) we
shepuryov [24]

Answer:

D.

Explanation:

In automated welding, defined as “welding with equipment that requires only occasional or no observation of the weld, and no manual adjustment of the equipment controls,” the welder's involvement is limited to activating the machine to initiate the welding cycle and observing the weld on an intermittent basis.

8 0
3 years ago
Determine the velocity of the 13-kgkg block BB in 4 ss . Express your answer to three significant figures and include the approp
Anvisha [2.4K]

Answer:

The question has some details missing : The 35-kg block A is released from rest. Determine the velocity of the 13-kgkg block BB in 4 ss . Express your answer to three significant figures and include the appropriate units. Enter positive value if the velocity is upward and negative value if the velocity is downward.

Explanation:

The detailed steps and appropriate calculation is as shown in the attached file.

6 0
3 years ago
Other questions:
  • A fluid flows steadily through a pipe with a uniform cross sectional area. The density of the fluid decreases to half its initia
    6·1 answer
  • Which term defines the amount of mechanical work an engine can do per unit of heat energy it uses?
    5·1 answer
  • A worker standing on a freshly mopped floor is
    7·1 answer
  • A train which is traveling at 70 mi/hr applies its brakes as it reaches point A and slows down with a constant deceleration. Its
    12·1 answer
  • Sam, a carpenter, is asked to identify the abilities he has that are important to his work. What are the top abilities he might
    9·2 answers
  • Giving out 100 coins cuz why not?​
    11·1 answer
  • Two identical bulbs in parallel in a radio create a total resistance of 15 ohms in the circuit. What's the resistance of each of
    6·1 answer
  • Which of the following suggestions would best help alleviate the Gulf of Mexico dead zone?
    13·1 answer
  • According to Gary Sirota, the proposed Bajagua wastewater treatment plant is a beneficial solution because __________.
    5·1 answer
  • While, Do...while, and For loops can best be characterized as which of the following?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!