Question: ------------------------------ Please Use PYTHON 2,7 ----------------------------------- Please DONT POST ANYTHING if you can't do it FULLY and if you are not 100% SURE FROM YOUR
------------------------------ Please Use PYTHON 2,7 -----------------------------------
Please DONT POST ANYTHING if you can't do it FULLY and if you are not 100% SURE FROM YOUR WORKbecause I do not want to post same question again and again for to get full answer !!!
Also, All neccessary codes which are mentioned in the questions are given at the end of the questions !!!!


Array Adt which is mentioned in the question 4
# Implement the Array ADT using array capabilities of the ctype module import ctypes class Array: # Create an array with 'size' elements def __init__( self, size ): assert size > 0, "Array size must be > 0" self._size = size # Create the array structure using the ctypes module self._elements = [None for i in range(size)] # Initialize each element self.clear( None ) # Return the size of the array def __len__( self ): return self._size # Get the content of the indexed element def __getitem__( self, index ): assert index >=0 and index =0 and indexArray2D Adt which is mentioned in the question 5:
# Implementation of the Array2D ADT using an array of arrays class Array2D: # Create a 2-D array of size num_rows X num_cols def __init__( self, num_rows, num_cols ): # Create a 1-D array to store an array reference for each row self._the_rows = Array( num_rows ) # Create the 1-D arrays for each rows of the 2-D array for i in range( num_rows ): self._the_rows[ i ] = Array( num_cols ) # Return the number of rows in the 2-D array def num_rows( self ): return len( self._the_rows ) # Return the number of cols in the 2-D array def num_cols( self ): return len( self._the_rows[0] ) # Clear the array by setting every element to the given value def clear( self, value ): for row in range( self.num_rows() ): self._the_rows[ row ].clear( value ) # Get the content of the element at position [i, j] def __getitem__( self, ndx_tuple ): assert len( ndx_tuple ) == 2, "Invalid number of array subscriptts." row = ndx_tuple[ 0 ] col = ndx_tuple[ 1 ] assert row >= 0 and row = 0 and col = 0 and row = 0 and colMatrix Adt which is mentioned in the question 6:
from array import Array2D class Matrix : def __init__( self, numRows, numCols ): self._theGrid = Array2D( numRows, numCols ) self._theGrid.clear( 0 ) def numRows( self ): return self._theGrid.numRows() def numCols( self ): return self._theGrid.numCols() def __getitem__( self, ndxTuple ): return self._theGrid[ ndxTuple[0], ndxTuple[1] ) def __setitem__( self, ndxTuple, scalar ): self._theGrid[ ndxTuple[0], ndxTuple[1] ] = scalar def scaleBy( self, scalar ): for r in range( self.numRows() ) : for c in range( self.numCols() ) : self[r, c] *= scalar def __add__( self, rhsMatrix ): assert rhsMatrix.numRows() == self.numRows() and \ rhsMatrix.numCols() == self.numCols(), \ "Matrix sizes not compatible for the add operation." newMatrix = Matrix( self.numRows(), self.numCols() ) for r in range( self.numRows() ) : for c in range( self.numCols() ) : newMatrix[r, c] = self[r, c] + rhsMatrix[r, c] return newMatrix4) Demonstrate that the implementation of the Array ADT provided in your textbook works as specified. Your implementation must provide str_) and_repr__() methods, in addition to the methods implemented in the textbook. The output of these methods must return each value separated with a comma. For example, if the array has values 10, 12, 14, 16, and 18, these methods must return the string "10, 12, 14, 16, 8" Your code should support following operations: import random array = Array ( 100 ) for i in range( len array): array[i]- random. random() 4) Demonstrate that the implementation of the Array ADT provided in your textbook works as specified. Your implementation must provide str_) and_repr__() methods, in addition to the methods implemented in the textbook. The output of these methods must return each value separated with a comma. For example, if the array has values 10, 12, 14, 16, and 18, these methods must return the string "10, 12, 14, 16, 8" Your code should support following operations: import random array = Array ( 100 ) for i in range( len array): array[i]- random. random()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
