Question: Need this program in scheme. a. Design a simple struct, a variable, and a set of functions to operate on these in Scheme. b. Make

Need this program in scheme. a. Design a simple struct, a variable,and a set of functions to operate on these in Scheme. b.Need this program in scheme.

a. Design a simple struct, a variable, and a set of functions to operate on these in Scheme. b. Make sure to set the language to scheme ("#lang scheme") at the top C. Struct i. Create a structure using the define-struct function that contains an id, description and price for a single item that could be sold at a grocery store. d. Variable i. Define a list of struct objects, each with their own id (must start at 1 and count up consecutively), description (simple string stating what it is, e.g. "milk") and price (a positive integer or floating number). ii. You must have at least 7 objects in the list. iji. Give a name for this list as you will need to refer to it. 1. Trefer to it as the master list in the text below. e. Functions (5 pts each) i. lookup 1. Takes an id and a list (which initially should be the list you defined above) as parameters and returns the object from the list that matches the id (hint: use car and cdr functions) jj. getdesc 1. Takes an id as parameter 2. Uses the lookup function to find the object with that id and returns the description of the object iii. getprice 1. Takes an id as parameter 2. Uses the lookup function to find the object with that id and returns the price of the object iv. subtotal 1. Takes a list (of id's) as a parameter 2. Goes through the parameter list and sums up the prices of all objects matching the id's. Uses getprice on each id in the list v. total 1. Takes a list (of id's) as a parameter 2. Use the format function to display the subtotal (found by calling the subtotal function you defined) as well as the total (found by using the subtotal plus its tax 11%). 3. Use Scheme's let expression to avoid evaluating the subtotal twice. a. "Let" is a common tool used in functional languages to define a new scope and any local variables for use inside that scope. vi. getlist 1. Takes no parameters 2. Returns a list of lists where each inner list is the id, description and price of each object in the master list 3. Since this doesn't take any parameters, you may want to define a helper function that takes a list as a parameter and have getlist call that helper function passing it the master list. This way you can use recursion with the helper function. f. Test code i. Write test code for each function ji. This lets you make sure everything is working correctly. g. Put comments to your code properly to describe the functionality of each function h. There are 6 functions. Each worth 5 pts. In order to get full credit, your code must be runnable. In another words, when I run your test code and/or my test code for each function, it should give me the expected results. a. Design a simple struct, a variable, and a set of functions to operate on these in Scheme. b. Make sure to set the language to scheme ("#lang scheme") at the top C. Struct i. Create a structure using the define-struct function that contains an id, description and price for a single item that could be sold at a grocery store. d. Variable i. Define a list of struct objects, each with their own id (must start at 1 and count up consecutively), description (simple string stating what it is, e.g. "milk") and price (a positive integer or floating number). ii. You must have at least 7 objects in the list. iji. Give a name for this list as you will need to refer to it. 1. Trefer to it as the master list in the text below. e. Functions (5 pts each) i. lookup 1. Takes an id and a list (which initially should be the list you defined above) as parameters and returns the object from the list that matches the id (hint: use car and cdr functions) jj. getdesc 1. Takes an id as parameter 2. Uses the lookup function to find the object with that id and returns the description of the object iii. getprice 1. Takes an id as parameter 2. Uses the lookup function to find the object with that id and returns the price of the object iv. subtotal 1. Takes a list (of id's) as a parameter 2. Goes through the parameter list and sums up the prices of all objects matching the id's. Uses getprice on each id in the list v. total 1. Takes a list (of id's) as a parameter 2. Use the format function to display the subtotal (found by calling the subtotal function you defined) as well as the total (found by using the subtotal plus its tax 11%). 3. Use Scheme's let expression to avoid evaluating the subtotal twice. a. "Let" is a common tool used in functional languages to define a new scope and any local variables for use inside that scope. vi. getlist 1. Takes no parameters 2. Returns a list of lists where each inner list is the id, description and price of each object in the master list 3. Since this doesn't take any parameters, you may want to define a helper function that takes a list as a parameter and have getlist call that helper function passing it the master list. This way you can use recursion with the helper function. f. Test code i. Write test code for each function ji. This lets you make sure everything is working correctly. g. Put comments to your code properly to describe the functionality of each function h. There are 6 functions. Each worth 5 pts. In order to get full credit, your code must be runnable. In another words, when I run your test code and/or my test code for each function, it should give me the expected results

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!