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
Determine the output logic-levels(boolean-levels) for XNOR if the two-inputs are inverted?​
stiv31 [10]

Answer:

<em><u>1</u></em>

<em><u>1What is the output of 2 Input XNOR gate if both the inputs are same? Explanation: The output of 2 Input XNOR gate is 1 if both the inputs are same. The output of the XNOR gate is 1 if both the inputs are logic 0 or logic 1. This is why they are called as equality detector.</u></em>

4 0
2 years ago
Tanya Pierce, President and owner of Florida Now Real Estate is seeking your assistance in designing a database for her business
const2013 [10]

Answer:

the answer is attributes for each entity

5 0
3 years ago
Initialize the tuple team_names with the strings 'Rockets', 'Raptors', 'Warriors', and 'Celtics' (The top-4 2018 NBA teams at th
Drupady [299]

Answer:

#Initialise a tuple

team_names = ('Rockets','Raptors','Warriors','Celtics')

print(team_names[0])

print(team_names[1])

print(team_names[2])

print(team_names[3])

Explanation:

The Python code illustrates or printed out the tuple team names at the end of a season.

The code displayed is a function that will display these teams as an output from the program.

4 0
3 years ago
What is the mass of the same dragster body (volume of 150 cm3) if it is made of basswood instead?
dusya [7]

Answer:

the answer is 61.5

Explanation:

8 0
3 years ago
A 2-mm-diameter electrical wire is insulated by a 2-mm-thick rubberized sheath (k = 0.13 W/m K), and the wire/sheath interface i
Semmy [17]

Answer:

maximum allowable electrical power=4.51W/m

critical radius of the insulation=13mm

Explanation:

Hello!

To solve this heat transfer problem we must initially draw the wire and interpret the whole problem (see attached image)

Subsequently, consider the heat transfer equation from the internal part of the tube to the external air, taking into account the resistance by convection, and  conduction as shown in the attached image

to find the critical insulation radius we must divide the conductivity of the material by the external convective coefficient

r=\frac{k}{h} =\frac{0.13}{10}=0.013m=13mm

3 0
2 years ago
Other questions:
  • A manufacturer makes integrated circuits that each have a resistance layer with a target thickness of 200 units. A circuit won't
    5·1 answer
  • Identify each statement as referring to a series or parallel circuit.
    15·1 answer
  • A displacement transducer has the following specifications: Linearity error ± 0.25% reading Drift ± 0.05%/○C reading Sensitivity
    8·1 answer
  • The Emergency Stop Button icon on the Inputs toolbar can be used to press or release the Emergency Stop button on the CNC machin
    10·1 answer
  • What is the relationship between orifice diameter and pipe diameter​
    15·1 answer
  • Do you understand entropy? Why the concept of entropy is difficult to engineering students?
    11·1 answer
  • The parts of a feature control frame are the tolerance value, the datum references, and the
    14·1 answer
  • Convert 103.69 kN to TN.
    14·1 answer
  • Poems that focus on one image usually have what purpose? PLEASE HELP MEH!!
    7·2 answers
  • Whats viruses c liver?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!