Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 6 CIS 252Intro to Computer Science 8. (15 points) Write a Haskell function Main> makeHealthier sub1 s. ssa 11 None Main makeHealthier salad1 salad

image text in transcribed
image text in transcribed
image text in transcribed
Assignment 6 CIS 252Intro to Computer Science 8. (15 points) Write a Haskell function Main> makeHealthier sub1 s. ssa 11 None Main makeHealthier salad1 salad None MainmakeHealthier Pizza1 Pizza Small Pesto [ Main> akeHealthier pizza2 Pizza Large Garlie tChicken,0lives,Chicken, Chickes, Veggies hannyPizzas [Menultem Integer that, given a list of menu items, counts the number of pizzns in thnt list that contain ham. For example, your function should have the following beh Main> hamnyPizzas order Main> hannyPizzas order2 Main> hannyPizzas [pizza2, pizza2, pizzal, pizza2] 6. (15 points) Write a Haskell function price t Menuites Float such that price item calculates the purchase price of iten. For example, your function should have the following behavior Hain) Price salad 1 6.75 Main> price sub 7.95 Main price pizzal 12.5 *Kain price pizza2 24.75 7. (15 points) Write a Haskell function that, given a list of menu items, returns the highest number of toppings on any pizza in that list. (If there are no pizzas in the list, the result is o.) For example, your function should have the following behavior Main sostToppinge (pizzat, pizza2,aalads,aubl) Main> BostToppings orderl Main> sostToppinge order Hint: Consider using Haskell's maximum::(Ord a) [a) >a function. Note: Do not urite a tes-line function. Instead, use uise pattern matching to consolidate several cases into a single eqwation. My function has four equations Exercises 1. (21 points) Define the following Haskell variables (a) A variable salad1 of type Menultem whose value reperesents a salad (b) A variable aubl of type Menulten whose value represents a small sub (c) A variable pizzal of type Menaltem whose value represents a small (d) A variable pizza2 of type MenuTten whose value represents a large 3. (12 points) Write a Haskell fanction with Greek dressing with Caesar dressing pizza with pesto sauce and no toppings pizza with garlic sauce, ham, olives, a double-order of pepperoni, and sauceCost i Size Sauce Ploat such that sauceCost sz sauce returns the price of a no-toppiag pizza of size sz that has saace sauce. For example, your function should have the Main> sauceCost Small Tonato veggies Main> sauceCost Large Pesto (e) A variable orderi of type (Menuttem] whose value represents a food15.5 order coesisting of all the following: A large sub with no dressing Note: As ith the preeious question, use wise pattern matching to make your code stuccinct . A salad with ranch dressing . A large plain (ie, o toppings) pizza with pesto sauce 4. (12 points) Write a Haskell function (t) A variable order2 of type [Menuttem) whose value represents a food supersize s Menuiten Menuites order consisting of all the following A small pizza with garlie sauce, pepperoni, veggies, ham, anuh that supersize ites returns a "sapersized" version of itea: that is, olives it converts small mena items into large menu items but otherwise leaves all items the same. For example, supersize pizzai returns a large plain pizza with pesto sauce, while supersize subi and upera ize salad 1 re- spectively return a large sub with Caesar dressing and a salad with Greek dressing . A large sub with Caesar dressing A senall sub with Greek dressing . A large pizza with tomato sauce, chicken, and veggies A salad with Greek dressing 5. (15 points) Maurice has decided to start eating a little bit healthier, which 2 (12 points) Write a Haskell function be intends to do by avoiding salty meat and salad dressing. Write a Haskell function toppingCost :: Size Topping Fleat such that toppingCost sz tpg returns the price of the topping tpg on a piza of size sz For example, your function should have the folowing makeHealthier 11 Mesulten Menuices behavior Main toppisgCost 8mal1 01ivea Main> toppingCost Large Chicken such that makeHealthier iten returns a menu item that is similar to item except that any dressing (on either salads or subs) is removed and any salty meat (ie., pepperoni or ham) is replaced by chicken For example, your function should have the following behavior 3.25 Coverage &Logistics .Salads are available for $6.75 each. This assignment covers material through Chapter 7 (Section 5.3 is particularly rel. evant) of Haskell: The Cruft of Functional Programming, as well as Section 14.1 . A large sub costs $9.50, and a small sub costs $7.95 For both subs and salads, customers can choose from the following options: ranch dressing, Greek dressing, Caesar dressing, or no dressing at all This homework is offically due in class on Thursday, March 7. However, it comes with an automatic extension: anything submitted to the CIS 252 bin near CST 4-226 by noon on Friday, March 8 will be accepted as being on time. The file hwistart.hs contains Haskell datatype definitions to represent these menu options: You may work singly or in pairs on this assignment. -posstble piaza toppings data Topping Pepperoni I Olives I Has Veggiers What to turn in You should turn in a hard copy of your source code, a transcript that demon- strates convincingly that your code is correct, and a completed disclosure cover deriving (Shou) --sauces for piazas data SauceTosato l Garlic Pesto sheet. deriving (Shou) Background sizes for pizzas and ssbs data SizSeallI Large This assignment involves the menu of a (fictional) local pizza shop that has re cently opened. Grab a copy of the file hwfistart.hs, which includes some datatype definitions that you will need for this assignment. Add your code to the en opossibte dressings for salads and subs deriving (Show) this file: do not make any alterations to the datatype definitions. The pizza shop offers a very limited menu, as follows: data Dressing . Ranch 1 Greek Caesar l None deriving (Shov) -items on the menu for purchase Pizzas are available in two sizes (small and large), and each comes with adata Menulten Salad Dressing choice of sauce (tomato, garlic, and pesto). The tomato and garlic sauces are considered standard (ie., they don't increase the cost of a pizza), but pesto is a premium sauce. l Sub Size Dressing Pizza Size Sauce (Topping deriving (Shov) . A small standard pizza with no toppings costs $11.00, and a large standard There are two important things to notice about these definitions pizza with no toppings is $13.50 Pesto sauce on a small pizza costs an additional $1.50, and it costs an1. None of these new types belong to the Eq class dditional S2.00 on a large pizza. As a result, you won't be able to use or / to compare elements of these types. Instead, you will need to use Haskell's pattern-matching facilities e The shop offers five optional pizza toppings: pepperoni, olives, ham, veg- gies, and chicken. Chicken costs $2.75 on a small pizza and $3.25 on a large pizza. Each of the other four toppings costs $1.50 on a snall pizza and $2.25 on a large 2. There is no limit on the number of toppings that can appear on a pizza: for example, Pizza Large Tomato [Ham, Olives, Ham) represents a large pizza with tomato sauce, olives and a double-order of ham. (The order in which the toppings appear in the list is unimportant.) Assignment 6 CIS 252Intro to Computer Science 8. (15 points) Write a Haskell function Main> makeHealthier sub1 s. ssa 11 None Main makeHealthier salad1 salad None MainmakeHealthier Pizza1 Pizza Small Pesto [ Main> akeHealthier pizza2 Pizza Large Garlie tChicken,0lives,Chicken, Chickes, Veggies hannyPizzas [Menultem Integer that, given a list of menu items, counts the number of pizzns in thnt list that contain ham. For example, your function should have the following beh Main> hamnyPizzas order Main> hannyPizzas order2 Main> hannyPizzas [pizza2, pizza2, pizzal, pizza2] 6. (15 points) Write a Haskell function price t Menuites Float such that price item calculates the purchase price of iten. For example, your function should have the following behavior Hain) Price salad 1 6.75 Main> price sub 7.95 Main price pizzal 12.5 *Kain price pizza2 24.75 7. (15 points) Write a Haskell function that, given a list of menu items, returns the highest number of toppings on any pizza in that list. (If there are no pizzas in the list, the result is o.) For example, your function should have the following behavior Main sostToppinge (pizzat, pizza2,aalads,aubl) Main> BostToppings orderl Main> sostToppinge order Hint: Consider using Haskell's maximum::(Ord a) [a) >a function. Note: Do not urite a tes-line function. Instead, use uise pattern matching to consolidate several cases into a single eqwation. My function has four equations Exercises 1. (21 points) Define the following Haskell variables (a) A variable salad1 of type Menultem whose value reperesents a salad (b) A variable aubl of type Menulten whose value represents a small sub (c) A variable pizzal of type Menaltem whose value represents a small (d) A variable pizza2 of type MenuTten whose value represents a large 3. (12 points) Write a Haskell fanction with Greek dressing with Caesar dressing pizza with pesto sauce and no toppings pizza with garlic sauce, ham, olives, a double-order of pepperoni, and sauceCost i Size Sauce Ploat such that sauceCost sz sauce returns the price of a no-toppiag pizza of size sz that has saace sauce. For example, your function should have the Main> sauceCost Small Tonato veggies Main> sauceCost Large Pesto (e) A variable orderi of type (Menuttem] whose value represents a food15.5 order coesisting of all the following: A large sub with no dressing Note: As ith the preeious question, use wise pattern matching to make your code stuccinct . A salad with ranch dressing . A large plain (ie, o toppings) pizza with pesto sauce 4. (12 points) Write a Haskell function (t) A variable order2 of type [Menuttem) whose value represents a food supersize s Menuiten Menuites order consisting of all the following A small pizza with garlie sauce, pepperoni, veggies, ham, anuh that supersize ites returns a "sapersized" version of itea: that is, olives it converts small mena items into large menu items but otherwise leaves all items the same. For example, supersize pizzai returns a large plain pizza with pesto sauce, while supersize subi and upera ize salad 1 re- spectively return a large sub with Caesar dressing and a salad with Greek dressing . A large sub with Caesar dressing A senall sub with Greek dressing . A large pizza with tomato sauce, chicken, and veggies A salad with Greek dressing 5. (15 points) Maurice has decided to start eating a little bit healthier, which 2 (12 points) Write a Haskell function be intends to do by avoiding salty meat and salad dressing. Write a Haskell function toppingCost :: Size Topping Fleat such that toppingCost sz tpg returns the price of the topping tpg on a piza of size sz For example, your function should have the folowing makeHealthier 11 Mesulten Menuices behavior Main toppisgCost 8mal1 01ivea Main> toppingCost Large Chicken such that makeHealthier iten returns a menu item that is similar to item except that any dressing (on either salads or subs) is removed and any salty meat (ie., pepperoni or ham) is replaced by chicken For example, your function should have the following behavior 3.25 Coverage &Logistics .Salads are available for $6.75 each. This assignment covers material through Chapter 7 (Section 5.3 is particularly rel. evant) of Haskell: The Cruft of Functional Programming, as well as Section 14.1 . A large sub costs $9.50, and a small sub costs $7.95 For both subs and salads, customers can choose from the following options: ranch dressing, Greek dressing, Caesar dressing, or no dressing at all This homework is offically due in class on Thursday, March 7. However, it comes with an automatic extension: anything submitted to the CIS 252 bin near CST 4-226 by noon on Friday, March 8 will be accepted as being on time. The file hwistart.hs contains Haskell datatype definitions to represent these menu options: You may work singly or in pairs on this assignment. -posstble piaza toppings data Topping Pepperoni I Olives I Has Veggiers What to turn in You should turn in a hard copy of your source code, a transcript that demon- strates convincingly that your code is correct, and a completed disclosure cover deriving (Shou) --sauces for piazas data SauceTosato l Garlic Pesto sheet. deriving (Shou) Background sizes for pizzas and ssbs data SizSeallI Large This assignment involves the menu of a (fictional) local pizza shop that has re cently opened. Grab a copy of the file hwfistart.hs, which includes some datatype definitions that you will need for this assignment. Add your code to the en opossibte dressings for salads and subs deriving (Show) this file: do not make any alterations to the datatype definitions. The pizza shop offers a very limited menu, as follows: data Dressing . Ranch 1 Greek Caesar l None deriving (Shov) -items on the menu for purchase Pizzas are available in two sizes (small and large), and each comes with adata Menulten Salad Dressing choice of sauce (tomato, garlic, and pesto). The tomato and garlic sauces are considered standard (ie., they don't increase the cost of a pizza), but pesto is a premium sauce. l Sub Size Dressing Pizza Size Sauce (Topping deriving (Shov) . A small standard pizza with no toppings costs $11.00, and a large standard There are two important things to notice about these definitions pizza with no toppings is $13.50 Pesto sauce on a small pizza costs an additional $1.50, and it costs an1. None of these new types belong to the Eq class dditional S2.00 on a large pizza. As a result, you won't be able to use or / to compare elements of these types. Instead, you will need to use Haskell's pattern-matching facilities e The shop offers five optional pizza toppings: pepperoni, olives, ham, veg- gies, and chicken. Chicken costs $2.75 on a small pizza and $3.25 on a large pizza. Each of the other four toppings costs $1.50 on a snall pizza and $2.25 on a large 2. There is no limit on the number of toppings that can appear on a pizza: for example, Pizza Large Tomato [Ham, Olives, Ham) represents a large pizza with tomato sauce, olives and a double-order of ham. (The order in which the toppings appear in the list is unimportant.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

Students also viewed these Databases questions

Question

Why would you want to layer software?

Answered: 1 week ago

Question

6.7 Discuss strategies for recruiting a more diverse workforce.

Answered: 1 week ago