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
I can't log in even though it says all ages are accepted.Instead when I TRY logging in it says this. "We're sorry, but we are no
uysha [10]

Answer:

Explanation:

This is not a question so to say. This is more like a complaint about how the platform works. Are you needing help with solving a personal problem or having troubles with the platform in itself

8 0
3 years ago
A certain solar energy collector produces a maximum temperature of 100°C. The energy is used in a cyclic heat engine that operat
Gwar [14]

Answer:

\eta _{max} = 0.2413 = 24.13%

\eta' _{max} = 0.5061 = 50.61%

Given:

T_{1max} = 100^{\circ} = 273 + 100 = 373 K

operating temperature of heat engine, T_{2} = 10^{\circ} = 273 + 10 = 283 K

T_{3max} = 300^{\circ} = 273 + 300 = 573 K

Solution:

For a  reversible cycle, maximum efficiency, \eta _{max} is given by:

\eta _{max} = 1 - \frac{T_{2}}{T_{1max}}

\eta _{max} = 1 - \frac{283}{373} = 0.24

\eta _{max} = 0.2413 = 24.13%

Now, on re designing collector, maximum temperature, T_{3max} changes to 300^{\circ}, so, the new maximum efficiency,  \eta' _{max} is given by:

\eta' _{max} = 1 - \frac{T_{2}}{T_{3max}}

\eta _{max} = 1 - \frac{283}{573} = 0.5061

\eta _{max} = 0.5061 = 50.61%

4 0
4 years ago
Elijah wants to make some changes to a game that he is creating. Elijah wants to move the bleachers to the right, the coaches to
Ahat [919]

Answer:

the editor

Explanation:

the variable is usually a number, and the conditional loop has nothign to do with movement/ where something is located

7 0
3 years ago
Read 2 more answers
The wall of drying oven is constructed by sandwiching insulation material of thermal conductivity k = 0.05 W/m°K between thin me
masha68 [24]

Answer:

86 mm

Explanation:

From the attached thermal circuit diagram, equation for i-nodes will be

\frac {T_ \infty, i-T_{i}}{ R^{"}_{cv, i}} + \frac {T_{o}-T_{i}}{ R^{"}_{cd}} + q_{rad} = 0 Equation 1

Similarly, the equation for outer node “o” will be

\frac {T_{ i}-T_{o}}{ R^{"}_{cd}} + \frac {T_{\infty, o} -T_{o}}{ R^{"}_{cv, o}} = 0 Equation 2

The conventive thermal resistance in i-node will be

R^{"}_{cv, i}= \frac {1}{h_{i}}= \frac {1}{30}= 0.033 m^{2}K/w Equation 3

The conventive hermal resistance per unit area is

R^{"}_{cv, o}= \frac {1}{h_{o}}= \frac {1}{10}= 0.100 m^{2}K/w Equation 4

The conductive thermal resistance per unit area is

R^{"}_{cd}= \frac {L}{K}= \frac {L}{0.05} m^{2}K/w Equation 5

Since q_{rad}  is given as 100, T_{o}  is 40 T_ \infty  is 300 T_{\infty, o}  is 25  

Substituting the values in equations 3,4 and 5 into equations 1 and 2 we obtain

\frac {300-T_{i}}{0.033} +\frac {40-T_{i}}{L/0.05} +100=0  Equation 6

\frac {T_{ i}-40}{L/0.05}+ \frac {25-40}{0.100}=0

T_{i}-40= \frac {L}{0.05}*150

T_{i}-40=3000L

T_{i}=3000L+40 Equation 7

From equation 6 we can substitute wherever there’s T_{i} with 3000L+40 as seen in equation 7 hence we obtain

\frac {300- (3000L+40)}{0.033} + \frac {40- (3000L+40)}{L/0.05}+100=0

The above can be simplified to be

\frac {260-3000L}{0.033}+ \frac {(-3000L)}{L/0.05}+100=0

\frac {260-3000L}{0.033}=50

-3000L=1.665-260

L= \frac {-258.33}{-3000}=0.086*10^{-3}m= 86mm

Therefore, insulation thickness is 86mm

8 0
3 years ago
I dont undertand this coding problem (Java):
chubhunter [2.5K]

Check The Attachment.

Download java
6 0
4 years ago
Other questions:
  • Write cout statements with stream manipulators that perform the following:
    8·1 answer
  • A circuit with ____ -diameter connecting wires at a _____ temperature will have the least electrical resistance.
    13·1 answer
  • Modify the CountByFives application so that the user enters the value to count by. Start each new line after 10 values have been
    5·1 answer
  • Given x = 67 and y = 18, use two's complement to calculate:(1)x+y (2) x-y (3)-x+y (4)-x-y. Do the calculation, show the results
    7·1 answer
  • Problem 5.024 A power cycle receives 1000 Btu by heat transfer from a reservoir at 1500°F and discharges energy by heat transfer
    13·1 answer
  • What Happens If A Sonic Boom Is Created?
    8·1 answer
  • What is the name for a program based on the way your brain works?
    13·2 answers
  • You are developing a mind map for measuring the viscosity of fluid. At which stage in the process will you specify the equipment
    10·1 answer
  • Which of the following procedures best applies to assessing the embodied energy of a building?
    12·1 answer
  • What are some benfits of getting involved with 4h
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!