CISC 360程序 写作、 辅导Java Python,C++程序

” CISC 360程序 写作、 辅导Java Python,C++程序CISC 360 Assignment 1September 18, 2020Reminder: All work submitted must be your own. You may (and should) ask for help from theinstructor, TAs or on Piazza.Most of the questions on this assignment are about writing code, but a few questions are aboutstepping. Please write your answers within the comments indicated in the file a1.hs (search forQ3.1 and Q3.2).Start early: Even if some questions look easy to you, Haskell is a very different language andyou may need more time than you think.Late policy: Assignments submitted up to 24 hours late (that is, by 11:59 pm the followingday) will be accepted with a 15% penalty.0 IMPORTANT: Your file must compileYour file must load (:load in GHCi) successfully, or we will automatically subtract 30% from yourmark.If you are halfway through a problem and run out of time, comment out the code that iscausing :load to fail By surrounding it with {- . . . -}, and write a comment describing what youwere trying to do. We can often give partial marks for evidence of progress towards a solution, butwe need the file to load and compile.1 Add your student IDThe file a1.hs will not compile until you add your student ID number by writing it after the =:– Your student ID:student_id :: Integerstudent_id =You do not need to write your name. When we download your submission, onQ includes yourname in the filename.2 Writing and testing small Haskell functions2.1 betweenCISC 360作业 写作、 辅导Java程序设计作业This function takes three integers m, n and p, and should return True if m n p, and returnFalse otherwise.Fill in the definition of between by replacing the word undefined with appropriate Haskellcode, and, if necessary, Deleting the = (for example, if you decide to define between using guards).a1, Jana Dunfield, CISC 360, Fall 2020 1 2020/9/181 Add your student IDWe have already written five test cases for between, called test between1, 2, etc. These arecombined into test between, which is True only if all five tests pass.2.2 carryThe carry function Takes two integers, and should return 1 if both integers are odd, and 0 otherwise(if both are even, or if one of them is even and the other is odd). (The name comes from the factthat its result is the carry bit produced By adding the least significant bits of the two integers.)3 Stepping questions3.1 First expressionThese questions ask you to step two small expressions. For example, the first stepping question asksyou to do the three steps needed to get the result. Replace the parts. (If you want to checkthe last line, you can find it by entering the expression into GHCi.)(\x – x * (3 + x)) 2= _______________________ _________________________= _______________________ _________________________= __ by arithmetic3.2 Second expressionThe other expression is somewhat larger, and uses a function double, which is defined in thecomment.Hint: The first step does not apply the function double. Haskell sees the expression(\a – \b – a (a 3)) double 0as the expression(\a – \b – a (a 3)) doubleapplied to the argument 0.The expression(\a – \b – a (a 3)) Doubleis the function (\a – \b – a (a 3)) applied to the argument double. That is where the firststep happens.Hint: The correct solution Steps 6 times (as indicated by the structure of blanks).a1, Jana Dunfield, CISC 360, Fall 2020 2 2020/9/184 tower4 towerIn this question, you need to write a function tower. Your function should be recursiveits definitionwill call itselfand should not use lists.The idea is that tower is specified by the following equation:The only remaining problem is that you may want to think of the product as looping from kto n, but Haskell does not have loops, so you have to use recursion instead. This will be discussedmore in lecture, but the example of diag from the lecture notes may be helpful: diag n computesthe sum of integers from 0 up to n, but does not use a loop. Instead, it calls itself recursively onn 1. You can think of it as counting down from n to 0.The file a1.hs includes a few tests for tower.5 Base conversionThe functions youll write for this question return Haskell strings, which are lists of characters. Wehave not discussed lists in Any detail; however, for this problem, you should only need to know thefollowing:a1, Jana Dunfield, CISC 360, Fall 2020 3 2020/9/185 Base conversion To return a string containing a single character 0, write[0]You could also write 0. To concatenate (append) two strings, use the built-in function ++. For example:[1, 2, 3] ++ [4]returns 1234, which is the same thing as [1, 2, 3, 4].5.1 toBinaryRead the specification in the comment immediately above toBinary.Fill in the definition of toBinary by replacing the word undefined with appropriate Haskellcode, and, if necessary, deleting the = (for example, if you decide to define toBinary using guards).5.2 toNaryRead the specification in the Comment immediately above toNary.We have already written part of the definition, to check for an invalid basetoNary only needsto handle bases between 2 and 10. If you pass a valid base to toNary, you will get an error (Nonexhaustivepatterns in function toNary) When Haskell falls off the end of the definition. You canfix this by adding an additional Guard to toNary.You should handle all bases between 2 and 10 with the same code. Dont hard-code eachbase; you should have no more than two guards (the given one, and one additional guard), andshould not do something like… = if base == 2 then …else if base == 3 then …else if base == 4 then …a1, Jana Dunfield, CISC 360, Fall 2020 4 2020/9/18如有需要,请加QQ:99515681 或邮箱:99515681@qq.com

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导