Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Included is the code I have written in F#, I want to write the array(a) to a wor

ID: 3920288 • Letter: I

Question

Included is the code I have written in F#, I want to write the array(a) to a word doc or txt file how would I do this?

1//declare array 2 let mutable a-[14; 23; 67; 59; 44; 58; 33; 37; 62; 85; 90; 60; 81; 3 82: 62: 34; 81; 63; 84; 12; 76; 62 3: 25; 57; 30; 82: 3; 57; 41; 13 4 83; 28; 31; 43; 26; 7; 36; 47; 61; 53; 85; 12; 80; 27; 65; 76; 39; 49; 5 21; 50; 9; 77; 24; 63; 38; 18; 89: 50: 42: 9; 6; 51; 1811 8 //swap function 9 let swap x (a: 'al) 10 Let temp - a. [x] 12 a. [x+1] a. [i+1] then //if the value in index i is greater then the value in the next index then call swap functio swap i a //swap function phase a. [i+1] then//if the value in index i is greater then the value in the next index then call swap function swap i a //swap function phase 0 then loop arr else arr //if there are no more phases in the array complete recursive loop Loop arr printfn "Unordered Array:"//print unordered array 34 a> Array.iter(printfn "A" 35 a (oddEven a) //order the array 36 37 a > Array.iter(printfn "%A") 38 39 40 printfn "Ordered Array:" //print ordered array 0 // return an integer exit code

Explanation / Answer

// require to open these two System lbraries for file I/O operations

open System.Net

open System.IO

// method to convert integer array to a string

let convertToString arr =

arr |> List.map (sprintf "%A") |> String.concat ","

[<EntryPoint>]

let main argv =

printfn "Unordered Array:"

a |> Array.iter(printfn "%A")

a <-| (oddEven a)

str <-| (convertToString a) // first convert the sorted array to a string by calling method

File.WriteAllText("filename.txt",str) // write converted string to a text file called filename.txt

0