Question: Question 2: (10 marks) Write a class called Syralength that contains a method called syra_length() that takes an integer parameter n that is greater than

Question 2: (10 marks) Write a class called Syralength that contains a method called syra_length() that takes an integer parameter n that is greater than zero. syra_length(n) returns the length of the Syracuse sequence that starts with n where the Syracuse sequence can be calculated by the following ecurrence: syra(1) 1 yra(n) syra(n/2), if n mod 20 syra(3 n+1), otherwise Thus for example the sequence of numbers generated by syra(3) is: 10,5,16,8,4,2,1 with a length of 7. Thus, syra_length(3) should return 7 To make your syra_length() function work fast your class should embed an array member variable where you record the length of previous calls to syra_length. So, for instance, if you have previously made a call to syra_length(3) and your current sequence reaches the number 3 then you should immediately know that there are 5 more numbers before the sequence ends by looking up the array. Write a driver program called SyraDriver that makes a new Syralength and calls syra_length() for the first 1000 integers
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
