Write a list map function that takes 3 arguments: (1) a pointer to a source struct...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a list map function that takes 3 arguments: (1) a pointer to a "source" struct list, a pointer to a "destination" struct list, and (2) a pointer to function that takes an int argument and returns an int. The list map function will loop through the nodes of the "source" list and at every node the provided function is called (using the function pointer) with one argument: the int value found inside the current struct node. The returned int from the function is then appended to the "destination" list. list map does not return anything. Question 2 [40 points] Write a list reduce function that takes 3 arguments: (1) a pointer to a struct list, (2) a pointer to function that takes two int arguments and returns an int, and (3) a "default" int value. If the list has zero nodes, list reduce returns the "default" int value. If the list has one node, list reduce will return the int value found within the single node in the list. Otherwise, list reduce should start by calling the provided function (using the function pointer) on the first two int values in the node chain and put the returned value in an "accumulator" int variable. After that, list reduce should loop through the node chain (starting from the 3rd node) and at every node the provided function is called with two arguments: the "accumulator" int variable, and the int value of the current struct node. The returned value from the function is then used to update the "accumulator". The function returns the "accumulator". Question 3 [25 points] The provided list.c file contains a number of test functions and a main() function that runs the test functions. Do not alter any of the existing tests. In this part, you will add 5 test functions: 2 test functions that test the functionality of list map, and 3 test functions that test the functionality of list reduce. Make sure to add these test functions to the array of tests in main() using appropriate test names. The test functions should return NULL if the test is successful or an appropriate error message otherwise (the return type is const char * to allow returning literal strings as shown in the provided test functions). Files to hand in All source files must be on git. The following files are to be packaged into a tarball a6.tar (located at the root of the repository; i.e., not in any subdirectories) and committed to git with the commit message "a6 hand-in": - Makefile (you may use the same Makefile that you handed-in for A5) list.c Write a list map function that takes 3 arguments: (1) a pointer to a "source" struct list, a pointer to a "destination" struct list, and (2) a pointer to function that takes an int argument and returns an int. The list map function will loop through the nodes of the "source" list and at every node the provided function is called (using the function pointer) with one argument: the int value found inside the current struct node. The returned int from the function is then appended to the "destination" list. list map does not return anything. Question 2 [40 points] Write a list reduce function that takes 3 arguments: (1) a pointer to a struct list, (2) a pointer to function that takes two int arguments and returns an int, and (3) a "default" int value. If the list has zero nodes, list reduce returns the "default" int value. If the list has one node, list reduce will return the int value found within the single node in the list. Otherwise, list reduce should start by calling the provided function (using the function pointer) on the first two int values in the node chain and put the returned value in an "accumulator" int variable. After that, list reduce should loop through the node chain (starting from the 3rd node) and at every node the provided function is called with two arguments: the "accumulator" int variable, and the int value of the current struct node. The returned value from the function is then used to update the "accumulator". The function returns the "accumulator". Question 3 [25 points] The provided list.c file contains a number of test functions and a main() function that runs the test functions. Do not alter any of the existing tests. In this part, you will add 5 test functions: 2 test functions that test the functionality of list map, and 3 test functions that test the functionality of list reduce. Make sure to add these test functions to the array of tests in main() using appropriate test names. The test functions should return NULL if the test is successful or an appropriate error message otherwise (the return type is const char * to allow returning literal strings as shown in the provided test functions). Files to hand in All source files must be on git. The following files are to be packaged into a tarball a6.tar (located at the root of the repository; i.e., not in any subdirectories) and committed to git with the commit message "a6 hand-in": - Makefile (you may use the same Makefile that you handed-in for A5) list.c
Expert Answer:
Answer rating: 100% (QA)
include include Define a struct for a linked list node containing an integer value struct ListNode i... View the full answer
Related Book For
Posted Date:
Students also viewed these computer network questions
-
Analyze and illustrate graphically (Draw graph ) the impact of the following events on the market for young palm tree plants at a nursery. Determine the effect on equilibrium price and quantity. In...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
A strip of metal is originally 1.5 m long. It is stretched in three steps: first to a length of 1.75 m, then to 2.0 m, and finally to 3.0 m. Show that the total true strain is the sum of the true...
-
Make up a multiple-choice question about evaporation and condensation energy changes?
-
The Cook County Authority is considering the purchase of a small plane to transport government officials. It is hoped that the plane will save money on travel costs for government employees. Assume...
-
Timmreck, T.C. Managing motivation and developing job satisfaction in the health care work environment. (2001). Health Care Manager, 2001, 20(1), 42-58. Copyright: Aspen Publishers, Inc. Using...
-
Wang Company began operations on January 1, 2018, by issuing common stock for $70,000 cash. During 2018, Wang received $88,000 cash from revenue and incurred costs that required $65,000 of cash...
-
A business analyst must auction off excess supplies to update the offices. What will the analyst likely pay for the auction service? a. The organization hosting the auction collects fees based on an...
-
According to a Bureau of Labor Statistics release of March 25, 2015, statisticians earn an average of $84,010 a year. Suppose that the current annual earnings of all statisticians have the mean and...
-
Summarise ethical requirements relating to financial reporting for corporate entities. Explain a conflict of interest and why you need to maintain an ethical position. Explain the concept of...
-
Given the below information, calculate the expected return for the stock using the Capital Asset Pricing Model. Beta of the stock = 1.2 Risk-free rate = 2.1% Market Risk Premium = 6%
-
Imagine, you have an opportunity to spend $1USD to plant a tree from every product (~$70USD) you sell. You need to prove/show consumers in a simple infographic that your activity is sustainable.
-
In what ways does the regulation of corporate securities differ from the regulation of other types of financial products? What regulatory philosophy underlies the regulation of corporate securities
-
Q3) Write the network model and 2 iterations of the network simplex for the following network. b1=3 b2=-1 3 b3=-1 1 b4=-1
-
Suppose a 10% 3years bond with a FV of $1000 Spot rates r1= 10%, r2= 12%, r3=13%. Calculate the forward rate required to calculate the bond price using the forward rate 1f2
-
A 400-fwhp diesel-powered track dozer will be used to support a scraper fleet. This dozer was purchased for $395,000. The estimated salvage value at the end of 4 yr is $105,000. The company's...
-
For the given transfer function: Vo(s) / Vi(s) = (s^2C^2R^2 + 1) / (s^2C^2R^2 + 4sCR + 1) Assumiing that 1/(CR) = 120 PI so write the matlab code to find the magnitude plot
-
Rewrite the following code using braced initialization list syntax; the rewrite should dispense with using the array ar: class Z200 { private: int j; char ch; double z; public: Z200(int jv, char chv,...
-
The following are some desired effects. Indicate whether each can be accomplished with default arguments, function overloading, both, or neither. Provide appropriate prototypes. a. mass(density,...
-
Can you assign the address of an object of a derived class to a pointer to the base class? Can you assign the address of an object of a base class to a pointer to the derived class?
-
Bristol-Myers Squibb (BMS) Company reports that it maintains a \($2\) billion, five-year revolving line of credit with a syndicate of lenders. The company disclosed in its annual report that: The...
-
Some corporate executives have reportedly attempted to manage their firms operating expenses through such actions as front-end loading or rear-end loading of their operating expenses. Explain the...
-
Fernandez & Co. experienced the following six events during the current year: 1. The sale of common stock to investors for \($5\) million cash. 2. The sale of a new bond issue to investors for...
Study smarter with the SolutionInn App