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
igomit [66]
3 years ago
10

Define a function romanDigitToInt that converts a single Roman digit to a decimal integer. This function takes an argument as a

element of the RomanDigit union type and transforms it into the decimal integer using patter matching. This function should have signature: RomanDigit -> int.
Computers and Technology
1 answer:
raketka [301]3 years ago
3 0

Answer:

let convertRomanToInt romanNumber : int =

match romanNumber with

| 'I' -> 1

| 'V' -> 5

| 'X' -> 10

| 'L' -> 50

| 'C' -> 100

| 'D' -> 500

| 'M' -> 100

let rec romanNumberToInteger romanNumber =

if (String.length romanNumber = 1) then

convertRomanToInt romanNumber.[0]

elif (String.length romanNumber = 0) then  0

else  let atuple = (romanNumber.[0],romanNumber.[1])

let f atuple =  match atuple with

| (f,s) when (convertRomanToInt f) >=(convertRomanToInt s)->(convertRomanToInt f) + (romanNumberToInteger romanNumber.[1..])

| (f,s) when (convertRomanToInt f) < (convertRomanToInt s) -> (convertRomanToInt s) - (convertRomanToInt f) + (romanNumberToInteger romanNumber.[2..])

f atuple

let charToRomanDigit c =

printfn "%c" c

match c with

| 'I' -> 'I'

| 'V' -> 'V'

| 'X' -> 'X'

| 'L' -> 'L'

| 'C' -> 'C'

| 'D' -> 'D'

| 'M' -> 'M'

| _ -> failwith "Invalid Entry"

let stringToNumber str =

let upperDigit (x:string) = x.ToUpper()

let upperString = upperDigit str

printfn "%s" upperString

String.collect (fun c -> sprintf "%c" (charToRomanDigit c)) upperString

let romanNumber = "XIX"

let upperDigit (x:string) = x.ToUpper()

printfn "a: %s" (upperDigit romanNumber)

romanNumber = stringToNumber romanNumber

printfn "\nValue = %d" (romanNumberToInteger romanNumber)

Explanation:

  • Create a function called convertRomanToInt  for pattern matching to convert romanNumber to valid integer
  • Create a recursive function called romanNumberToInteger  and check if length of romanNumber is 1 or 0 .
  • Check whether the first character is less than second character, then its reverse  otherwise it's normal .
  • Create tuple of first and second character  for pattern matching .
  • Create a function charToRomanDigit  and use String.collect to go through each character present in string and reconstruct them again .
  • System.Char.ToUpper is used to convert a character to uppercase and stringToNumber to convert string in valid Roman number .
  • Finally print the results.
You might be interested in
Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of
rewona [7]

Answer:

Program for the above question in python:

mass = float(input("Enter the mass in grams")) # It is used to take the mass as input.  

density = float(input("Enter the density grams per cm cube")) # It is used to take the input for the grams.

print("Volume ={:.2f}".format(mass/density)) #It is used to print the Volume.

Output:

  • If the user inputs as 2.98 and 3.2, then it will results as 0.92.

Explanation:

  • The above code is in python language, in which the first statement is used to take the inputs from the user for the mass and sore it into a mass variable.
  • Then the second statement also takes the input from the user and store it into a density variable.
  • Then the third statement of the code is used to print the volume up to two places using the above-defined formula.
3 0
4 years ago
When you use filter by form to restrict records that appear, you create the filter and then click the ____ button to apply the f
AlexFokin [52]
<span>When you use filter by form to restrict records that appear, you create the filter and then click the Toggle Filter button to apply the filter.
</span><span>This button is located in the Sort & Filter group on the Home tab.
</span><span>The Toggle Filter is used to switch between the filtered and unfiltered views.</span>
4 0
3 years ago
What is the purpose of the Zoom dialog box? to put the selected range in ascending order in a query to put the selected range in
AlekseyPX

The zoom dialog box helps to enter text and expressions in tight places, such as a property sheet or Query Design view. You can resize the zoom box and change the font. And the zoom box remembers the size and font each time you use it.

Use the

5 0
3 years ago
Read 2 more answers
Traffic collisions are among the top killers of children in America.
Blababa [14]
Whats the question if its true or false, then true
8 0
3 years ago
A user left a comment. Which best describes where will it be seen?
skelet666 [1.2K]

The correct answer is "It will be highlighted in the text and seen in the right margin."

Comments are known as notes or annotations that gives an author or editor an idea about a common mistake in his or her work. In other words, comments are used to give a heads up to the creator of a specific document.

7 0
3 years ago
Read 2 more answers
Other questions:
  • The superintendent forbade the students to bring their books and copies in the exam hall. (into direct speech)​
    10·1 answer
  • If no mode is indicated for a parameter, what mode is used?
    15·1 answer
  • This is C++
    10·1 answer
  • Suppose that the domestic production of computer games creates enjoyment for those who play the games. Domestic production of co
    14·1 answer
  • My pc suddenly freezes and i can't open any apps or task manager. Apps do not open at all and if i restart from the start it get
    9·1 answer
  • Need answer ASAP
    14·1 answer
  • The Freeze Panes feature would be most helpful for which situation?
    6·1 answer
  • Write an article for publication on why every student should be computer literate​
    13·1 answer
  • Please help!!
    12·2 answers
  • Does anyone know what's wrong with this code in Unity? HELP FAST PLEASE! This is for my game design course, I will give brainies
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!