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...
-
Two different investment companies offer college savings plans, one at 8.2% compounded continuously and the other at 8.4% compounded quarterly. Which is the better investment?
-
Bunker Hill Mining Company has two competing proposals: a processing mill and an electric shovel. Both pieces of equipment have an initial investment of $ 750,000. The net cash flows estimated for...
-
Could genetic algorithms be used to play complex games such as chess and checkers? Explain your answer.
-
Leah Friend is trying to decide which of two different kinds of candy to sell in her retail candy store. One type is a name brand candy that will practically sell itself. The other candy is cheaper...
-
Evaluating the Landscape: Evaluate the current social media landscape of Southern New Hampshire University by exploring their existing social media presence in relation to the fundraising effort. The...
-
1. Show how the sampling error calculations for the posttest measures were calculated. 2. If the CEO wanted to be sure that the estimates of awareness and positive image are within 2 percent of the...
-
The management of Hove Ltd has calculated the following statistics from its results for the year ended 31 December 2014. Equivalent average figures from a relevant trade association are also given....
-
Show that the enthalpy can be expressed in terms of the pressure and the density as follows: \(\mathrm{h}=2 \gamma /(\gamma-1)(\mathrm{p} / ho)\).
-
The indicative of the stall flutter is the sign of the integral under the curve of (i) lift vs vertical displacement for plunging, (ii) moment vs angle of attack for pitching. Why? In obtaining the...
-
Construct an audit questionnaire of management performance, which could be given to members of a project team. Test this on someone who has managed you. What areas would you suggest for improvement?
-
Find for a waverider flying at \(80 \mathrm{~km}\) altitude with a Mach number of 25, find: (i) approximate lifting pressure, (ii) lift coefficient, and induced drag coefficient. Assume ideal flow.
-
Under what conditions would it be possible to have an adiabatic flow process with a real fluid (with friction) and have the stagnation pressures at inlet and outlet to the system be the same?
-
Cindy runs a small business that has a profit function of P(t)=3t-5, where P(t) represents the profit (in thousands) after t weeks since their grand opening. a. Solve P(t)=15. In other words, when...
-
Three successive resonance frequencies in an organ pipe are 1310, 1834, and 2358 Hz. (a) Is the pipe closed at one end or open at both ends? (b) What is the fundamental frequency? (c) What is the...
-
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?
-
Water is to be used to absorb acetone from a dilute mixture with air in a tower packed with 3.5-in. metal Pall rings. Average conditions in the tower are: \[\text { Temperature }=25^{\circ}...
-
Propane gas at \(300 \mathrm{psia}\) and \(150^{\circ} \mathrm{F}\) is sent to an expansion turbine with an efficiency of \(80 \%\). What is the lowest outlet pressure that can be achieved without...
-
Liquid oxygen is stored in a tank at \(-298^{\circ} \mathrm{F}\) and 35 psia. It is to be pumped at \(100 \mathrm{lb} / \mathrm{s}\) to a pressure of \(300 \mathrm{psia}\). The liquid oxygen level in...
Study smarter with the SolutionInn App