The code below implements a function QU2 which has an input arr of type Array of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The code below implements a function QU2 which has an input arr of type Array of Int and returns an integer. function QU2 (arr) { var i in Int var anInt in Int anInt <-- 0 for (i <-- 1 to 3) { if (AT (i, arr) > 6) then { } anInt <-- an Int + 1 return 2* an Int } (a) Trace the values of the variables i and anInt after each execution of the body of the for loop as this code is executed when the input array arr is [8, 7, 6, 5]. Also write down the value that is returned for this input. (b) To ensure that the code in the given implementation is valid, suggest a precondition that the tivate input arr should satisfy. Go to Setti The code below implements a function QU2 which has an input arr of type Array of Int and returns an integer. function QU2 (arr) { var i in Int var anInt in Int anInt <-- 0 for (i <-- 1 to 3) { if (AT (i, arr) > 6) then { } anInt <-- an Int + 1 return 2* an Int } (a) Trace the values of the variables i and anInt after each execution of the body of the for loop as this code is executed when the input array arr is [8, 7, 6, 5]. Also write down the value that is returned for this input. (b) To ensure that the code in the given implementation is valid, suggest a precondition that the tivate input arr should satisfy. Go to Setti
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Use any method to evaluate the limit or show that it does not exist. lim (x,y) (0,0) x - y x + y
-
For the year ending December 31, 2018, Micron Corporation had income from continuing operations before taxes of $1,200,000 before considering the following transactions and events. All of the items...
-
Four populations are compared by analysis of variance. What are the possible relations among the four population means covered under the null and alternative hypotheses?
-
Ken Lewenza, president of the Canadian Auto Workers union (CAW) says the union is under pressure from Chrysler, Ford, and General Motors to accept performance pay and bonuses rather than...
-
What are the distinguishing characteristics of an executive information system (EIS)? Why have these systems become a part of business intelligence in many companies?
-
Politics can present many challenges in international businesses that can be difficult to overcome. You are the brand manager for an electric vehicle. You want to enter the Asian market. Evaluate...
-
The decedent used his own funds in the amount of $80,000 to acquire stock naming himself and his daughter as joint tenants with right of survivor ship. When the father died, the stock was worth...
-
Which characteristic describes the default gateway of a host computer? O a. The logical address of the router interface on the same network as the host computer O b. The logical address of the router...
-
If you both bet on the same outcome (whether right or wrong), the game continues to the next coin flip. Otherwise, one of you is the winner. (a) What is the chance YOU win on the first flip? [ Be...
-
It is now January 1, 2021, and you are considering the purchase of an outstanding bond that was issued on January 1, 2019. It has an 8.5% annual coupon and had a 30-year original maturity. (It...
-
Jordan has been tasked with planning a conference for her company. She needs to include sessions on new developments in the field and some training sessions to bring the people in her office up to...
-
Let F and E be two graphs of the same order, p and size, q. Prove that if E contains more components than F, then E must contain at least one cycle.
-
Two point sources produce waves in phase with the same amplitude and wavelength. The sources are a distance d apart. The distance from the right bisector to a point on the second nodal line is . The...
-
Solve the linear iterative system 3 -1 -2 In In+1 -4 6 10 Yn Yo Yn+1 2 -2 -3 Zn 20 The eigenvalues are 1,2,3.
-
When is the indirect pattern appropriate, and what are the benefits of using it?
-
Write a program that uses the following functions: Fill_array() takes as arguments the name of an array of double values and an array size. It prompts the user to enter double values to be entered in...
-
Suppose your main() function has the following line: cout < < Please enter your PIN: ; And suppose the compiler complains that cout is an unknown identifier.What is the likely cause of this...
-
Write a program that requests the user to enter two integers.The program should then calculate and report the sum of all the integers between and including the two integers. At this point, assume...
-
What is the difference between a predator and a situational (accidental) fraudster?
-
What are the two categories of data mining and knowledge discovery software?
-
Which types of economic damages are related to digital crimes?
Study smarter with the SolutionInn App