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
When were dresses made
klio [65]

Answer:

The world's oldest dress called the Tarkhan Dress is at 5,100 to 5,500 years of age.

Does that help? Or do you need something else? I can change my answer if this is not what you need! :D

Explanation:

6 0
3 years ago
The inner surface of a hollow cylinder is subjected to tangential and axial stresses of 40,000 and 24,000 psi, respectively. Det
Furkat [3]

Answer:

15,000 psi

Explanation:

The solution / solving is attach below.

5 0
3 years ago
PLEASE HELP!! Its easy!!!
Rina8888 [55]

Answer:

C is tire

F is cassette

D is hub

4 0
3 years ago
Read 2 more answers
Consider a N-channel enhancement MOSFET with VGS = 3V, Vt = 1 V, VDS = 10 V, and lambda =0 (channel length modulation parameter)
AveGali [126]

The current IDS is greater than 0 since the VGS has induced an inversion layer and the transistor is operating in the saturation region.

<u>Explanation:</u>

  • Since V_{ds} > V_{gs} - Vt because V_{gs} > Vt.
  • By the saturation region the MOSFET is operating.
  • A specific source voltage and gate of NMOS, the voltage get drained during the specific level, the drain voltage is rises beyond where there is no effect of current during saturated region.
  • MOSFET is a transistor which is a device of semiconductor vastly used for the electronic amplifying signals and switching in the devices of electronics.
  • The core of this is integrated circuit.
  • It is fabricated and designed in an individual chips due to tiny sizes.
7 0
3 years ago
Which is the main material in a solar cell?
quester [9]
Crystalline silicon
hope this helps!! <3
5 0
2 years ago
Other questions:
  • What is EL Niño?
    9·1 answer
  • A system consists of N very weakly interacting particles at a temperature T sufficiently high so that classical statistical mech
    9·1 answer
  • A _____ satellite system employs many satellites that are spaced so that, from any point on the Earth at any time, at least one
    10·1 answer
  • The uniform crate has a mass of 50 kg and rests on the cart having an inclined surface. Determine the smallest acceleration that
    10·1 answer
  • Airplanes typically have a Pitot-static probe located on the underside that measures relative wind speed as the airplane flies.
    6·1 answer
  • A motor cycle is moving up an incline of 1 in 30 at a speed of 80 km/h,and then suddenly the engine shuts down.The tractive resi
    11·1 answer
  • Please help is due tonight
    6·2 answers
  • TWO SENTENCES!!! What is something that you have used today that was designed by an engineer? What parts were designed by an eng
    11·2 answers
  • 17. Swing arm restraints are intended to prevent a vehicle from falling off a lift.
    6·1 answer
  • A properly fitted wearable pfd should have which characteristics
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!