CS 341 编程语言

CS    341Programming    LanguagesFall 2023Homework    #02Complete    By: 10/08/2023    @11:59pmPolicy: Individual    work    only,    late    work*not*    acceptedAssignment:         complete    F#programSubmission: submit    “main.fs”    electronically    on    GradescopePre-requisites: Lecture    informationReading    /    F#    ReferencesHere are some references on F# that prior students have found helpful:
    http://dungpa.github.io/fsharp-cheatsheet/
    https://fsharp.org/learn.html
    https://www.tutorialspoint.com/fsharp/index.htm
Programming    environments    for    F#The quickest way to get started is using replit.com: there is a project setup for this homework named“Homework 02” which is configured with F# and starter code.Alternatively, you can install Visual StudioCommunity Edition for Windows or Mac, both offer F#; create a new F# Console project to start programming.If you decide to work outside replit.com, be sure to download the starter code of “main.fs”.[ NOTE: Visual Studio Code is a different product, and is an editor, not an IDE --- you can use VS Code if youwant, but you’ll also need to install the necessary F# libraries and compilers. ]Homework    ExerciseThe exercise is to input a string from the user, and then output the following information:
    • Length of string (# of characters, including spaces and punctuation)
    • # of high frequency letters in the string (e, t, a, o, i, n, s, r, h, l) • # of each high frequency letterPage 2 of 5
    • The result of making the following substitutions for words in the input string
    o “the” to “her”
    o “boy” to “man”
    o “rat” to “hat”
 These substitutions may be within words. For example, them -> herm and boyboy -> manmanFor simplicity, only count lower-case letters. To help you get started, we are providing starter code that inputsa string from the user and calls a few functions that currently returna zero:When your program is complete, here’s an example of how it should behave given the input: a boy is runningThe most natural way to solve this problem in a functional language is to convert the input string to a list ofcharacters, and then work with the resulting list. Two functions are provided for converting strings: explode s
takes a string and returns a list of characters, and implode L takes a list of characters and returns a string.Here’s the starter code here for your reference:
    Page 3 of 5
    //
    // F# program to input a string and print out information
    // about the # of top 10 letters in that string and substituting certain words
    // Original Author:
    // Prof Jon Solworth
    // U. of Illinois, Chicago
    // CS 341, Fall 2023
    //
    //
    // explode:
    //
    // Given a string s, explodes the string into a list of characters.
    // Example: explode "apple" => ['a';'p';'p';'l';'e']
    //
    let explode (S:string) =
     List.ofArray (S.ToCharArray())
    //
    // implode
    //
    // The opposite of explode --- given a list of characters, returns
    // the list as a string. Example: implode ['t';'h';'e'] => "the"
    //
    let implode (L:char list) =
     new string(List.toArray L)
    //
    // returns length of the string
    //
    let rec length L =
     0
    //
    // returns # of top 10 letters of the english alphabetin the string
    //
    let rec topTen L =
     0
    
    [<EntryPoint>]
    let main argv =
     printfn "Starting"
    Page 4 of 5
     printfn ""
     printf("input> ")
     let input = System.Console.ReadLine()
     let L = explode input
     printfn "exploded: %A" L
     printfn ""
     let len = length L
     printfn "length of sentence: %A" len
     let num = topTen L
     printfn "# of top 10 letters: %A" num
     //
     // TODO: print count for each of the top 10 letters
     //
    
     printfn ""
     let S = implode L
     printfn "imploded: %A" S
     printfn ""
    
     //
     // TODO: substitute a series of letters from a given string
     //
     //
     // TODO: print updated sentence
     //
    
     printfn ""
     printfn "Done"
     0 // return 0 => success, much like C++

When producing output, use printfn with the %A option as shown above. This is the easiest way to outputvalues in F#, and will match the required output when submitting to Gradescope.
## Requirements
In order to earn full points for this homework, your code must meet the following requirements:• No variables (i.e. no use of the keyword mutable).• No loops and no if-else. Instead, use recursion or higher-order programming via List.map orList.iter.• Compute the length of the list yourself, do not call List.length; recall we wrote thelength functionin class.Page 5 of 5Challenge: it’s easy to fall into the trap of relying on copy-paste to solve this exercise. For example, you canwrite a function to count the number of ‘a’, then copy-paste and modify to count the number of ‘e’, thencopy-paste again to count the number of ‘i’. And so on. Instead, write a single function that is parameterizedby the top 10 letter, and just call this same function 10 times. Then, the next step would be abstract those 10
calls into one call to List.iter / List.map.

Grading    and    Electronic    Submission    A few days before the assignment is due, login to Gradescope.com and look for the assignment“Homework 2”. Submit your F# program file “main.fs” --- you have unlimited submissions. Keep in mind wegrade your LAST SUBMISSION unless you select an earlier submission for grading. You need to complete all thefunctions in order to get credit for this assignment.Also, add your name to the header comment, and comment any functions you write!
Academic    Conduct    PolicyLate work is not accepted for this assignment. All work is to be done individually — group work is not allowed.While we encourage you to talk to your peers and learn from them, this interaction must be superficial with regards toall work submitted for grading. This means you *cannot* work in teams, you cannot work side-by-side, you cannotsubmit someone else’s work (partial or complete) as your own. The University’s policy isavailable here:https://dos.uic.edu/conductforstudents.shtml
In particular, note that you are guilty of academic dishonesty if youextend or receive any kind of unauthorizedassistance. Absolutely no transfer of program code between students is permitted (paper or electronic), and you maynot solicit code from family, friends, or online forums (e.g. you cannot download answers from Chegg). Other examplesof academic dishonesty include emailing your program to another student, sharing your screen so that another studentmay copy your work, copying-pasting code from the internet, working together in a group, and allowing a tutor, TA, oranother individual to write an answer for you. Academic dishonesty is unacceptable, and penalties range from a lettergrade drop to expulsion from the university; cases are handled via the official student conduct process described at
WX:codehelp

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值