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
Write multiple if statements:
lora16 [44]
Zrizorzlzfxxxgoxxxxpgxtoxxxhxuxyf
3 0
3 years ago
How much horse power does a Lamborghini have
statuscvo [17]
The Lamborghini SCV12 has 830 horse power.
4 0
2 years ago
Read 2 more answers
If a shear stress acts in one plane of an element, there must be an equal and opposite shear stress acting on a plane that is
xxMikexx [17]

Answer:

90 degrees

Explanation:

In the case when the sheer stress acts in the one plane of an element so it should be equal and opposite also the shear stress acted on a plan i.e. 90 degrees from the plane

Therefore as per the given situation it should be 90 degrees from the plane

hence, the same is to be considered and relevant too

5 0
3 years ago
Read 2 more answers
What is Back EMF? How does it limits the speed of a permanent magnet DC?
ss7ja [257]

Answer and Explanation:

The DC motor has coils inside it which produces magnetic field inside the coil and due to thus magnetic field an emf is induced ,this induced emf is known as back emf. The back emf always acts against the applied voltage. It is represented by E_b

The back emf of the DC motor is given by E_b=\frac{NP\Phi }{60A}

Here N is speed of the motor ,P signifies the number of  poles ,Z signifies the the total number of conductor  and A is number of parallel paths

As from the relation we can see that back emf and speed ar dependent on each other it means back emf limits the speed of DC motor

8 0
3 years ago
An LED camping headlamp can run for 18 hours, powered by three AAA batteries. The batteries each have a capacity of 1000 mAh, an
KIM [24]

Answer:

a) the power consumption of the LEDs is 0.25 watt

b) the LEDs drew 0.0555 Amp current

Explanation:

Given the data in the question;

Three AAA Batteries;

<---- 1000mAh [ + -] 1.5 v ------1000mAh [ + -] 1.5 v --------1000mAh [ + -] 1.5 v------

so V_total = 3 × 1.5 = 4.5V

a) the power consumption of the LEDs

I_battery = 1000 mAh / 18hrs    { for 18 hrs}

I_battery = 1/18 Amp    { delivery by battery}

so consumption by led = I × V_total

we substitute

⇒ 1/18 × 4.5

P = 0.25 watt

Therefore the power consumption of the LEDs is 0.25 watt

b) How much current do the LEDs draw

I_Draw = I_battery = 1/18 Amp = 0.0555 Amp

Therefore the LEDs drew 0.0555 Amp current

5 0
3 years ago
Other questions:
  • A 1-lb collar is attached to a spring and slides without friction along a circular rod in a vertical plane. The spring has an un
    6·1 answer
  • The elementary liquid-phase series reaction
    11·1 answer
  • c++ If your company needs 200 pencils per year, you cannot simply use this year’s price as the cost of pencils 2 years from now.
    9·1 answer
  • Hii I need help can someone help me
    15·1 answer
  • Two kilograms of air within a piston–cylinder assembly executes a Carnot power cycle with maximum and minimum temperatures of 80
    5·2 answers
  • Rafel knows that lessons learned is a valuable aid to future projects. When should he and his team address
    14·1 answer
  • Who does each person work for? Monica works for a power company, Travis works for a utilities company, and Maggie is self-employ
    15·2 answers
  • A steel rod, which is free to move, has a length of 200 mm and a diameter of 20 mm at a temperature of 15oC. If the rod is heate
    10·1 answer
  • 10) A pressure sensor consisting of a diaphragm with strain gauges bonded to its surface has the following information in its sp
    12·1 answer
  • All of these are true about a magnesium part EXCEPT that it:
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!