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
Material with hardness of 220 Vickers is harder than material with a hardness of 180 Vickers. a)-True b)- False
PSYCHO15rus [73]

Answer:

Correct option a) True.

Explanation:

It is true since the Vickers hardness value refers to the force applied in a 136 ° diamond tip penetrator divided by the surface of the groove produced in the material, the lower the impression made on this greater the value will be end of the Vickers measurement and greater its hardness.

The equation to determine the Vickers hardness value will be:

Hv= ((1.854 × P)/(d²))  (kg/mm²)

Therefore a value of 220 Vickers refers to a harder material than another value of 180 Vickers.

6 0
3 years ago
What could happen in the aviation
Alina [70]

Answer:

Yes

Explanation:

7 0
3 years ago
Fixed rate mortgage offer:
jarptica [38.1K]

Answer: The answer is :

      C) $887

Explanation:

5 0
3 years ago
2 Air enters the compressor of a cold air-standard Brayton cycle at 100 kPa, 300 K, with a mass flow rate of 6 kg/s. The compres
lutik1710 [3]
You can see and download from the link

https://tlgur.com/d/GYYVL5lG

Please don't forget to put heart ♥️
5 0
2 years ago
8. What are two ways SpaceX plans to change personal travel?
GalinKa [24]

Answer:

as all the people should go near stratosphere

8 0
2 years ago
Other questions:
  • What are the two safety precautions taken before driving a car​
    12·1 answer
  • What the Best describes the purpose of the occupational safety and health administración OSHA
    12·1 answer
  • If you are in a tornado situation, which of the following actions would put you in danger?
    11·1 answer
  • Water evaporating from a pond does so as if it were diffusing across an air film 0.15 cm thick. The diffusion coefficient of wat
    8·1 answer
  • A plane wall, 7.5 cm thick, generates heat internally at the rate of 105W/m3. One side of the wall is insulated and the other si
    14·1 answer
  • I want to explain what 2000 feet looks like to young children so that they can imagine it in class
    12·1 answer
  • Which of the following describes a polar orbit?
    7·1 answer
  • Crank OA rotates with uniform angular velocity 0  4 rad/s along counterclockwise. Take OA= r= 0.5
    11·1 answer
  • HELP _7. All of the following except which would lead to an INCREASE in friction?
    15·1 answer
  • Which type of artificial intelligence (ai) can repeatedly perform tasks of limited scope?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!