Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code in Python. I have done up till the size method in step one but I am not sure if its correct: Step 1

Please code in Python. I have done up till the size method in step one but I am not sure if its correct:

Step 1 Write a first module that creates the Sequence ADT. It should consist of Python code in a file named SeqADT.py. The module should define a class SeqT, which contains the following class methods that define the external interface A constructor (SeqTO) that takes no arguments and creates an object whose state consists of an empty sequence. . A method named add(i, v) that takes the following inputs: i and v, where i (an integer) is the index where the value v (a real) should be added to the sequence. Values can only be added within the existing sequence, or immediately after the last entry in the existing sequence . A method named rm(i) that takes one argument: i (an integer). A call to this method modifies the sequence so that the entry at index i is removed. The length of the list will decrease by I. . A method named set(i, v) that takes two inputs: i (an integer) and v (a real) set is used to modity the entry in the sequence at index 2 to have the value v . A method named get(i) that takes on input: i (an integer). This method returns the value of the sequence at index i. A method named size() that takes no arguments and returns the current size (length) of the sequence (an integer) . A method named indexInSeq(v) that takes a real number v as input. For the sequence object s, indexInSeq returns the index i such that s.get(i) S v < s.get(i+1)

For the add function: It will add that value, v, to the sequence at the argument index i and the set function modifies the value at i, to arg v

For the indexInSeq method:

(The method is searching for where the value v would lie in the sequence of values. It also returns and index, not a value in the sequence. It isn't the first increasing part of the sequence, but the part where v would be found. You need the input v to determine the output. For the list [1.0, 2.0, 3.0, 4.0, 5.0], we have the following examples (remember that the first entry is index 0):

indexInSeq(1.7) = 0

indexInSeq(3.1) = 2

indexInSeq(4.1) = 3)

here is my code:

class SeqT:

def__init__(self){

self.__SeqT=[];

}

def add(self, i, v){

self.__SeqT[i] =v;

return self.__SeqT;

}

def rm(self, i){

del self.__SeqT[i];

(len.self.__SeqT) -1;

return self.__SeqT

}

def set(self, I, v){

self.__SeqT[i] = v;

}

def get(self, i){

self.__SeqT[i] =v;

}

def size(){

sizeOf = self.__len.seSeqT;

return sizeOf;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

More Books

Students also viewed these Databases questions

Question

7. Understand the challenges of multilingualism.

Answered: 1 week ago