Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 4c Implement a function, generateSequence which has an integer parameter length. The function generates and returns a string consisting of length unique integers

imageimage

Question 4c Implement a function, generateSequence which has an integer parameter length. The function generates and returns a string consisting of length unique integers and dashes, separated by commas (). The string starts with an integer, not necessarily 1. If length is 0 or negative, the function returns an empty string. If length is 1, the function returns a string of one integer. An example string is '2,3,-,-,7,8,9,-,11' when length is 9. Note that the string also satisfies these conditions: Integers are ordered in increasing order and neighbouring numbers are consecutive, e.g., 2 and 3 are consecutive and 7, 8 and 9 are consecutive. Integers immediately after a dash are at least one but not two more than the sum of the last integer before the dash and the number of dashes, e.g., the number after the first 2 dashes can be 6 or 7, and 7 is generated and included, instead of 6. Also, the number after the last dash can be 11 or 12, and 11 is generated and included, instead of 12. (10 marks) Question 4d Write a function, main which repeatedly prompts for the length of sequence to generate, calls the functions generate Sequence and checkSequence, and prints the output of both function calls until the user enters when prompted for the length. If the user enters negative numbers, display an error message and re-prompt the user. Sample run: to end: 10 Enter length of sequence to generate and to end: -2 Length of sequence must be a positive number Enter length of sequence to generate and 89,90,91,92,93,-,96,97,-,-: False Enter length of sequence to generate and 83, 84, 85, -,87,-,89,90,-,- : True to end: 10 to end: 9 Enter length of sequence to generate and 5,6,7,8,9,-,11,12,- : True Enter length of sequence to generate and to end: 0 (5 marks)

Step by Step Solution

3.40 Rating (147 Votes )

There are 3 Steps involved in it

Step: 1

For 4c heres the implementation python def generateSequencelength if len... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Structures and Algorithms in Java

Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser

6th edition

1118771334, 1118771338, 978-1118771334

More Books

Students also viewed these Programming questions

Question

What kind of rays are X-rays?

Answered: 1 week ago

Question

What impresses you the most about infants abilities, and why?

Answered: 1 week ago