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
Take 15 Points please Help HURRY!!!!​
Mnenie [13.5K]

Answer:

20 is your answer of look it once for both

3 0
3 years ago
Read 2 more answers
The signal propagation time between two ground stations in a synchronous satellite link is about millisecond is​
Sonja [21]

Answer:

270 is the answer for that

6 0
3 years ago
During the reaction, 3.50 μmol of HCl are produced. Calculate the final pH of the reaction solution. Assume that the HCl is comp
lyudmila [28]

Answer:

The pH of the solution will be equal to 5.46

Explanation:

The dissociation reaction of HCl is equal to:

HCl → H+ + Cl-

To solve the exercise we must first convert the µmoles to moles using the following conversion factor:

3.5µmoles x \frac{1 mol}{1x10^{6} umol} = 3.5x10^{-6}moles

Assuming a liter of solution, we can calculate the molar concentration by:

M = \frac{Number of moles}{Liter of solution}

Replacing:

M = \frac{3.5x10^{-6}moles }{1 L} = 3.5x10^{-6}moles/L

As this acid dissociates completely, the concentration of protons and chloride will be equal to 3.5x10^{-6}moles/L

The pH will be equal to:

pH = -log[H+]

Replacing:

pH = -log[3.5x10^{-6}] = 5.46

8 0
4 years ago
Why is an integrated circuit (IC) referred to as a special device?"<br> points more than 10 plz help
sladkih [1.3K]

Answer:

Because IC microcomputers are smaller and more versatile than previous control mechanisms, they allow the equipment to respond to a wider range of input and produce a wider range of output. They can also be reprogrammed without having to redesign the control circuitry

Explanation:

5 0
3 years ago
It is proposed that a 1,000-MW electric power plant be built with steam as the working fluid with the condenser to be cooled wit
elixir [45]

Answer:

The temperature rise of the river downstream from the power plant is approximately 1.9°C

Explanation:

Pls see the attached files below for the solution as typing it here may be difficult due to the formulas involved in solving the question.

5 0
3 years ago
Other questions:
  • Analysis of the relationship between the fuel economy​ (mpg) and engine size​ (in liters) for 35 models of cars produces the reg
    15·1 answer
  • Consider a Carnot heat-engine cycle executed in a closed system using 0.028 kg of steam as the working fluid. It is known that t
    11·1 answer
  • Write a program that prints a one-month calendar. The userspecifies the number of days in the month and the day of the weekon wh
    9·1 answer
  • Que a state properties of Sounds ] 1 laws of replactions of light 2 2​
    7·1 answer
  • Which of the following is the BEST definition for e-commerce? *
    13·1 answer
  • The seers were of the opinion that_____ . *
    14·1 answer
  • Which option identifies what would be best to use to illustrate Pablo’s ideas in the following scenario?
    14·1 answer
  • Ethylene glycol, the ingredient in antifreeze, does not cause health problems because it is a clear liquid.
    6·1 answer
  • Which of the following became essential to the construction process after the split between design and construction occurred dur
    15·1 answer
  • A pipe fitter would fabricate which one of the following systems?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!