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
Regeneration can only increase the efficiency of a Brayton cycle when working fluid leaving the turbine is hotter than the worki
storchak [24]

Answer:

True, <em>Regeneration is the only process where increases the efficiency of a Brayton cycle when working fluid leaving the turbine is hotter than working fluid leaving the compressor</em>.

Option: A

<u>Explanation: </u>

To increase the efficiency of brayton cycle there are three ways which includes inter-cooling, reheating and regeneration. <em>Regeneration</em> technique <em>is used when a turbine exhaust fluids have higher temperature than the working fluid leaving the compressor of the turbine. </em>

<em>Thermal efficiency</em> of a turbine is increased as <em>the exhaust fluid having higher temperatures are used in heat exchanger where the fluids from the compressor enters and increases the temperature of the fluids leaving the compressor. </em>

6 0
3 years ago
Read 2 more answers
Sensors are used to monitor the pressure and the temperature of a chemical solution stored in a vat. The circuitry for each sens
JulsSmile [24]
Circle because it’s round and we all love round things
5 0
3 years ago
Each of the following activities are commonly performed during the implementation of the Database Life Cycle (DBLC). Fill in the
kicyunya [14]
Yessiree I agree with yu cause yu are right
4 0
3 years ago
The most important element of green construction is that it is a(n) __________ approach to building. *
madam [21]
Environmentally friendly


Since it focuses on are sustainable and efficient with and are made with the future in mind.
5 0
3 years ago
Refrigerant 134a enters an air conditioner compressor at 4 bar, 20 C, and is compressed at steady state to 12 bar, 80 C. The vol
sleet_krkn [62]

Answer:

Q=15.7Kw

Explanation:

From the question we are told that:

Initial Pressure P_1=4bar

Initial Temperature T_1=20 C

Final Pressure  P_2=12 bar

Final Temperature T_2=80C

Work Output W= 60 kJ/kg

Generally Specific Energy from table is

At initial state

 P_1=4bar \& T_1=20 C

 E_1=262.96KJ/Kg

With

Specific Volume V'=0.05397m^3/kg

At Final state

 P_2=12 bar \& P_2=80C

 E_1=310.24KJ/Kg

Generally the equation for The Process is mathematically given by

 m_1E_1+w=m_2E_2+Q

Assuming Mass to be Equal

 m_1=m_1

Where

 m=\frac{V}{V'}

 m=frac{0.06666}{V'=0.05397m^3/kg}

 m=1.24

Therefore

 1.24*262.96+60)=1.24*310.24+Q

 Q=15.7Kw

4 0
3 years ago
Other questions:
  • Identify each statement as referring to a series or parallel circuit.
    15·1 answer
  • The voltage across a device and the current through it are:
    9·2 answers
  • A vehicle experiences hard shifting. Technician A says that the bell housing may be misaligned. Technician B says that incorrect
    5·1 answer
  • A stainless-steel specimen from the same material characterized up above, was formed into a rectangular cross-section of dimensi
    9·1 answer
  • In order to break even, your minimum selling price must be __________ your variable costs.
    10·1 answer
  • Under the normal sign convention, the distributed load on a beam is equal to the:_______A. The rate of change of the bending mom
    13·1 answer
  • Suppose the loop is moving toward the solenoid (to the right). Will current flow through the loop down the front, up the front,
    5·2 answers
  • Suggest how the following requirements might be rewritten in a
    8·1 answer
  • How wold you classify the earliest examples of S.T.E.M discoveries provided in this lesson?
    11·1 answer
  • The phase angle in a circuit is 45 degrees what's the power factor of this circuit?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!