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
Hey y’all just wanted to say sup and don’t stress so much about the world just leave it to god and it will all work out
Vaselesa [24]

Answer:

ok

ty for the kind words

Explanation:

7 0
3 years ago
Read 2 more answers
What advantage might there be to having the encoder located on the motor side of the gearhead instead of at the output shaft of
pickupchik [31]

The most accurate answer to that process is definitely precision. The Rotary encoder is an electro-mechanical device that converts the angular position or motion of a shaft or axle to analog or digital output signals. The efficiency of these devices is subject to the position and angle of the axis in front of the encoder.

Most cars use reduction systems in their gearboxes that convert a certain signal input into an output. Mechanically for example, a 20: 1 reduction box already infers that if there is a revolution in the input at the output there are 20. That same transferred to the encoder pulses would imply greater precision.

For example a decoder with 50 holes would have to read 1000 pulses (50 * 20) which is basically a degree of accuracy of 0.36 degrees. In this way it is possible to conclude that if the assembly of the encoder is carried out next to the motor and not at the output, it can be provided with greater precision at the time of reading.

7 0
4 years ago
If a 110-volt appliance requires 20 amps, what is the total power consumed?
juin [17]

Answer:

  2200 W

Explanation:

Use the given relation between current, voltage, and power to find the power requirement:

  P = IV

  P = (20 A)(110 V) = 2200 W

4 0
2 years ago
Read 2 more answers
A household refrigerator that has a power input of 450 W and a COP of 1.5 is to cool five large watermelons, 10 kg each, to 8°C.
Andreyy89

Answer:

6222.22 sec

Explanation:

Given data the power input to the refrigerator is 450 W

The COP of refrigerator is 1.5

Temperature T_1=8^{\circ}C

T_2=28^{\circ}C

mass of watermelon =10 kg

specific heat =4.2 KJ/kg°C

The amount of heat removed from 5 watermelon

Q=mc_pdt=5\times 10\times 4.2\times (28-8)=4200 KJ

We know that COP=\frac{Q_1}{W}

1.5=\frac{Q_1}{450}

Q_1=675 W=0.675 KW

so time required to cool the watermelon is

t=\frac{Q_1}{Q_2}=\frac{4200}{0.675}=6222.22 sec  

4 0
3 years ago
If the atomic radius of copper is 0.128 nm, calculate the volume of its unit cell in cubic meters.
Alex_Xolod [135]

Answer:

Volume of face centered cubic cell=4.74531*10^{-29} m^3

Explanation:

Consider the face centered cubic cell:

1 atom at each corner of cube.

1 atom at center of each face.

Consider the one face (ABCD) as shown in attachment for calculation:

Length of the all sides of face centered cubic cell is L.

Volume of face centered cubic cell= L^3

Now Consider the figure shown in attachment:

According to Pythagoras theorem on ΔADC.

L^{2}+L^2=(4a)^2     (a is the atomic radius)

L=\frac{4a}{\sqrt{2}} (Put in the formula of Volume)

Volume of face centered cubic cell= L^3

Volume of face centered cubic cell= (\frac{4a}{\sqrt{2}})^3

Volume of face centered cubic cell= (\frac{4(0.128*10^{-9}}{\sqrt{2}})^3

Volume of face centered cubic cell=4.74531*10^{-29} m^3

3 0
4 years ago
Other questions:
  • A higher grade number for oil means it is _____.
    6·2 answers
  • userInput = scnr.nextLine(); firstLetter = scnr.nextLine().charAt(0); if ( = firstLetter ) { System.out.println("Found match: "
    6·1 answer
  • The iron-blade plow allowed humans to increase food production during<br> what age?
    8·1 answer
  • An automobile travels along a straight road at 15.65 m/s through a 11.18 m/s speed zone. A police car observed the automobile. A
    9·1 answer
  • Whats a person who enters the electrical trade
    7·2 answers
  • Using the Rayleigh criterion, calculate the minimum feature size that can be resolved in a system with a 0.18 NA lens when g-lin
    13·1 answer
  • Drag each label to the correct location on the chart. Classify the organisms based on how they obtain food.
    14·2 answers
  • 6. Which of the following is considered a major disqualifying offense?
    9·2 answers
  • I really need help with my last topic,Hazard communication,if anyone can help me as soon as possible,that could be my Christmas
    12·1 answer
  • How would you increase the size of the base unit of length in the metric system
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!