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
EverFi future smart pie chart
alina1380 [7]

Answer:

wow!!!!!! you pie chart is sweet

3 0
3 years ago
write an interface downloadable that has a method "geturl" that returns the url of a downloadable object
Scrat [10]

Answer:

I want to believe the program is to be written in java and i hope your question is complete. The code is in the explanation section below

Explanation:

import java.util.Date;

public interface Downloadable {

  //abstract methods

  public String getUrl();

  public Date getLastDownloadDate();

 

}

3 0
3 years ago
Am i eating ramon nooddles rn
Elden [556K]

Answer:

You are eating ramen

Explanation:

It is shrimp flavor, yee yee

3 0
3 years ago
Read 2 more answers
A(n) _____ is an apparatus that changes alternating current (AC) to direct current (DC)
amid [387]

Answer:

rectifier

Explanation:

7 0
2 years ago
Who is responsible for conducting a hazard assessment?
slava [35]

Answer:

The Employee

Explanation:

Because it is there responsibility

5 0
3 years ago
Other questions:
  • What is the solution to the system of equations?<br><br>2x-y=7<br>y=2x+3​
    8·1 answer
  • OSHA does not approve individual states to have their own safety and health program.
    15·2 answers
  • 11.A heat engine operates between two reservoirs at 800 and 20°C. One-half of the work output of the heat engine is used to driv
    6·1 answer
  • Problem: design the following rectangular floor beam for a building.
    15·2 answers
  • What are your thoughts on physical education ?
    12·2 answers
  • Is an ideal way for a high school student to see what an engineer does on a typical day but does not provide a hands-on experien
    9·2 answers
  • Which type of Bridge is considered the strongest in both compression and tension?
    11·2 answers
  • How can statistical analysis of a dataset inform a design process
    11·1 answer
  • A 280 km long pipeline connects two pumping stations. It is desired to pump 0.56 m3/s of oil through a 0.62 m diameter line, the
    14·1 answer
  • A 5.74 kg rock is thrown upwards with a force of 317 N at a location where the local gravitational acceleration is 9.81 m/s^2. W
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!