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
Document the XSS stored exploit script: Use the View Source feature of the web page and create a screenshot of the few lines cod
Natali [406]

Answer:

Hold on let me ask my brother

Explanation:

5 0
3 years ago
Scenario* The organization is a regional XYZ Credit Union/Bank that has multiple branches and locations throughout the region.*
fiasKO [112]

Answer:

1) For preparation of plan :

It is to gather the team and creating the timeline. Gathering the inputs for the plan and confirming the mission and vision then launching the strategy.

2) A mission would describe about the company and the specification of the company

A vision is the long term or future state of the organization to achieve in a time frame.

Both would include the OAS statements and strategic shifts.

3) The OAS and strategic shift would help to create a balanced score card that would help for data gathering and analysis

This would include the financial, customers goal, Process goals, people's goals etc.

4) To create and develop the plan's framework:

To set the objective for high level organizational goals

To measure the and accomplish the objectives

To take initiatives to achieve the objectives

Explanation:

8 0
3 years ago
before adjusting drive-belt tension, technician a checks for proper pulley alignment. technician b looks up the specified belt t
Vsevolod [243]

Answer:

Technician b is correct

Explanation:

Before adjusting drive-belt tension, it is very important to check the vehicle workshop manual for specified belt tension, so that you can match your reading against the specification in the vehicle's service manual. If the tension reading you have matches the suggested reading in the vehicle's service manual and the belt is not damaged then you do not need to proceed any further. But if the reading does not match, then you can adjust the belt tension.

Therefore, technician b is correct.

5 0
3 years ago
Brainly and points if you want
Tju [1.3M]

Answer:

thank you

Explanation:

have a nice day

8 0
3 years ago
Read 2 more answers
Technician A says that mechanical shifting controls can wear out over time. Technician B says that vacuum control rubber diaphra
diamong [38]

Based on the information, both technician A and technician B are correct.

<h3>How to depict the information?</h3>

From the information given, Technician A says that mechanical shifting controls can wear out over time.

Technician B says that vacuum control rubber diaphragms can deteriorate over time.

In this case, both technicians are correct as the information depicted is true.

Learn more about technicians on:

brainly.com/question/1548867

#SPJ12

8 0
2 years ago
Other questions:
  • If you are sampling a 50Hz signal, what is the minimum sampling rate necessary to prevent aliasing?Why?
    7·1 answer
  • 2- A 2-m3 insulated tank containing ammonia at -20 C, 80% quality, is connected by a valve to a line flowing ammonia at 2 MPa, 6
    14·1 answer
  • 8. Which of the following is a characteristic of no-till farming?
    8·1 answer
  • Any help is appreciated.
    7·1 answer
  • Three consequences of unbalanced wheels on a motor vehicle​
    11·1 answer
  • Electricians will sometimes call ______ "disconnects" or a "disconnecting means."
    15·1 answer
  • Please help ASAP!!
    10·2 answers
  • The difference between an initial condition and a boundary condition for conduction in a solid is:___________
    9·1 answer
  • Select the correct answer.
    8·1 answer
  • Engineering problems and it solutions it machine design​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!